2015-07-08 05:19:56 +00:00
|
|
|
/*global woocommerce_admin_meta_boxes, woocommerce_admin, accounting, woocommerce_admin_meta_boxes_order */
|
2014-07-16 18:11:48 +00:00
|
|
|
jQuery( function ( $ ) {
|
2013-11-12 17:01:13 +00:00
|
|
|
|
2014-07-16 18:41:18 +00:00
|
|
|
/**
|
2015-01-12 15:43:13 +00:00
|
|
|
* Order Data Panel
|
2014-07-16 18:41:18 +00:00
|
|
|
*/
|
2015-01-12 15:43:13 +00:00
|
|
|
var wc_meta_boxes_order = {
|
|
|
|
states: null,
|
|
|
|
init: function() {
|
|
|
|
if ( ! ( typeof woocommerce_admin_meta_boxes_order === 'undefined' || typeof woocommerce_admin_meta_boxes_order.countries === 'undefined' ) ) {
|
|
|
|
/* State/Country select boxes */
|
|
|
|
this.states = $.parseJSON( woocommerce_admin_meta_boxes_order.countries.replace( /"/g, '"' ) );
|
2014-07-16 18:41:18 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$( '.js_field-country' ).select2().change( this.change_country );
|
|
|
|
$( '.js_field-country' ).trigger( 'change', [ true ] );
|
2015-04-13 15:37:22 +00:00
|
|
|
$( document.body ).on( 'change', 'select.js_field-state', this.change_state );
|
2015-01-12 15:43:13 +00:00
|
|
|
$( '#woocommerce-order-actions input, #woocommerce-order-actions a' ).click(function() {
|
|
|
|
window.onbeforeunload = '';
|
|
|
|
});
|
|
|
|
$( 'a.edit_address' ).click( this.edit_address );
|
2015-05-15 11:52:23 +00:00
|
|
|
$( 'a.billing-same-as-shipping' ).on( 'click', this.copy_billing_to_shipping );
|
|
|
|
$( 'a.load_customer_billing' ).on( 'click', this.load_billing );
|
|
|
|
$( 'a.load_customer_shipping' ).on( 'click', this.load_shipping );
|
|
|
|
$( '#customer_user' ).on( 'change', this.change_customer_user );
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-08-01 04:27:22 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
change_country: function( e, stickValue ) {
|
2014-08-01 04:47:03 +00:00
|
|
|
// Check for stickValue before using it
|
|
|
|
if ( typeof stickValue === 'undefined' ){
|
|
|
|
stickValue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent if we don't have the metabox data
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( wc_meta_boxes_order.states === null ){
|
2014-08-01 04:47:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $this = $( this ),
|
|
|
|
country = $this.val(),
|
2015-05-15 11:52:23 +00:00
|
|
|
$state = $this.parents( 'div.edit_address' ).find( ':input.js_field-state' ),
|
2014-08-01 04:47:03 +00:00
|
|
|
$parent = $state.parent(),
|
|
|
|
input_name = $state.attr( 'name' ),
|
|
|
|
input_id = $state.attr( 'id' ),
|
2014-08-02 21:34:30 +00:00
|
|
|
value = $this.data( 'woocommerce.stickState-' + country ) ? $this.data( 'woocommerce.stickState-' + country ) : $state.val(),
|
2014-08-01 04:47:03 +00:00
|
|
|
placeholder = $state.attr( 'placeholder' );
|
|
|
|
|
|
|
|
if ( stickValue ){
|
|
|
|
$this.data( 'woocommerce.stickState-' + country, value );
|
|
|
|
}
|
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
// Remove the previous DOM element
|
|
|
|
$parent.show().find( '.select2-container' ).remove();
|
2014-08-02 21:34:30 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( ! $.isEmptyObject( wc_meta_boxes_order.states[ country ] ) ) {
|
2014-08-01 04:47:03 +00:00
|
|
|
var $states_select = $( '<select name="' + input_name + '" id="' + input_id + '" class="js_field-state select short" placeholder="' + placeholder + '"></select>' ),
|
2015-01-12 15:43:13 +00:00
|
|
|
state = wc_meta_boxes_order.states[ country ];
|
2014-08-01 04:47:03 +00:00
|
|
|
|
|
|
|
$states_select.append( $( '<option value="">' + woocommerce_admin_meta_boxes_order.i18n_select_state_text + '</option>' ) );
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
$.each( state, function( index ) {
|
2014-08-01 04:47:03 +00:00
|
|
|
$states_select.append( $( '<option value="' + index + '">' + state[ index ] + '</option>' ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$states_select.val( value );
|
|
|
|
|
|
|
|
$state.replaceWith( $states_select );
|
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$states_select.show().select2().hide().change();
|
2014-08-01 04:47:03 +00:00
|
|
|
} else {
|
2014-11-11 11:24:02 +00:00
|
|
|
$state.replaceWith( '<input type="text" class="js_field-state" name="' + input_name + '" id="' + input_id + '" value="' + value + '" placeholder="' + placeholder + '" />' );
|
2014-08-01 04:47:03 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 09:04:23 +00:00
|
|
|
// This event has a typo - deprecated in 2.5.0
|
2015-04-13 15:37:22 +00:00
|
|
|
$( document.body ).trigger( 'contry-change.woocommerce', [country, $( this ).closest( 'div' )] );
|
2015-10-01 09:04:23 +00:00
|
|
|
$( document.body ).trigger( 'country-change.woocommerce', [country, $( this ).closest( 'div' )] );
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-08-01 04:27:22 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
change_state: function() {
|
2014-08-01 04:27:22 +00:00
|
|
|
// Here we will find if state value on a select has changed and stick it to the country data
|
|
|
|
var $this = $( this ),
|
|
|
|
state = $this.val(),
|
2015-05-15 11:52:23 +00:00
|
|
|
$country = $this.parents( 'div.edit_address' ).find( ':input.js_field-country' ),
|
2014-08-01 04:27:22 +00:00
|
|
|
country = $country.val();
|
|
|
|
|
|
|
|
$country.data( 'woocommerce.stickState-' + country, state );
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
init_tiptip: function() {
|
|
|
|
$( '#tiptip_holder' ).removeAttr( 'style' );
|
|
|
|
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
|
|
|
$( '.tips' ).tipTip({
|
|
|
|
'attribute': 'data-tip',
|
|
|
|
'fadeIn': 50,
|
|
|
|
'fadeOut': 50,
|
|
|
|
'delay': 200
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
edit_address: function( e ) {
|
|
|
|
e.preventDefault();
|
2014-07-17 20:17:54 +00:00
|
|
|
$( this ).hide();
|
2015-05-15 11:52:23 +00:00
|
|
|
$( this ).parent().find( 'a:not(.edit_address)' ).show();
|
2015-01-12 15:43:13 +00:00
|
|
|
$( this ).closest( '.order_data_column' ).find( 'div.address' ).hide();
|
|
|
|
$( this ).closest( '.order_data_column' ).find( 'div.edit_address' ).show();
|
|
|
|
},
|
2014-07-17 20:17:54 +00:00
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
change_customer_user: function() {
|
2015-05-15 11:52:23 +00:00
|
|
|
if ( ! $( '#_billing_country' ).val() ) {
|
|
|
|
$( 'a.edit_address' ).click();
|
|
|
|
wc_meta_boxes_order.load_billing( true );
|
|
|
|
wc_meta_boxes_order.load_shipping( true );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
load_billing: function( force ) {
|
|
|
|
if ( true === force || window.confirm( woocommerce_admin_meta_boxes.load_billing ) ) {
|
2014-07-07 15:45:08 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $( '#customer_user' ).val();
|
2014-07-07 15:45:08 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( ! user_id ) {
|
|
|
|
window.alert( woocommerce_admin_meta_boxes.no_customer_selected );
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-10 10:25:50 +00:00
|
|
|
|
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'billing',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_admin_meta_boxes.get_customer_details_nonce
|
2014-07-10 10:25:50 +00:00
|
|
|
};
|
|
|
|
|
2015-05-15 11:52:23 +00:00
|
|
|
$( this ).closest( 'div.edit_address' ).block({
|
2015-01-12 15:43:13 +00:00
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-16 18:41:18 +00:00
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2014-08-31 06:25:22 +00:00
|
|
|
success: function( response ) {
|
2015-10-27 15:53:54 +00:00
|
|
|
if ( response ) {
|
|
|
|
$.each( response, function( key, data ) {
|
|
|
|
$( ':input#_' + key ).val( data ).change();
|
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
2015-05-15 11:52:23 +00:00
|
|
|
$( 'div.edit_address' ).unblock();
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2014-07-16 18:41:18 +00:00
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
2015-05-15 11:52:23 +00:00
|
|
|
load_shipping: function( force ) {
|
|
|
|
if ( true === force || window.confirm( woocommerce_admin_meta_boxes.load_shipping ) ) {
|
2014-07-16 20:12:33 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
// Get user ID to load data for
|
|
|
|
var user_id = $( '#customer_user' ).val();
|
|
|
|
|
|
|
|
if ( ! user_id ) {
|
|
|
|
window.alert( woocommerce_admin_meta_boxes.no_customer_selected );
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-16 20:12:33 +00:00
|
|
|
|
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
user_id: user_id,
|
|
|
|
type_to_load: 'shipping',
|
|
|
|
action: 'woocommerce_get_customer_details',
|
|
|
|
security: woocommerce_admin_meta_boxes.get_customer_details_nonce
|
2014-07-16 20:12:33 +00:00
|
|
|
};
|
|
|
|
|
2015-05-15 11:52:23 +00:00
|
|
|
$( this ).closest( 'div.edit_address' ).block({
|
2015-01-12 15:43:13 +00:00
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-16 20:12:33 +00:00
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2014-08-31 06:25:22 +00:00
|
|
|
success: function( response ) {
|
2015-10-27 15:53:54 +00:00
|
|
|
if ( response ) {
|
|
|
|
$.each( response, function( key, data ) {
|
|
|
|
$( ':input#_' + key ).val( data ).change();
|
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
2015-05-15 11:52:23 +00:00
|
|
|
$( 'div.edit_address' ).unblock();
|
2014-07-16 20:12:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
copy_billing_to_shipping: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.copy_billing ) ) {
|
2015-10-27 15:53:54 +00:00
|
|
|
$('.order_data_column :input[name^="_billing_"]').each( function() {
|
|
|
|
var input_name = $(this).attr('name');
|
|
|
|
input_name = input_name.replace( '_billing_', '_shipping_' );
|
|
|
|
$( ':input#' + input_name ).val( $(this).val() ).change();
|
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-08 05:19:56 +00:00
|
|
|
};
|
2015-01-12 15:43:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Order Items Panel
|
|
|
|
*/
|
|
|
|
var wc_meta_boxes_order_items = {
|
|
|
|
init: function() {
|
2015-01-15 16:30:42 +00:00
|
|
|
this.stupidtable.init();
|
2015-01-12 15:43:13 +00:00
|
|
|
|
|
|
|
$( '#woocommerce-order-items' )
|
|
|
|
.on( 'click', 'button.add-line-item', this.add_line_item )
|
|
|
|
.on( 'click', 'button.refund-items', this.refund_items )
|
|
|
|
.on( 'click', '.cancel-action', this.cancel )
|
|
|
|
.on( 'click', 'button.add-order-item', this.add_item )
|
|
|
|
.on( 'click', 'button.add-order-fee', this.add_fee )
|
|
|
|
.on( 'click', 'button.add-order-shipping', this.add_shipping )
|
|
|
|
.on( 'click', 'button.add-order-tax', this.add_tax )
|
|
|
|
.on( 'click', 'input.check-column', this.bulk_actions.check_column )
|
|
|
|
.on( 'click', '.do_bulk_action', this.bulk_actions.do_bulk_action )
|
|
|
|
.on( 'click', 'button.calculate-action', this.calculate_totals )
|
|
|
|
.on( 'click', 'button.save-action', this.save_line_items )
|
|
|
|
.on( 'click', 'a.delete-order-tax', this.delete_tax )
|
|
|
|
.on( 'click', 'button.calculate-tax-action', this.calculate_tax )
|
|
|
|
.on( 'click', 'a.edit-order-item', this.edit_item )
|
|
|
|
.on( 'click', 'a.delete-order-item', this.delete_item )
|
|
|
|
|
|
|
|
// Refunds
|
|
|
|
.on( 'click', '.delete_refund', this.refunds.delete_refund )
|
|
|
|
.on( 'click', 'button.do-api-refund, button.do-manual-refund', this.refunds.do_refund )
|
2015-02-11 15:00:28 +00:00
|
|
|
.on( 'change', '.refund input.refund_line_total, .refund input.refund_line_tax', this.refunds.input_changed )
|
2015-01-12 15:43:13 +00:00
|
|
|
.on( 'change keyup', '.wc-order-refund-items #refund_amount', this.refunds.amount_changed )
|
|
|
|
.on( 'change', 'input.refund_order_item_qty', this.refunds.refund_quantity_changed )
|
|
|
|
|
|
|
|
// Qty
|
|
|
|
.on( 'change', 'input.quantity', this.quantity_changed )
|
|
|
|
|
|
|
|
// Subtotal/total
|
|
|
|
.on( 'keyup', '.woocommerce_order_items .split-input input:eq(0)', function() {
|
|
|
|
var $subtotal = $( this ).next();
|
|
|
|
if ( $subtotal.val() === '' || $subtotal.is( '.match-total' ) ) {
|
|
|
|
$subtotal.val( $( this ).val() ).addClass( 'match-total' );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.on( 'keyup', '.woocommerce_order_items .split-input input:eq(1)', function() {
|
|
|
|
$( this ).removeClass( 'match-total' );
|
|
|
|
})
|
|
|
|
|
|
|
|
// Meta
|
|
|
|
.on( 'click', 'button.add_order_item_meta', this.item_meta.add )
|
|
|
|
.on( 'click', 'button.remove_order_item_meta', this.item_meta.remove );
|
|
|
|
|
2015-04-13 16:23:06 +00:00
|
|
|
$( document.body )
|
2015-01-12 15:43:13 +00:00
|
|
|
.on( 'wc_backbone_modal_loaded', this.backbone.init )
|
|
|
|
.on( 'wc_backbone_modal_response', this.backbone.response );
|
|
|
|
},
|
|
|
|
|
|
|
|
block: function() {
|
|
|
|
$( '#woocommerce-order-items' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
unblock: function() {
|
|
|
|
$( '#woocommerce-order-items' ).unblock();
|
|
|
|
},
|
|
|
|
|
|
|
|
reload_items: function() {
|
|
|
|
var data = {
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
action: 'woocommerce_load_order_items',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2015-01-15 16:30:42 +00:00
|
|
|
wc_meta_boxes_order_items.stupidtable.init();
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
// When the qty is changed, increase or decrease costs
|
2015-01-12 15:43:13 +00:00
|
|
|
quantity_changed: function() {
|
2014-07-22 21:07:44 +00:00
|
|
|
var $row = $( this ).closest( 'tr.item' );
|
|
|
|
var qty = $( this ).val();
|
|
|
|
var o_qty = $( this ).attr( 'data-qty' );
|
|
|
|
var line_total = $( 'input.line_total', $row );
|
|
|
|
var line_subtotal = $( 'input.line_subtotal', $row );
|
|
|
|
|
|
|
|
// Totals
|
2014-09-10 14:07:24 +00:00
|
|
|
var unit_total = accounting.unformat( line_total.attr( 'data-total' ), woocommerce_admin.mon_decimal_point ) / o_qty;
|
2014-07-22 21:07:44 +00:00
|
|
|
line_total.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_total * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
|
|
|
);
|
|
|
|
|
2014-09-10 14:07:24 +00:00
|
|
|
var unit_subtotal = accounting.unformat( line_subtotal.attr( 'data-subtotal' ), woocommerce_admin.mon_decimal_point ) / o_qty;
|
2014-07-22 21:07:44 +00:00
|
|
|
line_subtotal.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_subtotal * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
|
|
|
);
|
|
|
|
|
|
|
|
// Taxes
|
2014-08-31 06:25:22 +00:00
|
|
|
$( 'td.line_tax', $row ).each(function() {
|
2014-07-22 21:07:44 +00:00
|
|
|
var line_total_tax = $( 'input.line_tax', $( this ) );
|
2014-09-10 14:07:24 +00:00
|
|
|
var unit_total_tax = accounting.unformat( line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty;
|
2014-07-22 21:07:44 +00:00
|
|
|
if ( 0 < unit_total_tax ) {
|
|
|
|
line_total_tax.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_total_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var line_subtotal_tax = $( 'input.line_subtotal_tax', $( this ) );
|
2014-09-10 14:07:24 +00:00
|
|
|
var unit_subtotal_tax = accounting.unformat( line_subtotal_tax.attr( 'data-subtotal_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty;
|
2014-07-22 21:07:44 +00:00
|
|
|
if ( 0 < unit_subtotal_tax ) {
|
|
|
|
line_subtotal_tax.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
|
2014-07-22 19:52:36 +00:00
|
|
|
$( this ).trigger( 'quantity_changed' );
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-07-10 10:25:50 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
add_line_item: function() {
|
2014-07-17 02:08:59 +00:00
|
|
|
$( 'div.wc-order-add-item' ).slideDown();
|
|
|
|
$( 'div.wc-order-bulk-actions' ).slideUp();
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refund_items: function() {
|
2014-07-17 02:08:59 +00:00
|
|
|
$( 'div.wc-order-refund-items' ).slideDown();
|
|
|
|
$( 'div.wc-order-bulk-actions' ).slideUp();
|
|
|
|
$( 'div.wc-order-totals-items' ).slideUp();
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( 'div.refund' ).show();
|
2014-07-25 16:35:59 +00:00
|
|
|
$( '.wc-order-edit-line-item .wc-order-edit-line-item-actions' ).hide();
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function() {
|
2014-07-17 02:08:59 +00:00
|
|
|
$( this ).closest( 'div.wc-order-data-row' ).slideUp();
|
|
|
|
$( 'div.wc-order-bulk-actions' ).slideDown();
|
|
|
|
$( 'div.wc-order-totals-items' ).slideDown();
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( 'div.refund' ).hide();
|
2014-07-25 16:35:59 +00:00
|
|
|
$( '.wc-order-edit-line-item .wc-order-edit-line-item-actions' ).show();
|
2014-07-17 02:08:59 +00:00
|
|
|
|
2014-07-17 20:17:54 +00:00
|
|
|
// Reload the items
|
|
|
|
if ( 'true' === $( this ).attr( 'data-reload' ) ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.reload_items();
|
2014-07-17 20:17:54 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
add_item: function() {
|
2014-07-21 02:58:34 +00:00
|
|
|
$( this ).WCBackboneModal({
|
2015-08-06 04:37:53 +00:00
|
|
|
template: 'wc-modal-add-products'
|
2014-07-21 02:58:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
add_fee: function() {
|
|
|
|
wc_meta_boxes_order_items.block();
|
2014-07-16 18:41:18 +00:00
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_order_fee',
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
2014-08-31 06:25:22 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
2014-07-22 13:18:11 +00:00
|
|
|
$( 'table.woocommerce_order_items tbody#order_fee_line_items' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.unblock();
|
2014-07-16 18:41:18 +00:00
|
|
|
});
|
2014-07-21 02:58:34 +00:00
|
|
|
|
2014-07-16 18:41:18 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
add_shipping: function() {
|
|
|
|
wc_meta_boxes_order_items.block();
|
2013-08-16 15:43:26 +00:00
|
|
|
|
2012-11-12 18:53:40 +00:00
|
|
|
var data = {
|
2014-07-16 18:41:18 +00:00
|
|
|
action: 'woocommerce_add_order_shipping',
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2012-11-12 18:53:40 +00:00
|
|
|
};
|
|
|
|
|
2014-08-31 06:25:22 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
2014-07-22 13:18:11 +00:00
|
|
|
$( 'table.woocommerce_order_items tbody#order_shipping_line_items' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.unblock();
|
2012-01-13 21:25:39 +00:00
|
|
|
});
|
2014-07-21 02:58:34 +00:00
|
|
|
|
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
add_tax: function() {
|
2014-07-21 02:58:34 +00:00
|
|
|
$( this ).WCBackboneModal({
|
2015-08-06 04:37:53 +00:00
|
|
|
template: 'wc-modal-add-tax'
|
2014-07-21 02:58:34 +00:00
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
edit_item: function() {
|
|
|
|
$( this ).closest( 'tr' ).find( '.view' ).hide();
|
|
|
|
$( this ).closest( 'tr' ).find( '.edit' ).show();
|
|
|
|
$( this ).hide();
|
|
|
|
$( 'button.add-line-item' ).click();
|
|
|
|
$( 'button.cancel-action' ).attr( 'data-reload', true );
|
|
|
|
return false;
|
|
|
|
},
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
delete_item: function() {
|
|
|
|
var answer = window.confirm( woocommerce_admin_meta_boxes.remove_item_notice );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( answer ) {
|
|
|
|
var $item = $( this ).closest( 'tr.item, tr.fee, tr.shipping' );
|
|
|
|
var order_item_id = $item.attr( 'data-order_item_id' );
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2012-04-10 00:39:31 +00:00
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
order_item_ids: order_item_id,
|
|
|
|
action: 'woocommerce_remove_order_item',
|
2014-07-22 19:52:36 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2012-04-10 00:39:31 +00:00
|
|
|
};
|
2012-08-01 12:43:46 +00:00
|
|
|
|
2014-07-22 19:52:36 +00:00
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2015-07-08 05:19:56 +00:00
|
|
|
success: function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
$item.remove();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2014-08-31 06:25:22 +00:00
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
delete_tax: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_delete_tax ) ) {
|
|
|
|
wc_meta_boxes_order_items.block();
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
action: 'woocommerce_remove_order_tax',
|
|
|
|
rate_id: $( this ).attr( 'data-rate_id' ),
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2014-07-10 10:25:50 +00:00
|
|
|
};
|
2012-11-12 13:41:54 +00:00
|
|
|
|
2014-07-22 19:52:36 +00:00
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
2014-07-10 10:25:50 +00:00
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2014-08-31 06:25:22 +00:00
|
|
|
success: function( response ) {
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2015-01-15 16:30:42 +00:00
|
|
|
wc_meta_boxes_order_items.stupidtable.init();
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2014-07-22 19:52:36 +00:00
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2014-07-18 20:24:34 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-07-18 20:24:34 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
calculate_tax: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.calc_line_taxes ) ) {
|
|
|
|
wc_meta_boxes_order_items.block();
|
2014-07-18 20:24:34 +00:00
|
|
|
|
2015-10-05 14:31:58 +00:00
|
|
|
var country = '';
|
2015-01-12 15:43:13 +00:00
|
|
|
var state = '';
|
|
|
|
var postcode = '';
|
|
|
|
var city = '';
|
|
|
|
|
2015-10-05 14:31:58 +00:00
|
|
|
if ( 'shipping' === woocommerce_admin_meta_boxes.tax_based_on ) {
|
|
|
|
country = $( '#_shipping_country' ).val();
|
2015-01-12 15:43:13 +00:00
|
|
|
state = $( '#_shipping_state' ).val();
|
|
|
|
postcode = $( '#_shipping_postcode' ).val();
|
|
|
|
city = $( '#_shipping_city' ).val();
|
2015-10-05 14:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'billing' === woocommerce_admin_meta_boxes.tax_based_on || ! country ) {
|
|
|
|
country = $( '#_billing_country' ).val();
|
2015-01-12 15:43:13 +00:00
|
|
|
state = $( '#_billing_state' ).val();
|
|
|
|
postcode = $( '#_billing_postcode' ).val();
|
|
|
|
city = $( '#_billing_city' ).val();
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_calc_line_taxes',
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize(),
|
|
|
|
country: country,
|
|
|
|
state: state,
|
|
|
|
postcode: postcode,
|
|
|
|
city: city,
|
|
|
|
security: woocommerce_admin_meta_boxes.calc_totals_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2015-01-15 16:30:42 +00:00
|
|
|
wc_meta_boxes_order_items.stupidtable.init();
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
calculate_totals: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.calc_totals ) ) {
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
// Get row totals
|
|
|
|
var line_totals = 0;
|
2014-07-18 20:24:34 +00:00
|
|
|
var tax = 0;
|
|
|
|
var shipping = 0;
|
|
|
|
|
2014-08-31 06:25:22 +00:00
|
|
|
$( '.woocommerce_order_items tr.shipping input.line_total' ).each(function() {
|
2014-07-22 21:07:44 +00:00
|
|
|
var cost = $( this ).val() || '0';
|
|
|
|
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
|
|
|
shipping = shipping + parseFloat( cost );
|
2014-07-18 20:24:34 +00:00
|
|
|
});
|
|
|
|
|
2014-08-31 06:25:22 +00:00
|
|
|
$( '.woocommerce_order_items input.line_tax' ).each(function() {
|
2014-07-22 21:07:44 +00:00
|
|
|
var cost = $( this ).val() || '0';
|
|
|
|
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
|
|
|
|
tax = tax + parseFloat( cost );
|
2014-07-18 20:24:34 +00:00
|
|
|
});
|
|
|
|
|
2014-08-31 06:25:22 +00:00
|
|
|
$( '.woocommerce_order_items tr.item, .woocommerce_order_items tr.fee' ).each(function() {
|
2014-07-22 21:07:44 +00:00
|
|
|
var line_total = $( this ).find( 'input.line_total' ).val() || '0';
|
|
|
|
line_totals = line_totals + accounting.unformat( line_total.replace( ',', '.' ) );
|
2014-07-18 20:24:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Tax
|
|
|
|
if ( 'yes' === woocommerce_admin_meta_boxes.round_at_subtotal ) {
|
|
|
|
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Total
|
|
|
|
$( '#_order_total' )
|
2014-11-25 11:05:14 +00:00
|
|
|
.val( accounting.formatNumber( line_totals + tax + shipping, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) )
|
2014-07-18 20:24:34 +00:00
|
|
|
.change();
|
|
|
|
|
|
|
|
$( 'button.save-action' ).click();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
save_line_items: function() {
|
2014-07-18 20:24:34 +00:00
|
|
|
var data = {
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
items: $( 'table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]' ).serialize(),
|
|
|
|
action: 'woocommerce_save_order_items',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
2014-07-18 20:24:34 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2015-01-15 16:30:42 +00:00
|
|
|
wc_meta_boxes_order_items.stupidtable.init();
|
2014-07-18 20:24:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-09-10 04:17:12 +00:00
|
|
|
$( this ).trigger( 'items_saved' );
|
|
|
|
|
2014-07-21 01:57:23 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
refunds: {
|
|
|
|
|
|
|
|
do_refund: function() {
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_do_refund ) ) {
|
|
|
|
var refund_amount = $( 'input#refund_amount' ).val();
|
|
|
|
var refund_reason = $( 'input#refund_reason' ).val();
|
|
|
|
|
|
|
|
// Get line item refunds
|
|
|
|
var line_item_qtys = {};
|
|
|
|
var line_item_totals = {};
|
|
|
|
var line_item_tax_totals = {};
|
|
|
|
|
|
|
|
$( '.refund input.refund_order_item_qty' ).each(function( index, item ) {
|
|
|
|
if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
|
|
|
|
if ( item.value ) {
|
|
|
|
line_item_qtys[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = item.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.refund input.refund_line_total' ).each(function( index, item ) {
|
|
|
|
if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
|
|
|
|
line_item_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = accounting.unformat( item.value, woocommerce_admin.mon_decimal_point );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '.refund input.refund_line_tax' ).each(function( index, item ) {
|
|
|
|
if ( $( item ).closest( 'tr' ).data( 'order_item_id' ) ) {
|
|
|
|
var tax_id = $( item ).data( 'tax_id' );
|
|
|
|
|
|
|
|
if ( ! line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] ) {
|
|
|
|
line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
line_item_tax_totals[ $( item ).closest( 'tr' ).data( 'order_item_id' ) ][ tax_id ] = accounting.unformat( item.value, woocommerce_admin.mon_decimal_point );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_refund_line_items',
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
refund_amount: refund_amount,
|
|
|
|
refund_reason: refund_reason,
|
|
|
|
line_item_qtys: JSON.stringify( line_item_qtys, null, '' ),
|
|
|
|
line_item_totals: JSON.stringify( line_item_totals, null, '' ),
|
|
|
|
line_item_tax_totals: JSON.stringify( line_item_tax_totals, null, '' ),
|
|
|
|
api_refund: $( this ).is( '.do-api-refund' ),
|
2016-03-01 13:08:25 +00:00
|
|
|
restock_refunded_items: $( '#restock_refunded_items:checked' ).length ? 'true' : 'false',
|
2015-01-12 15:43:13 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
|
|
|
if ( true === response.success ) {
|
|
|
|
wc_meta_boxes_order_items.reload_items();
|
|
|
|
|
|
|
|
if ( 'fully_refunded' === response.data.status ) {
|
|
|
|
// Redirect to same page for show the refunded status
|
|
|
|
window.location.href = window.location.href;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window.alert( response.data.error );
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
delete_refund: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_delete_refund ) ) {
|
|
|
|
var $refund = $( this ).closest( 'tr.refund' );
|
|
|
|
var refund_id = $refund.attr( 'data-order_refund_id' );
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_delete_refund',
|
|
|
|
refund_id: refund_id,
|
2015-07-08 05:19:56 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2015-01-12 15:43:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2015-07-08 05:19:56 +00:00
|
|
|
success: function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.reload_items();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
input_changed: function() {
|
|
|
|
var refund_amount = 0;
|
|
|
|
var $items = $( '.woocommerce_order_items' ).find( 'tr.item, tr.fee, tr.shipping' );
|
|
|
|
|
|
|
|
$items.each(function() {
|
|
|
|
var $row = $( this );
|
|
|
|
var refund_cost_fields = $row.find( '.refund input:not(.refund_order_item_qty)' );
|
|
|
|
|
|
|
|
refund_cost_fields.each(function( index, el ) {
|
|
|
|
refund_amount += parseFloat( accounting.unformat( $( el ).val() || 0, woocommerce_admin.mon_decimal_point ) );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$( '#refund_amount' )
|
|
|
|
.val( accounting.formatNumber(
|
|
|
|
refund_amount,
|
|
|
|
woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
|
|
|
'',
|
|
|
|
woocommerce_admin.mon_decimal_point
|
|
|
|
) )
|
|
|
|
.change();
|
|
|
|
},
|
|
|
|
|
|
|
|
amount_changed: function() {
|
|
|
|
var total = accounting.unformat( $( this ).val(), woocommerce_admin.mon_decimal_point );
|
|
|
|
|
|
|
|
$( 'button .wc-order-refund-amount .amount' ).text( accounting.formatMoney( total, {
|
|
|
|
symbol: woocommerce_admin_meta_boxes.currency_format_symbol,
|
|
|
|
decimal: woocommerce_admin_meta_boxes.currency_format_decimal_sep,
|
|
|
|
thousand: woocommerce_admin_meta_boxes.currency_format_thousand_sep,
|
|
|
|
precision: woocommerce_admin_meta_boxes.currency_format_num_decimals,
|
|
|
|
format: woocommerce_admin_meta_boxes.currency_format
|
|
|
|
} ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
// When the refund qty is changed, increase or decrease costs
|
|
|
|
refund_quantity_changed: function() {
|
|
|
|
var $row = $( this ).closest( 'tr.item' );
|
|
|
|
var qty = $row.find( 'input.quantity' ).val();
|
|
|
|
var refund_qty = $( this ).val();
|
|
|
|
var line_total = $( 'input.line_total', $row );
|
|
|
|
var refund_line_total = $( 'input.refund_line_total', $row );
|
|
|
|
|
|
|
|
// Totals
|
|
|
|
var unit_total = accounting.unformat( line_total.attr( 'data-total' ), woocommerce_admin.mon_decimal_point ) / qty;
|
|
|
|
|
|
|
|
refund_line_total.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_total * refund_qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
2015-02-04 15:12:47 +00:00
|
|
|
).change();
|
2015-01-12 15:43:13 +00:00
|
|
|
|
|
|
|
// Taxes
|
|
|
|
$( 'td.line_tax', $row ).each( function() {
|
|
|
|
var line_total_tax = $( 'input.line_tax', $( this ) );
|
|
|
|
var refund_line_total_tax = $( 'input.refund_line_tax', $( this ) );
|
|
|
|
var unit_total_tax = accounting.unformat( line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / qty;
|
|
|
|
|
|
|
|
if ( 0 < unit_total_tax ) {
|
|
|
|
refund_line_total_tax.val(
|
|
|
|
parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) )
|
|
|
|
.toString()
|
|
|
|
.replace( '.', woocommerce_admin.mon_decimal_point )
|
|
|
|
).change();
|
2015-01-15 18:57:33 +00:00
|
|
|
} else {
|
|
|
|
refund_line_total_tax.val( 0 ).change();
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Restock checkbox
|
|
|
|
if ( refund_qty > 0 ) {
|
2015-01-15 18:57:33 +00:00
|
|
|
$( '#restock_refunded_items' ).closest( 'tr' ).show();
|
2015-01-12 15:43:13 +00:00
|
|
|
} else {
|
2015-01-15 18:57:33 +00:00
|
|
|
$( '#restock_refunded_items' ).closest( 'tr' ).hide();
|
|
|
|
$( '.woocommerce_order_items input.refund_order_item_qty' ).each( function() {
|
|
|
|
if ( $( this ).val() > 0 ) {
|
|
|
|
$( '#restock_refunded_items' ).closest( 'tr' ).show();
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$( this ).trigger( 'refund_quantity_changed' );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
item_meta: {
|
|
|
|
|
|
|
|
add: function() {
|
|
|
|
var $button = $( this );
|
2016-01-08 11:42:32 +00:00
|
|
|
var $item = $button.closest( 'tr.item, tr.shipping' );
|
2014-07-21 01:57:23 +00:00
|
|
|
|
2014-07-22 14:26:18 +00:00
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
order_item_id: $item.attr( 'data-order_item_id' ),
|
|
|
|
action: 'woocommerce_add_order_item_meta',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2014-07-22 14:26:18 +00:00
|
|
|
};
|
2014-07-22 15:44:02 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
2014-07-22 14:26:18 +00:00
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
2014-07-22 14:26:18 +00:00
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
$item.find('tbody.meta_items').append( response );
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2014-07-22 14:26:18 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function() {
|
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.remove_item_meta ) ) {
|
|
|
|
var $row = $( this ).closest( 'tr' );
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
meta_id: $row.attr( 'data-meta_id' ),
|
|
|
|
action: 'woocommerce_remove_order_item_meta',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2015-07-08 05:19:56 +00:00
|
|
|
success: function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
$row.hide();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-22 14:26:18 +00:00
|
|
|
}
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-07-24 20:33:26 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
bulk_actions: {
|
2014-07-24 20:33:26 +00:00
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
check_column: function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
$( '#woocommerce-order-items' ).find( '.check-column input' ).attr( 'checked', 'checked' );
|
|
|
|
} else {
|
|
|
|
$( '#woocommerce-order-items' ).find( '.check-column input' ).removeAttr( 'checked' );
|
2014-07-24 20:33:26 +00:00
|
|
|
}
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
do_bulk_action: function() {
|
|
|
|
var action = $( this ).closest( '.bulk-actions' ).find( 'select' ).val();
|
|
|
|
var selected_rows = $( '#woocommerce-order-items' ).find( '.check-column input:checked' );
|
|
|
|
var item_ids = [];
|
|
|
|
|
|
|
|
$( selected_rows ).each( function() {
|
|
|
|
var $item = $( this ).closest( 'tr' );
|
|
|
|
|
|
|
|
if ( $item.attr( 'data-order_item_id' ) ) {
|
|
|
|
item_ids.push( $item.attr( 'data-order_item_id' ) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( item_ids.length === 0 ) {
|
|
|
|
window.alert( woocommerce_admin_meta_boxes.i18n_select_items );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
if ( wc_meta_boxes_order_items.bulk_actions[ 'do_' + action ] ) {
|
|
|
|
wc_meta_boxes_order_items.bulk_actions[ 'do_' + action ]( selected_rows, item_ids );
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
do_delete: function( selected_rows, item_ids ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.remove_item_notice ) ) {
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
order_item_ids: item_ids,
|
|
|
|
action: 'woocommerce_remove_order_item',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
2015-07-08 05:19:56 +00:00
|
|
|
success: function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
$( selected_rows ).each(function() {
|
|
|
|
$( this ).closest( 'tr' ).remove();
|
|
|
|
});
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
do_increase_stock: function( selected_rows, item_ids ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
var quantities = {};
|
|
|
|
|
|
|
|
$( selected_rows ).each(function() {
|
|
|
|
|
|
|
|
var $item = $( this ).closest( 'tr.item, tr.fee' );
|
|
|
|
var $qty = $item.find( 'input.quantity' );
|
|
|
|
|
|
|
|
quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val();
|
|
|
|
});
|
2014-07-24 20:33:26 +00:00
|
|
|
|
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
order_item_ids: item_ids,
|
|
|
|
order_item_qty: quantities,
|
|
|
|
action: 'woocommerce_increase_order_item_stock',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2014-07-24 20:33:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
2015-01-12 15:43:13 +00:00
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
2014-07-24 20:33:26 +00:00
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
window.alert( response );
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2014-07-24 20:33:26 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2014-07-24 20:33:26 +00:00
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
do_reduce_stock: function( selected_rows, item_ids ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
2014-07-24 14:34:14 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
var quantities = {};
|
2014-07-24 14:34:14 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$( selected_rows ).each(function() {
|
2014-07-24 14:34:14 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
var $item = $( this ).closest( 'tr.item, tr.fee' );
|
|
|
|
var $qty = $item.find( 'input.quantity' );
|
2014-07-24 14:34:14 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val();
|
2014-07-10 12:33:05 +00:00
|
|
|
});
|
2014-07-24 14:34:14 +00:00
|
|
|
|
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
order_item_ids: item_ids,
|
|
|
|
order_item_qty: quantities,
|
|
|
|
action: 'woocommerce_reduce_order_item_stock',
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
2014-07-10 12:33:05 +00:00
|
|
|
};
|
2014-07-24 14:34:14 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
|
|
|
window.alert( response );
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2014-07-10 12:33:05 +00:00
|
|
|
}
|
2015-07-08 05:19:56 +00:00
|
|
|
});
|
2014-07-10 12:33:05 +00:00
|
|
|
}
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
backbone: {
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
init: function( e, target ) {
|
2015-08-06 04:37:53 +00:00
|
|
|
if ( 'wc-modal-add-products' === target ) {
|
2015-04-13 15:37:22 +00:00
|
|
|
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
},
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 17:11:01 +00:00
|
|
|
response: function( e, target, data ) {
|
2015-08-06 04:37:53 +00:00
|
|
|
if ( 'wc-modal-add-tax' === target ) {
|
2015-01-12 17:11:01 +00:00
|
|
|
var rate_id = data.add_order_tax;
|
|
|
|
var manual_rate_id = '';
|
|
|
|
|
|
|
|
if ( data.manual_tax_rate_id ) {
|
|
|
|
manual_rate_id = data.manual_tax_rate_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
wc_meta_boxes_order_items.backbone.add_tax( rate_id, manual_rate_id );
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
2015-08-06 04:37:53 +00:00
|
|
|
if ( 'wc-modal-add-products' === target ) {
|
2015-01-12 17:11:01 +00:00
|
|
|
wc_meta_boxes_order_items.backbone.add_item( data.add_order_items );
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
},
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 17:11:01 +00:00
|
|
|
add_item: function( add_item_ids ) {
|
|
|
|
add_item_ids = add_item_ids.split( ',' );
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( add_item_ids ) {
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
var count = add_item_ids.length;
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order_items.block();
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$.each( add_item_ids, function( index, value ) {
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_order_item',
|
|
|
|
item_to_add: value,
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
|
|
|
$( 'table.woocommerce_order_items tbody#order_line_items' ).append( response );
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( !--count ) {
|
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
|
|
|
}
|
|
|
|
});
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
});
|
2014-07-16 18:11:48 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
},
|
2014-07-21 01:36:12 +00:00
|
|
|
|
2015-01-12 17:11:01 +00:00
|
|
|
add_tax: function( rate_id, manual_rate_id ) {
|
2015-01-12 15:43:13 +00:00
|
|
|
if ( manual_rate_id ) {
|
|
|
|
rate_id = manual_rate_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! rate_id ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rates = $( '.order-tax-id' ).map( function() {
|
|
|
|
return $( this ).val();
|
|
|
|
}).get();
|
|
|
|
|
|
|
|
// Test if already exists
|
|
|
|
if ( -1 === $.inArray( rate_id, rates ) ) {
|
|
|
|
wc_meta_boxes_order_items.block();
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_add_order_tax',
|
|
|
|
rate_id: rate_id,
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
security: woocommerce_admin_meta_boxes.order_item_nonce
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: woocommerce_admin_meta_boxes.ajax_url,
|
|
|
|
data: data,
|
|
|
|
type: 'POST',
|
|
|
|
success: function( response ) {
|
2015-09-07 17:51:10 +00:00
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).empty();
|
|
|
|
$( '#woocommerce-order-items' ).find( '.inside' ).append( response );
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init_tiptip();
|
|
|
|
wc_meta_boxes_order_items.unblock();
|
2015-01-15 16:30:42 +00:00
|
|
|
wc_meta_boxes_order_items.stupidtable.init();
|
2015-01-12 15:43:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
window.alert( woocommerce_admin_meta_boxes.i18n_tax_rate_already_exists );
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 16:30:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
stupidtable: {
|
|
|
|
init: function() {
|
|
|
|
$( '.woocommerce_order_items' ).stupidtable().on( 'aftertablesort', this.add_arrows );
|
|
|
|
},
|
|
|
|
|
|
|
|
add_arrows: function( event, data ) {
|
|
|
|
var th = $( this ).find( 'th' );
|
|
|
|
var arrow = data.direction === 'asc' ? '↑' : '↓';
|
|
|
|
var index = data.column;
|
2014-07-23 10:30:06 +00:00
|
|
|
|
2015-01-15 16:30:42 +00:00
|
|
|
if ( 1 < index ) {
|
|
|
|
index = index - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
th.find( '.wc-arrow' ).remove();
|
|
|
|
th.eq( index ).append( '<span class="wc-arrow">' + arrow + '</span>' );
|
|
|
|
}
|
2014-07-23 10:30:06 +00:00
|
|
|
}
|
2015-01-12 15:43:13 +00:00
|
|
|
};
|
2014-07-23 10:30:06 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
/**
|
|
|
|
* Order Notes Panel
|
|
|
|
*/
|
|
|
|
var wc_meta_boxes_order_notes = {
|
|
|
|
init: function() {
|
|
|
|
$( '#woocommerce-order-notes' )
|
|
|
|
.on( 'click', 'a.add_note', this.add_order_note )
|
|
|
|
.on( 'click', 'a.delete_note', this.delete_order_note );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
add_order_note: function() {
|
|
|
|
if ( ! $( 'textarea#add_order_note' ).val() ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-21 01:36:12 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$( '#woocommerce-order-notes' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2014-07-21 01:36:12 +00:00
|
|
|
|
2014-07-22 15:42:17 +00:00
|
|
|
var data = {
|
2015-01-12 15:43:13 +00:00
|
|
|
action: 'woocommerce_add_order_note',
|
|
|
|
post_id: woocommerce_admin_meta_boxes.post_id,
|
|
|
|
note: $( 'textarea#add_order_note' ).val(),
|
|
|
|
note_type: $( 'select#order_note_type' ).val(),
|
2015-07-08 05:19:56 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.add_order_note_nonce
|
2014-07-22 15:42:17 +00:00
|
|
|
};
|
2014-07-21 01:36:12 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
|
|
|
$( 'ul.order_notes' ).prepend( response );
|
|
|
|
$( '#woocommerce-order-notes' ).unblock();
|
|
|
|
$( '#add_order_note' ).val( '' );
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
delete_order_note: function() {
|
|
|
|
var note = $( this ).closest( 'li.note' );
|
|
|
|
|
|
|
|
$( note ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
|
|
|
background: '#fff',
|
|
|
|
opacity: 0.6
|
2014-07-22 15:42:17 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-21 01:36:12 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
var data = {
|
|
|
|
action: 'woocommerce_delete_order_note',
|
|
|
|
note_id: $( note ).attr( 'rel' ),
|
2015-07-08 05:19:56 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.delete_order_note_nonce
|
2015-01-12 15:43:13 +00:00
|
|
|
};
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function() {
|
2015-01-12 15:43:13 +00:00
|
|
|
$( note ).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2015-07-08 05:19:56 +00:00
|
|
|
}
|
2015-03-03 13:41:52 +00:00
|
|
|
};
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
/**
|
|
|
|
* Order Downloads Panel
|
|
|
|
*/
|
|
|
|
var wc_meta_boxes_order_downloads = {
|
|
|
|
init: function() {
|
|
|
|
$( '.order_download_permissions' )
|
|
|
|
.on( 'click', 'button.grant_access', this.grant_access )
|
|
|
|
.on( 'click', 'button.revoke_access', this.revoke_access );
|
|
|
|
},
|
|
|
|
|
|
|
|
grant_access: function() {
|
|
|
|
var products = $( '#grant_access_id' ).val();
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-07-22 19:52:36 +00:00
|
|
|
if ( ! products ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '.order_download_permissions' ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
2014-11-13 18:28:15 +00:00
|
|
|
background: '#fff',
|
2014-07-22 19:52:36 +00:00
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-11-12 12:22:35 +00:00
|
|
|
var data = {
|
2014-07-22 19:52:36 +00:00
|
|
|
action: 'woocommerce_grant_access_to_download',
|
|
|
|
product_ids: products,
|
2016-03-01 13:08:25 +00:00
|
|
|
loop: $('.order_download_permissions .wc-metabox').length,
|
2014-07-22 19:52:36 +00:00
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
2015-07-08 05:19:56 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.grant_access_nonce
|
2012-11-12 12:22:35 +00:00
|
|
|
};
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
2013-11-27 14:03:04 +00:00
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
if ( response ) {
|
2014-07-22 19:52:36 +00:00
|
|
|
$( '.order_download_permissions .wc-metaboxes' ).append( response );
|
2014-07-10 10:25:50 +00:00
|
|
|
} else {
|
2014-07-22 19:52:36 +00:00
|
|
|
window.alert( woocommerce_admin_meta_boxes.i18n_download_permission_fail );
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2013-11-27 14:03:04 +00:00
|
|
|
|
2015-04-13 15:37:22 +00:00
|
|
|
$( document.body ).trigger( 'wc-init-datepickers' );
|
2015-01-12 13:04:19 +00:00
|
|
|
$( '#grant_access_id' ).val( '' ).change();
|
2014-07-22 19:52:36 +00:00
|
|
|
$( '.order_download_permissions' ).unblock();
|
2013-11-27 14:03:04 +00:00
|
|
|
});
|
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2015-01-12 15:43:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
revoke_access: function () {
|
2014-07-22 19:52:36 +00:00
|
|
|
if ( window.confirm( woocommerce_admin_meta_boxes.i18n_permission_revoke ) ) {
|
|
|
|
var el = $( this ).parent().parent();
|
|
|
|
var product = $( this ).attr( 'rel' ).split( ',' )[0];
|
|
|
|
var file = $( this ).attr( 'rel' ).split( ',' )[1];
|
2014-07-10 10:25:50 +00:00
|
|
|
|
|
|
|
if ( product > 0 ) {
|
2014-07-22 19:52:36 +00:00
|
|
|
$( el ).block({
|
|
|
|
message: null,
|
|
|
|
overlayCSS: {
|
2014-11-13 18:28:15 +00:00
|
|
|
background: '#fff',
|
2014-07-22 19:52:36 +00:00
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
|
|
|
|
var data = {
|
2014-07-22 19:52:36 +00:00
|
|
|
action: 'woocommerce_revoke_access_to_download',
|
|
|
|
product_id: product,
|
|
|
|
download_id: file,
|
|
|
|
order_id: woocommerce_admin_meta_boxes.post_id,
|
2015-07-08 05:19:56 +00:00
|
|
|
security: woocommerce_admin_meta_boxes.revoke_access_nonce
|
2014-07-10 10:25:50 +00:00
|
|
|
};
|
|
|
|
|
2015-07-08 05:19:56 +00:00
|
|
|
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function() {
|
2014-07-10 10:25:50 +00:00
|
|
|
// Success
|
2014-07-22 19:52:36 +00:00
|
|
|
$( el ).fadeOut( '300', function () {
|
|
|
|
$( el ).remove();
|
2014-07-10 10:25:50 +00:00
|
|
|
});
|
|
|
|
});
|
2013-11-27 14:03:04 +00:00
|
|
|
|
2014-07-10 10:25:50 +00:00
|
|
|
} else {
|
2014-07-22 19:52:36 +00:00
|
|
|
$( el ).fadeOut( '300', function () {
|
|
|
|
$( el ).remove();
|
2013-11-27 14:03:04 +00:00
|
|
|
});
|
2014-07-10 10:25:50 +00:00
|
|
|
}
|
2013-11-27 14:03:04 +00:00
|
|
|
}
|
2014-07-10 10:25:50 +00:00
|
|
|
return false;
|
2011-11-26 16:15:25 +00:00
|
|
|
}
|
2015-03-03 13:41:52 +00:00
|
|
|
};
|
2014-11-26 15:37:06 +00:00
|
|
|
|
2015-01-12 15:43:13 +00:00
|
|
|
wc_meta_boxes_order.init();
|
|
|
|
wc_meta_boxes_order_items.init();
|
|
|
|
wc_meta_boxes_order_notes.init();
|
|
|
|
wc_meta_boxes_order_downloads.init();
|
2015-01-12 17:11:01 +00:00
|
|
|
});
|