PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / assets / js / admin / wc-orders.js
wc-orders.js
102 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global wc_orders_params */
2 jQuery( function( $ ) {
3
4 if ( typeof wc_orders_params === 'undefined' ) {
5 return false;
6 }
7
8 /**
9 * WCOrdersTable class.
10 */
11 var WCOrdersTable = function() {
12
13 const SELECTORS = [
14 // WordPress 7.1 renders primary order cells as th instead of td.
15 ".post-type-shop_order .wp-list-table tbody td:not(.check-column)",
16 ".post-type-shop_order .wp-list-table tbody th:not(.check-column)",
17 ".woocommerce_page_wc-orders .wp-list-table.orders tbody td:not(.check-column)",
18 ".woocommerce_page_wc-orders .wp-list-table.orders tbody th:not(.check-column)"
19 ]
20
21 $( document )
22 .on(
23 'click',
24 SELECTORS.join( ', ' ),
25 this.onRowClick
26 )
27 .on( 'click', '.order-preview:not(.disabled)', this.onPreview );
28 };
29
30 /**
31 * Click a row.
32 */
33 WCOrdersTable.prototype.onRowClick = function( e ) {
34 if ( $( e.target ).filter( 'a, a *, .no-link, .no-link *, button, button *' ).length ) {
35 return true;
36 }
37
38 if ( window.getSelection && window.getSelection().toString().length ) {
39 return true;
40 }
41
42 var $row = $( this ).closest( 'tr' ),
43 href = $row.find( 'a.order-view' ).attr( 'href' );
44
45 if ( href && href.length ) {
46 e.preventDefault();
47
48 if ( e.metaKey || e.ctrlKey ) {
49 window.open( href, '_blank' );
50 } else {
51 window.location = href;
52 }
53 }
54 };
55
56 /**
57 * Preview an order.
58 */
59 WCOrdersTable.prototype.onPreview = function() {
60 var $previewButton = $( this ),
61 $order_id = $previewButton.data( 'orderId' );
62
63 if ( $previewButton.data( 'order-data' ) ) {
64 $( this ).WCBackboneModal({
65 template: 'wc-modal-view-order',
66 variable : $previewButton.data( 'orderData' )
67 });
68 } else {
69 $previewButton.addClass( 'disabled' );
70
71 $.ajax({
72 url: wc_orders_params.ajax_url,
73 data: {
74 order_id: $order_id,
75 action : 'woocommerce_get_order_details',
76 security: wc_orders_params.preview_nonce
77 },
78 type: 'GET',
79 success: function( response ) {
80 $( '.order-preview' ).removeClass( 'disabled' );
81
82 if ( response.success ) {
83 $previewButton.data( 'orderData', response.data );
84
85 $( this ).WCBackboneModal({
86 template: 'wc-modal-view-order',
87 variable : response.data
88 });
89 }
90 }
91 });
92 }
93 return false;
94
95 };
96
97 /**
98 * Init WCOrdersTable.
99 */
100 new WCOrdersTable();
101 } );
102