api-keys.js
5 years ago
api-keys.min.js
5 years ago
backbone-modal.js
5 years ago
backbone-modal.min.js
5 years ago
marketplace-suggestions.js
4 years ago
marketplace-suggestions.min.js
3 years ago
meta-boxes-coupon.js
5 years ago
meta-boxes-coupon.min.js
3 years ago
meta-boxes-order.js
3 years ago
meta-boxes-order.min.js
3 years ago
meta-boxes-product-variation.js
3 years ago
meta-boxes-product-variation.min.js
3 years ago
meta-boxes-product.js
3 years ago
meta-boxes-product.min.js
3 years ago
meta-boxes.js
3 years ago
meta-boxes.min.js
3 years ago
network-orders.js
8 years ago
network-orders.min.js
3 years ago
product-editor.js
3 years ago
product-editor.min.js
3 years ago
product-ordering.js
3 years ago
product-ordering.min.js
3 years ago
quick-edit.js
4 years ago
quick-edit.min.js
3 years ago
reports.js
5 years ago
reports.min.js
3 years ago
settings-views-html-settings-tax.js
5 years ago
settings-views-html-settings-tax.min.js
3 years ago
settings.js
4 years ago
settings.min.js
3 years ago
system-status.js
3 years ago
system-status.min.js
3 years ago
term-ordering.js
3 years ago
term-ordering.min.js
3 years ago
users.js
5 years ago
users.min.js
3 years ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-enhanced-select.js
3 years ago
wc-enhanced-select.min.js
3 years ago
wc-orders.js
3 years ago
wc-orders.min.js
3 years ago
wc-product-export.js
5 years ago
wc-product-export.min.js
5 years ago
wc-product-import.js
3 years ago
wc-product-import.min.js
3 years ago
wc-setup.js
5 years ago
wc-setup.min.js
3 years ago
wc-shipping-classes.js
5 years ago
wc-shipping-classes.min.js
3 years ago
wc-shipping-zone-methods.js
4 years ago
wc-shipping-zone-methods.min.js
3 years ago
wc-shipping-zones.js
4 years ago
wc-shipping-zones.min.js
3 years ago
wc-status-widget.js
4 years ago
wc-status-widget.min.js
4 years ago
woocommerce_admin.js
3 years ago
woocommerce_admin.min.js
3 years ago
network-orders.js
91 lines
| 1 | /*global woocommerce_network_orders */ |
| 2 | (function( $, _, undefined ) { |
| 3 | |
| 4 | if ( 'undefined' === typeof woocommerce_network_orders ) { |
| 5 | return; |
| 6 | } |
| 7 | |
| 8 | var orders = [], |
| 9 | promises = [], // Track completion (pass or fail) of ajax requests. |
| 10 | deferred = [], // Tracks the ajax deferreds. |
| 11 | $tbody = $( document.getElementById( 'network-orders-tbody' ) ), |
| 12 | template = _.template( $( document.getElementById( 'network-orders-row-template') ).text() ), |
| 13 | $loadingIndicator = $( document.getElementById( 'woocommerce-network-order-table-loading' ) ), |
| 14 | $orderTable = $( document.getElementById( 'woocommerce-network-order-table' ) ), |
| 15 | $noneFound = $( document.getElementById( 'woocommerce-network-orders-no-orders' ) ); |
| 16 | |
| 17 | // No sites, so bail. |
| 18 | if ( ! woocommerce_network_orders.sites.length ) { |
| 19 | $loadingIndicator.removeClass( 'is-active' ); |
| 20 | $orderTable.removeClass( 'is-active' ); |
| 21 | $noneFound.addClass( 'is-active' ); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $.each( woocommerce_network_orders.sites, function( index, value ) { |
| 26 | promises[ index ] = $.Deferred(); |
| 27 | deferred.push( $.ajax( { |
| 28 | url : woocommerce_network_orders.order_endpoint, |
| 29 | data: { |
| 30 | _wpnonce: woocommerce_network_orders.nonce, |
| 31 | network_orders: true, |
| 32 | blog_id: value |
| 33 | }, |
| 34 | type: 'GET' |
| 35 | } ).success(function( response ) { |
| 36 | var orderindex; |
| 37 | |
| 38 | for ( orderindex in response ) { |
| 39 | orders.push( response[ orderindex ] ); |
| 40 | } |
| 41 | |
| 42 | promises[ index ].resolve(); |
| 43 | }).fail(function (){ |
| 44 | promises[ index ].resolve(); |
| 45 | }) ); |
| 46 | } ); |
| 47 | |
| 48 | if ( promises.length > 0 ) { |
| 49 | $.when.apply( $, promises ).done( function() { |
| 50 | var orderindex, |
| 51 | currentOrder; |
| 52 | |
| 53 | // Sort orders, newest first |
| 54 | orders.sort(function( a, b ) { |
| 55 | var adate, bdate; |
| 56 | |
| 57 | adate = Date.parse( a.date_created_gmt ); |
| 58 | bdate = Date.parse( b.date_created_gmt ); |
| 59 | |
| 60 | if ( adate === bdate ) { |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | if ( adate < bdate ) { |
| 65 | return 1; |
| 66 | } else { |
| 67 | return -1; |
| 68 | } |
| 69 | }); |
| 70 | |
| 71 | if ( orders.length > 0 ) { |
| 72 | for ( orderindex in orders ) { |
| 73 | currentOrder = orders[ orderindex ]; |
| 74 | |
| 75 | $tbody.append( template( currentOrder ) ); |
| 76 | } |
| 77 | |
| 78 | $noneFound.removeClass( 'is-active' ); |
| 79 | $loadingIndicator.removeClass( 'is-active' ); |
| 80 | $orderTable.addClass( 'is-active' ); |
| 81 | } else { |
| 82 | $noneFound.addClass( 'is-active' ); |
| 83 | $loadingIndicator.removeClass( 'is-active' ); |
| 84 | $orderTable.removeClass( 'is-active' ); |
| 85 | } |
| 86 | |
| 87 | } ); |
| 88 | } |
| 89 | |
| 90 | })( jQuery, _ ); |
| 91 |