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(/"/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('');else{var l=e(''),u=o.states[n];l.append(e('")),e.each(u,function(o){l.append(e('"))}),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(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).on("wc_order_items_reload",this.reload_items).on("wc_order_items_reloaded",this.reloaded_items),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 o={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:o,type:"POST",success:function(o){e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(o),t.reloaded_items(),t.unblock()}})},reloaded_items:function(){o.init_tiptip(),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;00?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=' | |
';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"),a=e("div.wc-order-item-bulk-edit");if(i.length&&a.children().length>0){a.slideDown();var n=!1;i.each(function(){e(this).is("tr.item")&&(n=!0)}),n?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()}},modify_stock:function(o,i){o.preventDefault(),t.block(),e("#woocommerce-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var a=e("table.woocommerce_order_items").find("tr.selected"),n={},r=e.map(a,function(o){return parseInt(e(o).data("order_item_id"),10)});a.each(function(){e(this).find("input.quantity").length&&(n[e(this).attr("data-order_item_id")]=e(this).find("input.quantity").val())});var c={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:r,order_item_qty:n,action:i,security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:c,type:"POST",success:function(o){t.unblock(),!0===o.success&&e.map(o.data,function(o){if(o.success){var t={action:"woocommerce_add_order_note",post_id:woocommerce_admin_meta_boxes.post_id,note:o.note,note_type:"",security:woocommerce_admin_meta_boxes.add_order_note_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(o){e("ul.order_notes").prepend(o)})}else window.alert(o.note)}),e("#woocommerce-order-notes").unblock()}})},do_increase_stock:function(e){t.bulk_actions.modify_stock(e,"woocommerce_increase_order_item_stock")},do_reduce_stock:function(e){t.bulk_actions.modify_stock(e,"woocommerce_reduce_order_item_stock")}},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(o){if(o){t.block();var i={action:"woocommerce_add_order_item",item_to_add:o,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")&&(i.items=e("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize()),e.post(woocommerce_admin_meta_boxes.ajax_url,i,function(o){o.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(o.data.html),t.reloaded_items()):window.alert(o.data.error),t.unblock()})}},add_tax:function(o,i){if(i&&(o=i),!o)return!1;var a=e(".order-tax-id").map(function(){return e(this).val()}).get();if(-1===e.inArray(o,a)){t.block();var n={action:"woocommerce_add_order_tax",rate_id:o,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:n,dataType:"json",type:"POST",success:function(o){o.success?(e("#woocommerce-order-items").find(".inside").empty(),e("#woocommerce-order-items").find(".inside").append(o.data.html),t.reloaded_items()):window.alert(o.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?"↑":"↓",n=t.column;i.find(".wc-arrow").remove(),i.eq(n).append(''+a+"")}}},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()});