learndash-admin-settings-data-reports.js
2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
jQuery( function() {
jQuery( 'table#learndash-data-reports button' ).on( 'click', function( e ) {
e.preventDefault();
var form_nonce = jQuery( 'input#learndash-data-reports-nonce' ).val();
var parent_tr = jQuery( this ).parents( 'tr' );
var data_nonce = jQuery( this ).attr( 'data-nonce' );
var data_slug = jQuery( this ).attr( 'data-slug' );
// Close all other progress meters
jQuery( 'table#learndash-data-reports .learndash-data-reports-status' ).hide();
// disable all other buttons
jQuery( 'table#learndash-data-reports button.learndash-data-reports-button' ).prop( 'disabled', true );
// Hide all download buttons
jQuery( 'table#learndash-data-reports a.learndash-data-reports-download-link' ).hide();
var post_data = {
action: 'learndash-data-reports',
nonce: form_nonce,
data: {
init: 1,
nonce: data_nonce,
slug: data_slug,
},
};
learndash_data_reports_do_ajax( post_data, parent_tr );
} );
} );
function learndash_data_reports_do_ajax( post_data, container ) {
if ( ( typeof post_data === 'undefined' ) || ( post_data == '' ) ) {
active_post_data = {};
return false;
}
jQuery.ajax( {
type: 'POST',
url: ajaxurl,
dataType: 'json',
cache: false,
data: post_data,
error: function( jqXHR, textStatus, errorThrown ) {
},
success: function( reply_data ) {
if ( typeof reply_data !== 'undefined' ) {
if ( typeof reply_data.data !== 'undefined' ) {
// Update the progress meter
if ( jQuery( '.learndash-data-reports-status', container ).length ) {
jQuery( '.learndash-data-reports-status', container ).show();
if ( typeof reply_data.data.progress_percent !== 'undefined' ) {
jQuery( '.learndash-data-reports-status .progress-meter-image', container ).css( 'width', reply_data.data.progress_percent + '%' );
}
if ( typeof reply_data.data.progress_label !== 'undefined' ) {
jQuery( '.learndash-data-reports-status .progress-label', container ).html( reply_data.data.progress_label );
}
}
var total_count = 0;
if ( typeof reply_data.data.total_count !== 'undefined' ) {
total_count = parseInt( reply_data.data.total_count );
}
var result_count = 0;
if ( typeof reply_data.data.result_count !== 'undefined' ) {
result_count = parseInt( reply_data.data.result_count );
}
if ( result_count < total_count ) {
post_data.data = reply_data.data;
learndash_data_reports_do_ajax( post_data, container );
} else {
// Re-enable the buttons
jQuery( 'table#learndash-data-reports button.learndash-data-reports-button' ).prop( 'disabled', false );
if ( ( typeof reply_data.data.report_download_link !== 'undefined' ) && ( reply_data.data.report_download_link != '' ) ) {
window.location.href = reply_data.data.report_download_link;
}
}
}
}
},
} );
}