PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.4
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.4
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / assets / src / js / admin / orders / export-orders.js

export-orders.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.4, at assets/src/js/admin/orders/export-orders.js

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import * as lpUtils from 'lpAssetsJsPath/utils.js';
2 import * as lpToastify from 'lpAssetsJsPath/lpToastify';
3
4 export const ExportOrdersToCSV = () => {
5 const handleExport = ( args ) => {
6 const { e, target } = args;
7 e.preventDefault();
8 lpUtils.lpSetLoadingEl( target, true );
9 let dataSend = JSON.parse( target.dataset.send );
10
11 const callBack = {
12 success: ( response ) => {
13 const { message, status, data } = response;
14
15 if ( status === 'success' ) {
16 const maxPage = data?.max_page;
17 const nextPage = data?.next_page;
18 const done = data?.done;
19 const downloadUrl = data?.download_url;
20
21 if ( !! maxPage && !! nextPage && nextPage <= maxPage ) {
22 dataSend = { ...dataSend, paged: nextPage };
23 window.lpAJAXG.fetchAJAX( dataSend, callBack );
24 } else if ( !! done ) {
25 lpToastify.show( message, 'success' );
26
27 const link = document.createElement( 'a' );
28 link.href = downloadUrl;
29 link.target = '_self';
30 document.body.appendChild( link );
31 link.click();
32 document.body.removeChild( link );
33 }
34 } else {
35 throw message;
36 }
37 },
38 error: ( error ) => {
39 lpToastify.show( error, 'error' );
40 },
41 completed: () => {
42 lpUtils.lpSetLoadingEl( target, false );
43 },
44 };
45
46 window.lpAJAXG.fetchAJAX( dataSend, callBack );
47 };
48
49 lpUtils.eventHandlers( 'click', [
50 {
51 selector: '.lp-btn-export-order-to-csv',
52 class: this,
53 callBack: handleExport,
54 },
55 ] );
56 };
57