woocommerce/assets/js/admin/meta-boxes-order.min.js

1 line
27 KiB
JavaScript

jQuery(function(e){var o={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=e.parseJSON(woocommerce_admin_meta_boxes_order.countries.replace(/&quot;/g,'"'))),e(".js_field-country").selectWoo().change(this.change_country),e(".js_field-country").trigger("change",[!0]),e(document.body).on("change","select.js_field-state",this.change_state),e("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""}),e("a.edit_address").click(this.edit_address),e("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),e("a.load_customer_billing").on("click",this.load_billing),e("a.load_customer_shipping").on("click",this.load_shipping),e("#customer_user").on("change",this.change_customer_user)},change_country:function(t,i){if(void 0===i&&(i=!1),null!==o.states){var a=e(this),n=a.val(),r=a.parents("div.edit_address").find(":input.js_field-state"),c=r.parent(),d=r.attr("name"),_=r.attr("id"),m=a.data("woocommerce.stickState-"+n)?a.data("woocommerce.stickState-"+n):r.val(),s=r.attr("placeholder");if(i&&a.data("woocommerce.stickState-"+n,m),c.show().find(".select2-container").remove(),e.isEmptyObject(o.states[n]))r.replaceWith('<input type="text" class="js_field-state" name="'+d+'" id="'+_+'" value="'+m+'" placeholder="'+s+'" />');else{var l=e('<select name="'+d+'" id="'+_+'" class="js_field-state select short" placeholder="'+s+'"></select>'),u=o.states[n];l.append(e('<option value="">'+woocommerce_admin_meta_boxes_order.i18n_select_state_text+"</option>")),e.each(u,function(o){l.append(e('<option value="'+o+'">'+u[o]+"</option>"))}),l.val(m),r.replaceWith(l),l.show().selectWoo().hide().change()}e(document.body).trigger("contry-change.woocommerce",[n,e(this).closest("div")]),e(document.body).trigger("country-change.woocommerce",[n,e(this).closest("div")])}},change_state:function(){var o=e(this),t=o.val(),i=o.parents("div.edit_address").find(":input.js_field-country"),a=i.val();i.data("woocommerce.stickState-"+a,t)},init_tiptip:function(){e("#tiptip_holder").removeAttr("style"),e("#tiptip_arrow").removeAttr("style"),e(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},edit_address:function(o){o.preventDefault();var t=e(this),i=t.closest(".order_data_column"),a=i.find("div.edit_address"),n=i.find("div.address"),r=a.find(".js_field-country"),c=a.find(".js_field-state");n.hide(),t.parent().find("a").toggle(),r.val()||r.val(woocommerce_admin_meta_boxes_order.default_country).change(),c.val()||c.val(woocommerce_admin_meta_boxes_order.default_state).change(),a.show()},change_customer_user:function(){e("#_billing_country").val()||(e("a.edit_address").click(),o.load_billing(!0),o.load_shipping(!0))},load_billing:function(o){if(!0===o||window.confirm(woocommerce_admin_meta_boxes.load_billing)){var t=e("#customer_user").val();if(!t)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var i={user_id:t,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(o){o&&o.billing&&e.each(o.billing,function(o,t){e(":input#_billing_"+o).val(t).change()}),e("div.edit_address").unblock()}})}return!1},load_shipping:function(o){if(!0===o||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){var t=e("#customer_user").val();if(!t)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var i={user_id:t,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(o){o&&o.billing&&e.each(o.shipping,function(o,t){e(":input#_shipping_"+o).val(t).change()}),e("div.edit_address").unblock()}})}return!1},copy_billing_to_shipping:function(){return window.confirm(woocommerce_admin_meta_boxes.copy_billing)&&e('.order_data_column :input[name^="_billing_"]').each(function(){var o=e(this).attr("name");o=o.replace("_billing_","_shipping_"),e(":input#"+o).val(e(this).val()).change()}),!1}},t={init:function(){this.stupidtable.init(),e("#woocommerce-order-items").on("click","button.add-line-item",this.add_line_item).on("click","button.add-coupon",this.add_coupon).on("click","a.remove-coupon",this.remove_coupon).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","button.save-action",this.save_line_items).on("click","a.delete-order-tax",this.delete_tax).on("click","button.calculate-action",this.recalculate).on("click","a.edit-order-item",this.edit_item).on("click","a.delete-order-item",this.delete_item).on("click","tr.item, tr.fee, tr.shipping, tr.refund",this.select_row).on("click","tr.item :input, tr.fee :input, tr.shipping :input, tr.refund :input, tr.item a, tr.fee a, tr.shipping a, tr.refund a",this.select_row_child).on("click","button.bulk-delete-items",this.bulk_actions.do_delete).on("click","button.bulk-increase-stock",this.bulk_actions.do_increase_stock).on("click","button.bulk-decrease-stock",this.bulk_actions.do_reduce_stock).on("click",".delete_refund",this.refunds.delete_refund).on("click","button.do-api-refund, button.do-manual-refund",this.refunds.do_refund).on("change",".refund input.refund_line_total, .refund input.refund_line_tax",this.refunds.input_changed).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).on("change","input.quantity",this.quantity_changed).on("keyup change",".split-input :input",function(){var o=e(this).parent().prev().find(":input");o&&(""===o.val()||o.is(".match-total"))&&o.val(e(this).val()).addClass("match-total")}).on("keyup",".split-input :input",function(){e(this).removeClass("match-total")}).on("click","button.add_order_item_meta",this.item_meta.add).on("click","button.remove_order_item_meta",this.item_meta.remove),e(document.body).on("wc_backbone_modal_loaded",this.backbone.init).on("wc_backbone_modal_response",this.backbone.response)},block:function(){e("#woocommerce-order-items").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e("#woocommerce-order-items").unblock()},reload_items:function(){var i={order_id:woocommerce_admin_meta_boxes.post_id,action:"woocommerce_load_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};t.block(),e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(i){e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i),o.init_tiptip(),t.unblock(),t.stupidtable.init()}})},quantity_changed:function(){var o=e(this).closest("tr.item"),t=e(this).val(),i=e(this).attr("data-qty"),a=e("input.line_total",o),n=e("input.line_subtotal",o),r=accounting.unformat(a.attr("data-total"),woocommerce_admin.mon_decimal_point)/i;a.val(parseFloat(accounting.formatNumber(r*t,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point));var c=accounting.unformat(n.attr("data-subtotal"),woocommerce_admin.mon_decimal_point)/i;n.val(parseFloat(accounting.formatNumber(c*t,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),e("input.line_tax",o).each(function(){var a=e(this),n=a.data("tax_id"),r=accounting.unformat(a.attr("data-total_tax"),woocommerce_admin.mon_decimal_point)/i,c=e('input.line_subtotal_tax[data-tax_id="'+n+'"]',o),d=accounting.unformat(c.attr("data-subtotal_tax"),woocommerce_admin.mon_decimal_point)/i;0<r&&a.val(parseFloat(accounting.formatNumber(r*t,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),0<d&&c.val(parseFloat(accounting.formatNumber(d*t,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point))}),e(this).trigger("quantity_changed")},add_line_item:function(){return e("div.wc-order-add-item").slideDown(),e("div.wc-order-data-row-toggle").not("div.wc-order-add-item").slideUp(),!1},add_coupon:function(){var i=window.prompt(woocommerce_admin_meta_boxes.i18n_apply_coupon);if(null!=i){t.block();var a={action:"woocommerce_add_coupon_discount",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,coupon:i};e.post(woocommerce_admin_meta_boxes.ajax_url,a,function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.unblock(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()})}return!1},remove_coupon:function(){var i=e(this);t.block();var a={action:"woocommerce_remove_order_coupon",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,coupon:i.data("code")};e.post(woocommerce_admin_meta_boxes.ajax_url,a,function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.unblock(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()})},refund_items:function(){return e("div.wc-order-refund-items").slideDown(),e("div.wc-order-data-row-toggle").not("div.wc-order-refund-items").slideUp(),e("div.wc-order-totals-items").slideUp(),e("#woocommerce-order-items").find("div.refund").show(),e(".wc-order-edit-line-item .wc-order-edit-line-item-actions").hide(),!1},cancel:function(){return e("div.wc-order-data-row-toggle").not("div.wc-order-bulk-actions").slideUp(),e("div.wc-order-bulk-actions").slideDown(),e("div.wc-order-totals-items").slideDown(),e("#woocommerce-order-items").find("div.refund").hide(),e(".wc-order-edit-line-item .wc-order-edit-line-item-actions").show(),"true"===e(this).attr("data-reload")&&t.reload_items(),!1},add_item:function(){return e(this).WCBackboneModal({template:"wc-modal-add-products"}),!1},add_fee:function(){var i=window.prompt(woocommerce_admin_meta_boxes.i18n_add_fee);if(null!=i){t.block();var a=e.extend({},t.get_taxable_address(),{action:"woocommerce_add_order_fee",dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,amount:i});e.post(woocommerce_admin_meta_boxes.ajax_url,a,function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.unblock(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()})}return!1},add_shipping:function(){t.block();var o={action:"woocommerce_add_order_shipping",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,dataType:"json"};return e.post(woocommerce_admin_meta_boxes.ajax_url,o,function(o){o.success?e("table.woocommerce_order_items tbody#order_shipping_line_items").append(o.data.html):window.alert(o.data.error),t.unblock()}),!1},add_tax:function(){return e(this).WCBackboneModal({template:"wc-modal-add-tax"}),!1},edit_item:function(){return e(this).closest("tr").find(".view").hide(),e(this).closest("tr").find(".edit").show(),e(this).hide(),e("button.add-line-item").click(),e("button.cancel-action").attr("data-reload",!0),!1},delete_item:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_notice)){var i=e(this).closest("tr.item, tr.fee, tr.shipping").attr("data-order_item_id");t.block();var a=e.extend({},t.get_taxable_address(),{order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:i,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce});"true"===e("button.cancel-action").attr("data-reload")&&(a.items=e("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize()),e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:a,type:"POST",success:function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.unblock(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()}})}return!1},delete_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_tax)){t.block();var i={action:"woocommerce_remove_order_tax",rate_id:e(this).attr("data-rate_id"),order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.unblock(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()}})}return!1},get_taxable_address:function(){var o="",t="",i="",a="";return"shipping"===woocommerce_admin_meta_boxes.tax_based_on&&(o=e("#_shipping_country").val(),t=e("#_shipping_state").val(),i=e("#_shipping_postcode").val(),a=e("#_shipping_city").val()),"billing"!==woocommerce_admin_meta_boxes.tax_based_on&&o||(o=e("#_billing_country").val(),t=e("#_billing_state").val(),i=e("#_billing_postcode").val(),a=e("#_billing_city").val()),{country:o,state:t,postcode:i,city:a}},recalculate:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_totals)){t.block();var i=e.extend({},t.get_taxable_address(),{action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:e("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),security:woocommerce_admin_meta_boxes.calc_totals_nonce});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(i){e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i),o.init_tiptip(),t.unblock(),t.stupidtable.init()}})}return!1},save_line_items:function(){var i={order_id:woocommerce_admin_meta_boxes.post_id,items:e("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};return t.block(),e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(i){e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i),o.init_tiptip(),t.unblock(),t.stupidtable.init()}}),e(this).trigger("items_saved"),!1},refunds:{do_refund:function(){if(t.block(),window.confirm(woocommerce_admin_meta_boxes.i18n_do_refund)){var o=e("input#refund_amount").val(),i=e("input#refund_reason").val(),a=e("input#refunded_amount").val(),n={},r={},c={};e(".refund input.refund_order_item_qty").each(function(o,t){e(t).closest("tr").data("order_item_id")&&t.value&&(n[e(t).closest("tr").data("order_item_id")]=t.value)}),e(".refund input.refund_line_total").each(function(o,t){e(t).closest("tr").data("order_item_id")&&(r[e(t).closest("tr").data("order_item_id")]=accounting.unformat(t.value,woocommerce_admin.mon_decimal_point))}),e(".refund input.refund_line_tax").each(function(o,t){if(e(t).closest("tr").data("order_item_id")){var i=e(t).data("tax_id");c[e(t).closest("tr").data("order_item_id")]||(c[e(t).closest("tr").data("order_item_id")]={}),c[e(t).closest("tr").data("order_item_id")][i]=accounting.unformat(t.value,woocommerce_admin.mon_decimal_point)}});var d={action:"woocommerce_refund_line_items",order_id:woocommerce_admin_meta_boxes.post_id,refund_amount:o,refunded_amount:a,refund_reason:i,line_item_qtys:JSON.stringify(n,null,""),line_item_totals:JSON.stringify(r,null,""),line_item_tax_totals:JSON.stringify(c,null,""),api_refund:e(this).is(".do-api-refund"),restock_refunded_items:e("#restock_refunded_items:checked").length?"true":"false",security:woocommerce_admin_meta_boxes.order_item_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,d,function(e){!0===e.success?window.location.href=window.location.href:(window.alert(e.data.error),t.reload_items(),t.unblock())})}else t.unblock()},delete_refund:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_refund)){var o=e(this).closest("tr.refund").attr("data-order_refund_id");t.block();var i={action:"woocommerce_delete_refund",refund_id:o,security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:i,type:"POST",success:function(){t.reload_items()}})}return!1},input_changed:function(){var o=0;e(".woocommerce_order_items").find("tr.item, tr.fee, tr.shipping").each(function(){e(this).find(".refund input:not(.refund_order_item_qty)").each(function(t,i){o+=parseFloat(accounting.unformat(e(i).val()||0,woocommerce_admin.mon_decimal_point))})}),e("#refund_amount").val(accounting.formatNumber(o,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change()},amount_changed:function(){var o=accounting.unformat(e(this).val(),woocommerce_admin.mon_decimal_point);e("button .wc-order-refund-amount .amount").text(accounting.formatMoney(o,{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}))},refund_quantity_changed:function(){var o=e(this).closest("tr.item"),t=o.find("input.quantity").val(),i=e(this).val(),a=e("input.line_total",o),n=e("input.refund_line_total",o),r=accounting.unformat(a.attr("data-total"),woocommerce_admin.mon_decimal_point)/t;n.val(parseFloat(accounting.formatNumber(r*i,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change(),e(".refund_line_tax",o).each(function(){var a=e(this),n=a.data("tax_id"),r=e('input.line_tax[data-tax_id="'+n+'"]',o),c=accounting.unformat(r.data("total_tax"),woocommerce_admin.mon_decimal_point)/t;0<c?a.val(parseFloat(accounting.formatNumber(c*i,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change():a.val(0).change()}),i>0?e("#restock_refunded_items").closest("tr").show():(e("#restock_refunded_items").closest("tr").hide(),e(".woocommerce_order_items input.refund_order_item_qty").each(function(){e(this).val()>0&&e("#restock_refunded_items").closest("tr").show()})),e(this).trigger("refund_quantity_changed")}},item_meta:{add:function(){var o=e(this).closest("tr.item, tr.shipping"),t=o.find("tbody.meta_items"),i=t.find("tr").length+1,a='<tr data-meta_id="0"><td><input type="text" placeholder="'+woocommerce_admin_meta_boxes_order.placeholder_name+'" name="meta_key['+o.attr("data-order_item_id")+"][new-"+i+']" /><textarea placeholder="'+woocommerce_admin_meta_boxes_order.placeholder_value+'" name="meta_value['+o.attr("data-order_item_id")+"][new-"+i+']"></textarea></td><td width="1%"><button class="remove_order_item_meta button">&times;</button></td></tr>';return t.append(a),!1},remove:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_meta)){var o=e(this).closest("tr");o.find(":input").val(""),o.hide()}return!1}},select_row:function(){var o=!1;o=e(this).is("tr")?e(this):e(this).closest("tr");var t=e(this).closest("table");o.is(".selected")?o.removeClass("selected"):o.addClass("selected");var i=t.find("tr.selected");if(i.length){e("div.wc-order-item-bulk-edit").slideDown();var a=!1;i.each(function(){e(this).is("tr.item")&&(a=!0)}),a?e(".bulk-increase-stock, .bulk-decrease-stock").show():e(".bulk-increase-stock, .bulk-decrease-stock").hide()}else e("div.wc-order-item-bulk-edit").slideUp()},select_row_child:function(e){e.stopPropagation()},bulk_actions:{do_delete:function(o){o.preventDefault();var i=e("table.woocommerce_order_items").find("tr.selected");if(i.length&&window.confirm(woocommerce_admin_meta_boxes.remove_item_notice)){t.block();var a=[],n=[],r=[];e.map(i,function(o){var t=e(o);t.is(".refund")?n.push(parseInt(e(t).data("order_refund_id"),10)):a.push(parseInt(e(t).data("order_item_id"),10))}),a.length&&r.push(e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:{order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:a,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce},type:"POST"})),n.length&&r.push(e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:{action:"woocommerce_delete_refund",refund_id:n,security:woocommerce_admin_meta_boxes.order_item_nonce},type:"POST"})),r?e.when.apply(e,r).done(function(){t.reload_items(),t.unblock()}):t.unblock()}},do_increase_stock:function(o){o.preventDefault(),t.block();var i=e("table.woocommerce_order_items").find("tr.selected"),a={},n=e.map(i,function(o){return parseInt(e(o).data("order_item_id"),10)});i.each(function(){e(this).find("input.quantity").length&&(a[e(this).attr("data-order_item_id")]=e(this).find("input.quantity").val())});var r={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:n,order_item_qty:a,action:"woocommerce_increase_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(e){window.alert(e),t.unblock()}})},do_reduce_stock:function(o){o.preventDefault(),t.block();var i=e("table.woocommerce_order_items").find("tr.selected"),a={},n=e.map(i,function(o){return parseInt(e(o).data("order_item_id"),10)});i.each(function(){e(this).find("input.quantity").length&&(a[e(this).attr("data-order_item_id")]=e(this).find("input.quantity").val())});var r={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:n,order_item_qty:a,action:"woocommerce_reduce_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(e){window.alert(e),t.unblock()}})}},backbone:{init:function(o,t){"wc-modal-add-products"===t&&(e(document.body).trigger("wc-enhanced-select-init"),e("#add_item_id").selectWoo("open").selectWoo("focus"))},response:function(e,o,i){if("wc-modal-add-tax"===o){var a=i.add_order_tax,n="";i.manual_tax_rate_id&&(n=i.manual_tax_rate_id),t.backbone.add_tax(a,n)}"wc-modal-add-products"===o&&t.backbone.add_item(i.add_order_items)},add_item:function(i){if(i){t.block();var a={action:"woocommerce_add_order_item",item_to_add:i,dataType:"json",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce,data:e("#wc-backbone-modal-dialog form").serialize()};"true"===e("button.cancel-action").attr("data-reload")&&(a.items=e("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize()),e.post(woocommerce_admin_meta_boxes.ajax_url,a,function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()})}},add_tax:function(i,a){if(a&&(i=a),!i)return!1;var n=e(".order-tax-id").map(function(){return e(this).val()}).get();if(-1===e.inArray(i,n)){t.block();var r={action:"woocommerce_add_order_tax",rate_id:i,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,dataType:"json",type:"POST",success:function(i){i.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(i.data.html),o.init_tiptip(),t.stupidtable.init()):window.alert(i.data.error),t.unblock()}})}else window.alert(woocommerce_admin_meta_boxes.i18n_tax_rate_already_exists)}},stupidtable:{init:function(){e(".woocommerce_order_items").stupidtable(),e(".woocommerce_order_items").on("aftertablesort",this.add_arrows)},add_arrows:function(o,t){var i=e(this).find("th"),a="asc"===t.direction?"&uarr;":"&darr;",n=t.column;i.find(".wc-arrow").remove(),i.eq(n).append('<span class="wc-arrow">'+a+"</span>")}}},i={init:function(){e("#woocommerce-order-notes").on("click","button.add_note",this.add_order_note).on("click","a.delete_note",this.delete_order_note)},add_order_note:function(){if(e("textarea#add_order_note").val()){e("#woocommerce-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o={action:"woocommerce_add_order_note",post_id:woocommerce_admin_meta_boxes.post_id,note:e("textarea#add_order_note").val(),note_type:e("select#order_note_type").val(),security:woocommerce_admin_meta_boxes.add_order_note_nonce};return e.post(woocommerce_admin_meta_boxes.ajax_url,o,function(o){e("ul.order_notes").prepend(o),e("#woocommerce-order-notes").unblock(),e("#add_order_note").val("")}),!1}},delete_order_note:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_note)){var o=e(this).closest("li.note");e(o).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var t={action:"woocommerce_delete_order_note",note_id:e(o).attr("rel"),security:woocommerce_admin_meta_boxes.delete_order_note_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(){e(o).remove()})}return!1}},a={init:function(){e(".order_download_permissions").on("click","button.grant_access",this.grant_access).on("click","button.revoke_access",this.revoke_access).on("click","#copy-download-link",this.copy_link).on("aftercopy","#copy-download-link",this.copy_success).on("aftercopyfailure","#copy-download-link",this.copy_fail)},grant_access:function(){var o=e("#grant_access_id").val();if(o){e(".order_download_permissions").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var t={action:"woocommerce_grant_access_to_download",product_ids:o,loop:e(".order_download_permissions .wc-metabox").length,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.grant_access_nonce};return e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(o){o?e(".order_download_permissions .wc-metaboxes").append(o):window.alert(woocommerce_admin_meta_boxes.i18n_download_permission_fail),e(document.body).trigger("wc-init-datepickers"),e("#grant_access_id").val("").change(),e(".order_download_permissions").unblock()}),!1}},revoke_access:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_permission_revoke)){var o=e(this).parent().parent(),t=e(this).attr("rel").split(",")[0],i=e(this).attr("rel").split(",")[1],a=e(this).data("permission_id");if(t>0){e(o).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var n={action:"woocommerce_revoke_access_to_download",product_id:t,download_id:i,permission_id:a,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.revoke_access_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,n,function(){e(o).fadeOut("300",function(){e(o).remove()})})}else e(o).fadeOut("300",function(){e(o).remove()})}return!1},copy_link:function(o){wcClearClipboard(),wcSetClipboard(e(this).attr("href"),e(this)),o.preventDefault()},copy_success:function(){e(this).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()},copy_fail:function(){e(this).tipTip({attribute:"data-tip-failed",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()}};o.init(),t.init(),i.init(),a.init()});