installed plugin Easy Digital Downloads
version 3.1.0.3
This commit is contained in:
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Export screen JS
|
||||
*/
|
||||
const EDD_Export = {
|
||||
|
||||
init: function() {
|
||||
this.submit();
|
||||
},
|
||||
|
||||
submit: function() {
|
||||
const self = this;
|
||||
|
||||
$( document.body ).on( 'submit', '.edd-export-form', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
const form = $( this ),
|
||||
submitButton = form.find( 'button[type="submit"]' ).first();
|
||||
|
||||
if ( submitButton.hasClass( 'button-disabled' ) || submitButton.is( ':disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = form.serialize();
|
||||
|
||||
if ( submitButton.hasClass( 'button-primary' ) ) {
|
||||
submitButton.removeClass( 'button-primary' ).addClass( 'button-secondary' );
|
||||
}
|
||||
submitButton.attr( 'disabled', true ).addClass( 'updating-message' );
|
||||
form.find( '.notice-wrap' ).remove();
|
||||
form.append( '<div class="notice-wrap"><div class="edd-progress"><div></div></div></div>' );
|
||||
|
||||
// start the process
|
||||
self.process_step( 1, data, self );
|
||||
} );
|
||||
},
|
||||
|
||||
process_step: function( step, data, self ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
form: data,
|
||||
action: 'edd_do_ajax_export',
|
||||
step: step,
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function( response ) {
|
||||
if ( 'done' === response.step || response.error || response.success ) {
|
||||
// We need to get the actual in progress form, not all forms on the page
|
||||
const export_form = $( '.edd-export-form' ).find( '.edd-progress' ).parent().parent();
|
||||
const notice_wrap = export_form.find( '.notice-wrap' );
|
||||
|
||||
export_form.find( 'button' ).attr( 'disabled', false ).removeClass( 'updating-message' ).addClass( 'updated-message' );
|
||||
export_form.find( 'button .spinner' ).hide().css( 'visibility', 'visible' );
|
||||
|
||||
if ( response.error ) {
|
||||
const error_message = response.message;
|
||||
notice_wrap.html( '<div class="updated error"><p>' + error_message + '</p></div>' );
|
||||
} else if ( response.success ) {
|
||||
const success_message = response.message;
|
||||
notice_wrap.html( '<div id="edd-batch-success" class="updated notice"><p>' + success_message + '</p></div>' );
|
||||
if ( response.data ) {
|
||||
$.each( response.data, function ( key, value ) {
|
||||
$( '.edd_' + key ).html( value );
|
||||
} );
|
||||
}
|
||||
} else {
|
||||
notice_wrap.remove();
|
||||
window.location = response.url;
|
||||
}
|
||||
} else {
|
||||
$( '.edd-progress div' ).animate( {
|
||||
width: response.percentage + '%',
|
||||
}, 50, function() {
|
||||
// Animation complete.
|
||||
} );
|
||||
self.process_step( parseInt( response.step ), data, self );
|
||||
}
|
||||
},
|
||||
} ).fail( function( response ) {
|
||||
if ( window.console && window.console.log ) {
|
||||
console.log( response );
|
||||
}
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
EDD_Export.init();
|
||||
} );
|
@ -0,0 +1,174 @@
|
||||
/**
|
||||
* Import screen JS
|
||||
*/
|
||||
var EDD_Import = {
|
||||
|
||||
init: function() {
|
||||
this.submit();
|
||||
},
|
||||
|
||||
submit: function() {
|
||||
const self = this;
|
||||
|
||||
$( '.edd-import-form' ).ajaxForm( {
|
||||
beforeSubmit: self.before_submit,
|
||||
success: self.success,
|
||||
complete: self.complete,
|
||||
dataType: 'json',
|
||||
error: self.error,
|
||||
} );
|
||||
},
|
||||
|
||||
before_submit: function( arr, form, options ) {
|
||||
form.find( '.notice-wrap' ).remove();
|
||||
form.append( '<div class="notice-wrap"><div class="edd-progress"><div></div></div></div>' );
|
||||
|
||||
//check whether client browser fully supports all File API
|
||||
if ( window.File && window.FileReader && window.FileList && window.Blob ) {
|
||||
|
||||
// HTML5 File API is supported by browser
|
||||
|
||||
} else {
|
||||
const import_form = $( '.edd-import-form' ).find( '.edd-progress' ).parent().parent();
|
||||
const notice_wrap = import_form.find( '.notice-wrap' );
|
||||
|
||||
import_form.find( '.button:disabled' ).attr( 'disabled', false );
|
||||
|
||||
//Error for older unsupported browsers that doesn't support HTML5 File API
|
||||
notice_wrap.html( '<div class="update error"><p>' + edd_vars.unsupported_browser + '</p></div>' );
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
success: function( responseText, statusText, xhr, form ) {},
|
||||
|
||||
complete: function( xhr ) {
|
||||
const self = $( this ),
|
||||
response = jQuery.parseJSON( xhr.responseText );
|
||||
|
||||
if ( response.success ) {
|
||||
const form = $( '.edd-import-form .notice-wrap' ).parent();
|
||||
|
||||
form.find( '.edd-import-file-wrap,.notice-wrap' ).remove();
|
||||
form.find( '.edd-import-options' ).slideDown();
|
||||
|
||||
// Show column mapping
|
||||
let select = form.find( 'select.edd-import-csv-column' ),
|
||||
row = select.parents( 'tr' ).first(),
|
||||
options = '',
|
||||
columns = response.data.columns.sort( function( a, b ) {
|
||||
if ( a < b ) {
|
||||
return -1;
|
||||
}
|
||||
if ( a > b ) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} );
|
||||
|
||||
$.each( columns, function( key, value ) {
|
||||
options += '<option value="' + value + '">' + value + '</option>';
|
||||
} );
|
||||
|
||||
select.append( options );
|
||||
|
||||
select.on( 'change', function() {
|
||||
const key = $( this ).val();
|
||||
|
||||
if ( ! key ) {
|
||||
$( this ).parent().next().html( '' );
|
||||
} else if ( false !== response.data.first_row[ key ] ) {
|
||||
$( this ).parent().next().html( response.data.first_row[ key ] );
|
||||
} else {
|
||||
$( this ).parent().next().html( '' );
|
||||
}
|
||||
} );
|
||||
|
||||
$.each( select, function() {
|
||||
$( this ).val( $( this ).attr( 'data-field' ) ).change();
|
||||
} );
|
||||
|
||||
$( document.body ).on( 'click', '.edd-import-proceed', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
form.find( '.edd-import-proceed.button-primary' ).addClass( 'updating-message' );
|
||||
form.append( '<div class="notice-wrap"><div class="edd-progress"><div></div></div></div>' );
|
||||
|
||||
response.data.mapping = form.serialize();
|
||||
|
||||
EDD_Import.process_step( 1, response.data, self );
|
||||
} );
|
||||
} else {
|
||||
EDD_Import.error( xhr );
|
||||
}
|
||||
},
|
||||
|
||||
error: function( xhr ) {
|
||||
// Something went wrong. This will display error on form
|
||||
|
||||
const response = jQuery.parseJSON( xhr.responseText );
|
||||
const import_form = $( '.edd-import-form' ).find( '.edd-progress' ).parent().parent();
|
||||
const notice_wrap = import_form.find( '.notice-wrap' );
|
||||
|
||||
import_form.find( '.button:disabled' ).attr( 'disabled', false );
|
||||
|
||||
if ( response.data.error ) {
|
||||
notice_wrap.html( '<div class="update error"><p>' + response.data.error + '</p></div>' );
|
||||
} else {
|
||||
notice_wrap.remove();
|
||||
}
|
||||
},
|
||||
|
||||
process_step: function( step, import_data, self ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
form: import_data.form,
|
||||
nonce: import_data.nonce,
|
||||
class: import_data.class,
|
||||
upload: import_data.upload,
|
||||
mapping: import_data.mapping,
|
||||
action: 'edd_do_ajax_import',
|
||||
step: step,
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function( response ) {
|
||||
if ( 'done' === response.data.step || response.data.error ) {
|
||||
// We need to get the actual in progress form, not all forms on the page
|
||||
const import_form = $( '.edd-import-form' ).find( '.edd-progress' ).parent().parent();
|
||||
const notice_wrap = import_form.find( '.notice-wrap' );
|
||||
|
||||
import_form.find( '.button:disabled' ).attr( 'disabled', false );
|
||||
|
||||
if ( response.data.error ) {
|
||||
notice_wrap.html( '<div class="update error"><p>' + response.data.error + '</p></div>' );
|
||||
} else {
|
||||
import_form.find( '.edd-import-options' ).hide();
|
||||
$( 'html, body' ).animate( {
|
||||
scrollTop: import_form.parent().offset().top,
|
||||
}, 500 );
|
||||
|
||||
notice_wrap.html( '<div class="updated"><p>' + response.data.message + '</p></div>' );
|
||||
}
|
||||
} else {
|
||||
$( '.edd-progress div' ).animate( {
|
||||
width: response.data.percentage + '%',
|
||||
}, 50, function() {
|
||||
// Animation complete.
|
||||
} );
|
||||
|
||||
EDD_Import.process_step( parseInt( response.data.step ), import_data, self );
|
||||
}
|
||||
},
|
||||
} ).fail( function( response ) {
|
||||
if ( window.console && window.console.log ) {
|
||||
console.log( response );
|
||||
}
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
EDD_Import.init();
|
||||
} );
|
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Tools screen JS
|
||||
*/
|
||||
const EDD_Tools = {
|
||||
|
||||
init: function() {
|
||||
this.revoke_api_key();
|
||||
this.regenerate_api_key();
|
||||
this.create_api_key();
|
||||
this.recount_stats();
|
||||
},
|
||||
|
||||
revoke_api_key: function() {
|
||||
$( document.body ).on( 'click', '.edd-revoke-api-key', function( e ) {
|
||||
return confirm( edd_vars.revoke_api_key );
|
||||
} );
|
||||
},
|
||||
regenerate_api_key: function() {
|
||||
$( document.body ).on( 'click', '.edd-regenerate-api-key', function( e ) {
|
||||
return confirm( edd_vars.regenerate_api_key );
|
||||
} );
|
||||
},
|
||||
create_api_key: function() {
|
||||
$( document.body ).on( 'submit', '#api-key-generate-form', function( e ) {
|
||||
const input = $( 'input[type="text"][name="user_id"]' );
|
||||
|
||||
input.css( 'border-color', '#ddd' );
|
||||
|
||||
const user_id = input.val();
|
||||
if ( user_id.length < 1 || user_id === 0 ) {
|
||||
input.css( 'border-color', '#ff0000' );
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
},
|
||||
recount_stats: function() {
|
||||
$( document.body ).on( 'change', '#recount-stats-type', function() {
|
||||
const export_form = $( '#edd-tools-recount-form' ),
|
||||
selected_type = $( 'option:selected', this ).data( 'type' ),
|
||||
submit_button = $( '#recount-stats-submit' ),
|
||||
products = $( '#tools-product-dropdown' );
|
||||
|
||||
// Reset the form
|
||||
export_form.find( '.notice-wrap' ).remove();
|
||||
submit_button.attr( 'disabled', false ).removeClass( 'updated-message' );
|
||||
products.hide();
|
||||
$( '.edd-recount-stats-descriptions span' ).hide();
|
||||
|
||||
if ( 'recount-download' === selected_type ) {
|
||||
products.show();
|
||||
products.find( '.edd-select-chosen' ).css( 'width', 'auto' );
|
||||
} else if ( 'reset-stats' === selected_type ) {
|
||||
export_form.append( '<div class="notice-wrap"></div>' );
|
||||
const notice_wrap = export_form.find( '.notice-wrap' );
|
||||
notice_wrap.html( '<div class="notice notice-warning"><p><input type="checkbox" id="confirm-reset" name="confirm_reset_store" value="1" /> <label for="confirm-reset">' + edd_vars.reset_stats_warn + '</label></p></div>' );
|
||||
|
||||
$( '#recount-stats-submit' ).attr( 'disabled', true );
|
||||
} else {
|
||||
products.hide();
|
||||
products.val( 0 );
|
||||
}
|
||||
|
||||
$( '#' + selected_type ).show();
|
||||
} );
|
||||
|
||||
$( document.body ).on( 'change', '#confirm-reset', function() {
|
||||
const checked = $( this ).is( ':checked' );
|
||||
if ( checked ) {
|
||||
$( '#recount-stats-submit' ).attr( 'disabled', false );
|
||||
} else {
|
||||
$( '#recount-stats-submit' ).attr( 'disabled', true );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '#edd-tools-recount-form' ).submit( function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
const selection = $( '#recount-stats-type' ).val(),
|
||||
export_form = $( this ),
|
||||
selected_type = $( 'option:selected', this ).data( 'type' );
|
||||
|
||||
if ( 'reset-stats' === selected_type ) {
|
||||
const is_confirmed = $( '#confirm-reset' ).is( ':checked' );
|
||||
if ( is_confirmed ) {
|
||||
return true;
|
||||
}
|
||||
has_errors = true;
|
||||
}
|
||||
|
||||
export_form.find( '.notice-wrap' ).remove();
|
||||
export_form.append( '<div class="notice-wrap"></div>' );
|
||||
|
||||
var notice_wrap = export_form.find( '.notice-wrap' ),
|
||||
has_errors = false;
|
||||
|
||||
if ( null === selection || 0 === selection ) {
|
||||
// Needs to pick a method edd_vars.batch_export_no_class
|
||||
notice_wrap.html( '<div class="updated error"><p>' + edd_vars.batch_export_no_class + '</p></div>' );
|
||||
has_errors = true;
|
||||
}
|
||||
|
||||
if ( 'recount-download' === selected_type ) {
|
||||
const selected_download = $( 'select[name="download_id"]' ).val();
|
||||
if ( selected_download === 0 ) {
|
||||
// Needs to pick download edd_vars.batch_export_no_reqs
|
||||
notice_wrap.html( '<div class="updated error"><p>' + edd_vars.batch_export_no_reqs + '</p></div>' );
|
||||
has_errors = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( has_errors ) {
|
||||
export_form.find( 'button:disabled' ).attr( 'disabled', false ).removeClass( 'updated-message' );
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
EDD_Tools.init();
|
||||
} );
|
Reference in New Issue
Block a user