api-keys.js
5 years ago
api-keys.min.js
3 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
10 months ago
marketplace-suggestions.min.js
10 months ago
meta-boxes-coupon.js
1 year ago
meta-boxes-coupon.min.js
1 year ago
meta-boxes-order.js
1 month ago
meta-boxes-order.min.js
1 month ago
meta-boxes-product-variation.js
1 year ago
meta-boxes-product-variation.min.js
1 year ago
meta-boxes-product.js
1 month ago
meta-boxes-product.min.js
1 month ago
meta-boxes.js
4 months ago
meta-boxes.min.js
4 months ago
network-orders.js
8 years ago
network-orders.min.js
3 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
11 months ago
product-editor.min.js
11 months ago
product-ordering.js
3 months ago
product-ordering.min.js
3 months ago
quick-edit.js
1 year ago
quick-edit.min.js
1 year ago
reports.js
1 year ago
reports.min.js
1 year ago
settings-views-html-settings-tax.js
1 year ago
settings-views-html-settings-tax.min.js
1 year ago
settings.js
1 year ago
settings.min.js
1 year ago
system-status.js
3 months ago
system-status.min.js
3 months ago
term-ordering.js
3 months ago
term-ordering.min.js
3 months ago
users.js
5 years ago
users.min.js
3 years ago
variation-gallery.js
1 month ago
variation-gallery.min.js
1 month ago
wc-brands-enhanced-select.js
1 year ago
wc-brands-enhanced-select.min.js
1 year ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-customer-stock-notifications.js
10 months ago
wc-customer-stock-notifications.min.js
10 months 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
3 years ago
wc-product-export.js
1 year ago
wc-product-export.min.js
1 year ago
wc-product-import.js
3 years ago
wc-product-import.min.js
3 years ago
wc-recent-reviews-widget-async.js
4 months ago
wc-recent-reviews-widget-async.min.js
4 months ago
wc-setup.js
5 years ago
wc-setup.min.js
3 years ago
wc-shipping-classes.js
1 year ago
wc-shipping-classes.min.js
1 year ago
wc-shipping-providers.js
3 months ago
wc-shipping-providers.min.js
3 months ago
wc-shipping-zone-methods.js
6 months ago
wc-shipping-zone-methods.min.js
6 months ago
wc-shipping-zones.js
1 year ago
wc-shipping-zones.min.js
1 year ago
wc-status-widget-async.js
4 months ago
wc-status-widget-async.min.js
4 months ago
wc-status-widget.js
1 year ago
wc-status-widget.min.js
1 year ago
woocommerce_admin.js
1 month ago
woocommerce_admin.min.js
1 month ago
wc-product-export.js
115 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 | export_product_ids = $this.$form.find('input[name="product_ids"]').val() || ''; |
| 50 | |
| 51 | $.ajax( { |
| 52 | type: 'POST', |
| 53 | url: ajaxurl, |
| 54 | data: { |
| 55 | form : data, |
| 56 | action : 'woocommerce_do_ajax_product_export', |
| 57 | step : step, |
| 58 | columns : columns, |
| 59 | selected_columns : selected_columns, |
| 60 | export_meta : export_meta, |
| 61 | export_types : export_types, |
| 62 | export_category : export_category, |
| 63 | export_product_ids : export_product_ids, |
| 64 | filename : filename, |
| 65 | security : wc_product_export_params.export_nonce |
| 66 | }, |
| 67 | dataType: 'json', |
| 68 | success: function( response ) { |
| 69 | if ( response.success ) { |
| 70 | if ( 'done' === response.data.step ) { |
| 71 | $this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage ); |
| 72 | window.location = response.data.url; |
| 73 | setTimeout( function() { |
| 74 | $this.$form.removeClass( 'woocommerce-exporter__exporting' ); |
| 75 | $this.$form.find('.woocommerce-exporter-button').prop( 'disabled', false ); |
| 76 | }, 2000 ); |
| 77 | } else { |
| 78 | $this.$form.find('.woocommerce-exporter-progress').val( response.data.percentage ); |
| 79 | $this.processStep( parseInt( response.data.step, 10 ), data, response.data.columns, filename ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | } |
| 85 | } ).fail( function( response ) { |
| 86 | window.console.log( response ); |
| 87 | } ); |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * Handle fields per export type. |
| 92 | */ |
| 93 | productExportForm.prototype.exportTypeFields = function() { |
| 94 | var exportCategory = $( '.woocommerce-exporter-category' ); |
| 95 | |
| 96 | if ( -1 !== $.inArray( 'variation', $( this ).val() ) ) { |
| 97 | exportCategory.closest( 'tr' ).hide(); |
| 98 | exportCategory.val( '' ).trigger( 'change' ); // Reset WooSelect selected value. |
| 99 | } else { |
| 100 | exportCategory.closest( 'tr' ).show(); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * Function to call productExportForm on jquery selector. |
| 106 | */ |
| 107 | $.fn.wc_product_export_form = function() { |
| 108 | new productExportForm( this ); |
| 109 | return this; |
| 110 | }; |
| 111 | |
| 112 | $( '.woocommerce-exporter' ).wc_product_export_form(); |
| 113 | |
| 114 | })( jQuery, window ); |
| 115 |