/** * 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( '
' ); const notice_wrap = export_form.find( '.notice-wrap' ); notice_wrap.html( '
' + edd_vars.batch_export_no_class + '
' + edd_vars.batch_export_no_reqs + '