api-keys.js
5 years ago
api-keys.min.js
2 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
4 years ago
marketplace-suggestions.min.js
2 years ago
meta-boxes-coupon.js
5 years ago
meta-boxes-coupon.min.js
2 years ago
meta-boxes-order.js
2 years ago
meta-boxes-order.min.js
2 years ago
meta-boxes-product-variation.js
2 years ago
meta-boxes-product-variation.min.js
2 years ago
meta-boxes-product.js
2 years ago
meta-boxes-product.min.js
2 years ago
meta-boxes.js
2 years ago
meta-boxes.min.js
2 years ago
network-orders.js
8 years ago
network-orders.min.js
2 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
3 years ago
product-editor.min.js
2 years ago
product-ordering.js
3 years ago
product-ordering.min.js
2 years ago
quick-edit.js
4 years ago
quick-edit.min.js
2 years ago
reports.js
5 years ago
reports.min.js
2 years ago
settings-views-html-settings-tax.js
3 years ago
settings-views-html-settings-tax.min.js
2 years ago
settings.js
4 years ago
settings.min.js
2 years ago
system-status.js
3 years ago
system-status.min.js
2 years ago
term-ordering.js
4 years ago
term-ordering.min.js
2 years ago
users.js
5 years ago
users.min.js
2 years ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-enhanced-select.js
2 years ago
wc-enhanced-select.min.js
2 years ago
wc-orders.js
3 years ago
wc-orders.min.js
2 years ago
wc-product-export.js
5 years ago
wc-product-export.min.js
2 years ago
wc-product-import.js
3 years ago
wc-product-import.min.js
2 years ago
wc-setup.js
5 years ago
wc-setup.min.js
2 years ago
wc-shipping-classes.js
2 years ago
wc-shipping-classes.min.js
2 years ago
wc-shipping-zone-methods.js
2 years ago
wc-shipping-zone-methods.min.js
2 years ago
wc-shipping-zones.js
2 years ago
wc-shipping-zones.min.js
2 years ago
wc-status-widget.js
3 years ago
wc-status-widget.min.js
3 years ago
woocommerce_admin.js
2 years ago
woocommerce_admin.min.js
2 years ago
wc-product-export.js
113 lines
| 1 | /*global ajaxurl, wc_product_export_params */ |
| 2 | ;(function ( $, window ) { |
| 3 | /** |
| 4 | * productExportForm handles the export process. |
| 5 | */ |
| 6 | var productExportForm = function( $form ) { |
| 7 | this.$form = $form; |
| 8 | this.xhr = false; |
| 9 | |
| 10 | // Initial state. |
| 11 | this.$form.find('.woocommerce-exporter-progress').val( 0 ); |
| 12 | |
| 13 | // Methods. |
| 14 | this.processStep = this.processStep.bind( this ); |
| 15 | |
| 16 | // Events. |
| 17 | $form.on( 'submit', { productExportForm: this }, this.onSubmit ); |
| 18 | $form.find( '.woocommerce-exporter-types' ).on( 'change', { productExportForm: this }, this.exportTypeFields ); |
| 19 | }; |
| 20 | |
| 21 | /** |
| 22 | * Handle export form submission. |
| 23 | */ |
| 24 | productExportForm.prototype.onSubmit = function( event ) { |
| 25 | event.preventDefault(); |
| 26 | |
| 27 | var currentDate = new Date(), |
| 28 | day = currentDate.getDate(), |
| 29 | month = currentDate.getMonth() + 1, |
| 30 | year = currentDate.getFullYear(), |
| 31 | timestamp = currentDate.getTime(), |
| 32 | filename = 'wc-product-export-' + day + '-' + month + '-' + year + '-' + timestamp + '.csv'; |
| 33 | |
| 34 | event.data.productExportForm.$form.addClass( 'woocommerce-exporter__exporting' ); |
| 35 | event.data.productExportForm.$form.find('.woocommerce-exporter-progress').val( 0 ); |
| 36 | event.data.productExportForm.$form.find('.woocommerce-exporter-button').prop( 'disabled', true ); |
| 37 | event.data.productExportForm.processStep( 1, $( this ).serialize(), '', filename ); |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * Process the current export step. |
| 42 | */ |
| 43 | productExportForm.prototype.processStep = function( step, data, columns, filename ) { |
| 44 | var $this = this, |
| 45 | selected_columns = $( '.woocommerce-exporter-columns' ).val(), |
| 46 | export_meta = $( '#woocommerce-exporter-meta:checked' ).length ? 1: 0, |
| 47 | export_types = $( '.woocommerce-exporter-types' ).val(), |
| 48 | export_category = $( '.woocommerce-exporter-category' ).val(); |
| 49 | |
| 50 | $.ajax( { |
| 51 | type: 'POST', |
| 52 | url: ajaxurl, |
| 53 | data: { |
| 54 | form : data, |
| 55 | action : 'woocommerce_do_ajax_product_export', |
| 56 | step : step, |
| 57 | columns : columns, |
| 58 | selected_columns : selected_columns, |
| 59 | export_meta : export_meta, |
| 60 | export_types : export_types, |
| 61 | export_category : export_category, |
| 62 | filename : filename, |
| 63 | security : wc_product_export_params.export_nonce |
| 64 | }, |
| 65 | dataType: 'json', |
| 66 | success: function( response ) { |
| 67 | if ( response.success ) { |
| 68 | if ( 'done' === response.data.step ) { |
| 69 | $this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage ); |
| 70 | window.location = response.data.url; |
| 71 | setTimeout( function() { |
| 72 | $this.$form.removeClass( 'woocommerce-exporter__exporting' ); |
| 73 | $this.$form.find('.woocommerce-exporter-button').prop( 'disabled', false ); |
| 74 | }, 2000 ); |
| 75 | } else { |
| 76 | $this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage ); |
| 77 | $this.processStep( parseInt( response.data.step, 10 ), data, response.data.columns, filename ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | } |
| 83 | } ).fail( function( response ) { |
| 84 | window.console.log( response ); |
| 85 | } ); |
| 86 | }; |
| 87 | |
| 88 | /** |
| 89 | * Handle fields per export type. |
| 90 | */ |
| 91 | productExportForm.prototype.exportTypeFields = function() { |
| 92 | var exportCategory = $( '.woocommerce-exporter-category' ); |
| 93 | |
| 94 | if ( -1 !== $.inArray( 'variation', $( this ).val() ) ) { |
| 95 | exportCategory.closest( 'tr' ).hide(); |
| 96 | exportCategory.val( '' ).trigger( 'change' ); // Reset WooSelect selected value. |
| 97 | } else { |
| 98 | exportCategory.closest( 'tr' ).show(); |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | /** |
| 103 | * Function to call productExportForm on jquery selector. |
| 104 | */ |
| 105 | $.fn.wc_product_export_form = function() { |
| 106 | new productExportForm( this ); |
| 107 | return this; |
| 108 | }; |
| 109 | |
| 110 | $( '.woocommerce-exporter' ).wc_product_export_form(); |
| 111 | |
| 112 | })( jQuery, window ); |
| 113 |