관리-도구
편집 파일: meta-boxes-order.min.js
jQuery(function(u){window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){};var p={states:null,init:function(){"undefined"!=typeof kkart_admin_meta_boxes_order&&"undefined"!=typeof kkart_admin_meta_boxes_order.countries&&(this.states=JSON.parse(kkart_admin_meta_boxes_order.countries.replace(/"/g,'"'))),u(".js_field-country").selectWoo().change(this.change_country),u(".js_field-country").trigger("change",[!0]),u(document.body).on("change","select.js_field-state",this.change_state),u("#kkart-order-actions input, #kkart-order-actions a").click(function(){window.onbeforeunload=""}),u("a.edit_address").click(this.edit_address),u("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),u("a.load_customer_billing").on("click",this.load_billing),u("a.load_customer_shipping").on("click",this.load_shipping),u("#customer_user").on("change",this.change_customer_user)},change_country:function(e,o){var t,a,r,i,n,d,c,_,s,m,l;void 0===o&&(o=!1),null!==p.states&&(a=(t=u(this)).val(),m=(r=t.parents("div.edit_address").find(":input.js_field-state")).parent(),i=r.val(),n=r.attr("name"),d=r.attr("id"),c=t.data("kkart.stickState-"+a)?t.data("kkart.stickState-"+a):i,_=r.attr("placeholder"),o&&t.data("kkart.stickState-"+a,c),m.show().find(".select2-container").remove(),u.isEmptyObject(p.states[a])?(l=u('<input type="text" />').prop("id",d).prop("name",n).prop("placeholder",_).addClass("js_field-state").val(i),r.replaceWith(l)):(s=p.states[a],m=u('<option value=""></option>').text(kkart_admin_meta_boxes_order.i18n_select_state_text),l=u("<select></select>").prop("id",d).prop("name",n).prop("placeholder",_).addClass("js_field-state select short").append(m),u.each(s,function(e){var o=u("<option></option>").prop("value",e).text(s[e]);e===i&&o.prop("selected"),l.append(o)}),l.val(c),r.replaceWith(l),l.show().selectWoo().hide().change()),u(document.body).trigger("contry-change.kkart",[a,u(this).closest("div")]),u(document.body).trigger("country-change.kkart",[a,u(this).closest("div")]))},change_state:function(){var e=u(this),o=e.val(),t=e.parents("div.edit_address").find(":input.js_field-country"),e=t.val();t.data("kkart.stickState-"+e,o)},init_tiptip:function(){u("#tiptip_holder").removeAttr("style"),u("#tiptip_arrow").removeAttr("style"),u(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200,keepAlive:!0})},edit_address:function(e){e.preventDefault();var o=u(this),t=o.closest(".order_data_column"),a=t.find("div.edit_address"),r=t.find("div.address"),i=a.find(".js_field-country"),e=a.find(".js_field-state"),t=Boolean(a.find('input[name^="_billing_"]').length);r.hide(),o.parent().find("a").toggle(),i.val()||(i.val(kkart_admin_meta_boxes_order.default_country).change(),e.val(kkart_admin_meta_boxes_order.default_state).change()),a.show();t=t?"order_edit_billing_address_click":"order_edit_shipping_address_click";window.wcTracks.recordEvent(t,{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()})},change_customer_user:function(){u("#_billing_country").val()||(u("a.edit_address").click(),p.load_billing(!0),p.load_shipping(!0))},load_billing:function(e){if(!0===e||window.confirm(kkart_admin_meta_boxes.load_billing)){e=u("#customer_user").val();if(!e)return window.alert(kkart_admin_meta_boxes.no_customer_selected),!1;e={user_id:e,action:"kkart_get_customer_details",security:kkart_admin_meta_boxes.get_customer_details_nonce};u(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e&&e.billing&&u.each(e.billing,function(e,o){u(":input#_billing_"+e).val(o).change()}),u("div.edit_address").unblock()}})}return!1},load_shipping:function(e){if(!0===e||window.confirm(kkart_admin_meta_boxes.load_shipping)){e=u("#customer_user").val();if(!e)return window.alert(kkart_admin_meta_boxes.no_customer_selected),!1;e={user_id:e,action:"kkart_get_customer_details",security:kkart_admin_meta_boxes.get_customer_details_nonce};u(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e&&e.billing&&u.each(e.shipping,function(e,o){u(":input#_shipping_"+e).val(o).change()}),u("div.edit_address").unblock()}})}return!1},copy_billing_to_shipping:function(){return window.confirm(kkart_admin_meta_boxes.copy_billing)&&u('.order_data_column :input[name^="_billing_"]').each(function(){var e=(e=u(this).attr("name")).replace("_billing_","_shipping_");u(":input#"+e).val(u(this).val()).change()}),!1}},d={init:function(){this.stupidtable.init(),u("#kkart-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",".refund-actions .cancel-action",this.track_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",".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",".kkart-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 e=u(this).parent().prev().find(":input");e&&(""===e.val()||e.is(".match-total"))&&e.val(u(this).val()).addClass("match-total")}).on("keyup",".split-input :input",function(){u(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("kkart_order_items_reload",this.reload_items).on("kkart_order_items_reloaded",this.reloaded_items),u(document.body).on("kkart_backbone_modal_loaded",this.backbone.init).on("kkart_backbone_modal_response",this.backbone.response)},block:function(){u("#kkart-order-items").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){u("#kkart-order-items").unblock()},reload_items:function(){var e={order_id:kkart_admin_meta_boxes.post_id,action:"kkart_load_order_items",security:kkart_admin_meta_boxes.order_item_nonce};d.block(),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e),d.reloaded_items(),d.unblock()}})},reloaded_items:function(){p.init_tiptip(),d.stupidtable.init()},quantity_changed:function(){var i=u(this).closest("tr.item"),n=u(this).val(),d=u(this).attr("data-qty"),e=u("input.line_total",i),o=u("input.line_subtotal",i),t=accounting.unformat(e.attr("data-total"),kkart_admin.mon_decimal_point)/d;e.val(parseFloat(accounting.formatNumber(t*n,kkart_admin_meta_boxes.rounding_precision,"")).toString().replace(".",kkart_admin.mon_decimal_point));t=accounting.unformat(o.attr("data-subtotal"),kkart_admin.mon_decimal_point)/d;o.val(parseFloat(accounting.formatNumber(t*n,kkart_admin_meta_boxes.rounding_precision,"")).toString().replace(".",kkart_admin.mon_decimal_point)),u("input.line_tax",i).each(function(){var e=u(this),o=e.data("tax_id"),t=accounting.unformat(e.attr("data-total_tax"),kkart_admin.mon_decimal_point)/d,a=u('input.line_subtotal_tax[data-tax_id="'+o+'"]',i),r=accounting.unformat(a.attr("data-subtotal_tax"),kkart_admin.mon_decimal_point)/d,o="yes"===kkart_admin_meta_boxes.round_at_subtotal,o=kkart_admin_meta_boxes[o?"rounding_precision":"currency_format_num_decimals"];0<t&&e.val(parseFloat(accounting.formatNumber(t*n,o,"")).toString().replace(".",kkart_admin.mon_decimal_point)),0<r&&a.val(parseFloat(accounting.formatNumber(r*n,o,"")).toString().replace(".",kkart_admin.mon_decimal_point))}),u(this).trigger("quantity_changed")},add_line_item:function(){return u("div.kkart-order-add-item").slideDown(),u("div.kkart-order-data-row-toggle").not("div.kkart-order-add-item").slideUp(),window.wcTracks.recordEvent("order_edit_add_items_click",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}),!1},add_coupon:function(){window.wcTracks.recordEvent("order_edit_add_coupon_click",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()});var e,o,t,a=window.prompt(kkart_admin_meta_boxes.i18n_apply_coupon);return null==a?window.wcTracks.recordEvent("order_edit_add_coupon_cancel",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}):(d.block(),e=u("#customer_user").val(),o=u("#_billing_email").val(),t=u.extend({},d.get_taxable_address(),{action:"kkart_add_coupon_discount",dataType:"json",order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce,coupon:a,user_id:e,user_email:o}),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:t,type:"POST",success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_added_coupon",{order_id:t.order_id,status:u("#order_status").val()})}})),!1},remove_coupon:function(){var e=u(this);d.block();e=u.extend({},d.get_taxable_address(),{action:"kkart_remove_order_coupon",dataType:"json",order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce,coupon:e.data("code")});u.post(kkart_admin_meta_boxes.ajax_url,e,function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()})},refund_items:function(){return u("div.kkart-order-refund-items").slideDown(),u("div.kkart-order-data-row-toggle").not("div.kkart-order-refund-items").slideUp(),u("div.kkart-order-totals-items").slideUp(),u("#kkart-order-items").find("div.refund").show(),u(".kkart-order-edit-line-item .kkart-order-edit-line-item-actions").hide(),window.wcTracks.recordEvent("order_edit_refund_button_click",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}),!1},cancel:function(){return u("div.kkart-order-data-row-toggle").not("div.kkart-order-bulk-actions").slideUp(),u("div.kkart-order-bulk-actions").slideDown(),u("div.kkart-order-totals-items").slideDown(),u("#kkart-order-items").find("div.refund").hide(),u(".kkart-order-edit-line-item .kkart-order-edit-line-item-actions").show(),"true"===u(this).attr("data-reload")&&d.reload_items(),window.wcTracks.recordEvent("order_edit_add_items_cancelled",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}),!1},track_cancel:function(){window.wcTracks.recordEvent("order_edit_refund_cancel",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()})},add_item:function(){return u(this).KKARTBackboneModal({template:"kkart-modal-add-products"}),!1},add_fee:function(){window.wcTracks.recordEvent("order_edit_add_fee_click",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()});var o,e=window.prompt(kkart_admin_meta_boxes.i18n_add_fee);return null==e?window.wcTracks.recordEvent("order_edit_add_fee_cancel",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}):(d.block(),o=u.extend({},d.get_taxable_address(),{action:"kkart_add_order_fee",dataType:"json",order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce,amount:e}),u.post(kkart_admin_meta_boxes.ajax_url,o,function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock(),window.wcTracks.recordEvent("order_edit_added_fee",{order_id:o.post_id,status:u("#order_status").val()})):window.alert(e.data.error),d.unblock()})),!1},add_shipping:function(){d.block();var o={action:"kkart_add_order_shipping",order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce,dataType:"json"};return u.post(kkart_admin_meta_boxes.ajax_url,o,function(e){e.success?(u("table.kkart_order_items tbody#order_shipping_line_items").append(e.data.html),window.wcTracks.recordEvent("order_edit_add_shipping",{order_id:o.post_id,status:u("#order_status").val()})):window.alert(e.data.error),d.unblock()}),!1},add_tax:function(){return u(this).KKARTBackboneModal({template:"kkart-modal-add-tax"}),!1},edit_item:function(){return u(this).closest("tr").find(".view").hide(),u(this).closest("tr").find(".edit").show(),u(this).hide(),u("button.add-line-item").click(),u("button.cancel-action").attr("data-reload",!0),window.wcTracks.recordEvent("order_edit_edit_item_click",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}),!1},delete_item:function(){var e,o;return window.confirm(kkart_admin_meta_boxes.remove_item_notice)&&(e=u(this).closest("tr.item, tr.fee, tr.shipping").attr("data-order_item_id"),d.block(),o=u.extend({},d.get_taxable_address(),{order_id:kkart_admin_meta_boxes.post_id,order_item_ids:e,action:"kkart_remove_order_item",security:kkart_admin_meta_boxes.order_item_nonce}),"true"===u("button.cancel-action").attr("data-reload")&&(o.items=u("table.kkart_order_items :input[name], .kkart-order-totals-items :input[name]").serialize()),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:o,type:"POST",success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(u("ul.order_notes").empty(),u("ul.order_notes").append(u(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_remove_item",{order_id:o.post_id,status:u("#order_status").val()})}})),!1},delete_tax:function(){var e;return window.confirm(kkart_admin_meta_boxes.i18n_delete_tax)?(d.block(),e={action:"kkart_remove_order_tax",rate_id:u(this).attr("data-rate_id"),order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce},u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),d.reloaded_items(),d.unblock()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_delete_tax",{order_id:e.order_id,status:u("#order_status").val()})}})):window.wcTracks.recordEvent("order_edit_delete_tax_cancel",{order_id:kkart_admin_meta_boxes.post_id,status:u("#order_status").val()}),!1},get_taxable_address:function(){var e="",o="",t="",a="";return"shipping"===kkart_admin_meta_boxes.tax_based_on&&(e=u("#_shipping_country").val(),o=u("#_shipping_state").val(),t=u("#_shipping_postcode").val(),a=u("#_shipping_city").val()),"billing"!==kkart_admin_meta_boxes.tax_based_on&&e||(e=u("#_billing_country").val(),o=u("#_billing_state").val(),t=u("#_billing_postcode").val(),a=u("#_billing_city").val()),{country:e,state:o,postcode:t,city:a}},recalculate:function(){var o;return window.confirm(kkart_admin_meta_boxes.calc_totals)?(d.block(),o=u.extend({},d.get_taxable_address(),{action:"kkart_calc_line_taxes",order_id:kkart_admin_meta_boxes.post_id,items:u("table.kkart_order_items :input[name], .kkart-order-totals-items :input[name]").serialize(),security:kkart_admin_meta_boxes.calc_totals_nonce}),u(document.body).trigger("order-totals-recalculate-before",o),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:o,type:"POST",success:function(e){u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e),d.reloaded_items(),d.unblock(),u(document.body).trigger("order-totals-recalculate-success",e)},complete:function(e){u(document.body).trigger("order-totals-recalculate-complete",e),window.wcTracks.recordEvent("order_edit_recalc_totals",{order_id:o.post_id,OK_cancel:"OK",status:u("#order_status").val()})}})):window.wcTracks.recordEvent("order_edit_recalc_totals",{order_id:kkart_admin_meta_boxes.post_id,OK_cancel:"cancel",status:u("#order_status").val()}),!1},save_line_items:function(){var e={order_id:kkart_admin_meta_boxes.post_id,items:u("table.kkart_order_items :input[name], .kkart-order-totals-items :input[name]").serialize(),action:"kkart_save_order_items",security:kkart_admin_meta_boxes.order_item_nonce};return d.block(),u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(u("ul.order_notes").empty(),u("ul.order_notes").append(u(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):(d.unblock(),window.alert(e.data.error))},complete:function(){window.wcTracks.recordEvent("order_edit_save_line_items",{order_id:e.post_id,status:u("#order_status").val()})}}),u(this).trigger("items_saved"),!1},refunds:{do_refund:function(){var e,o,t,a,r,i,n;d.block(),window.confirm(kkart_admin_meta_boxes.i18n_do_refund)?(e=u("input#refund_amount").val(),o=u("input#refund_reason").val(),t=u("input#refunded_amount").val(),a={},r={},i={},u(".refund input.refund_order_item_qty").each(function(e,o){u(o).closest("tr").data("order_item_id")&&o.value&&(a[u(o).closest("tr").data("order_item_id")]=o.value)}),u(".refund input.refund_line_total").each(function(e,o){u(o).closest("tr").data("order_item_id")&&(r[u(o).closest("tr").data("order_item_id")]=accounting.unformat(o.value,kkart_admin.mon_decimal_point))}),u(".refund input.refund_line_tax").each(function(e,o){var t;u(o).closest("tr").data("order_item_id")&&(t=u(o).data("tax_id"),i[u(o).closest("tr").data("order_item_id")]||(i[u(o).closest("tr").data("order_item_id")]={}),i[u(o).closest("tr").data("order_item_id")][t]=accounting.unformat(o.value,kkart_admin.mon_decimal_point))}),n={action:"kkart_refund_line_items",order_id:kkart_admin_meta_boxes.post_id,refund_amount:e,refunded_amount:t,refund_reason:o,line_item_qtys:JSON.stringify(a,null,""),line_item_totals:JSON.stringify(r,null,""),line_item_tax_totals:JSON.stringify(i,null,""),api_refund:u(this).is(".do-api-refund"),restock_refunded_items:u("#restock_refunded_items:checked").length?"true":"false",security:kkart_admin_meta_boxes.order_item_nonce},u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:n,type:"POST",success:function(e){!0===e.success?window.location.reload():(window.alert(e.data.error),d.reload_items(),d.unblock())},complete:function(){window.wcTracks.recordEvent("order_edit_refunded",{order_id:n.order_id,status:u("#order_status").val(),api_refund:n.api_refund,has_reason:Boolean(n.refund_reason.length),restock:"true"===n.restock_refunded_items})}})):d.unblock()},delete_refund:function(){var e;return window.confirm(kkart_admin_meta_boxes.i18n_delete_refund)&&(e=u(this).closest("tr.refund").attr("data-order_refund_id"),d.block(),e={action:"kkart_delete_refund",refund_id:e,security:kkart_admin_meta_boxes.order_item_nonce},u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(){d.reload_items()}})),!1},input_changed:function(){var t=0;u(".kkart_order_items").find("tr.item, tr.fee, tr.shipping").each(function(){u(this).find(".refund input:not(.refund_order_item_qty)").each(function(e,o){t+=parseFloat(accounting.unformat(u(o).val()||0,kkart_admin.mon_decimal_point))})}),u("#refund_amount").val(accounting.formatNumber(t,kkart_admin_meta_boxes.currency_format_num_decimals,"",kkart_admin.mon_decimal_point)).change()},amount_changed:function(){var e=accounting.unformat(u(this).val(),kkart_admin.mon_decimal_point);u("button .kkart-order-refund-amount .amount").text(accounting.formatMoney(e,{symbol:kkart_admin_meta_boxes.currency_format_symbol,decimal:kkart_admin_meta_boxes.currency_format_decimal_sep,thousand:kkart_admin_meta_boxes.currency_format_thousand_sep,precision:kkart_admin_meta_boxes.currency_format_num_decimals,format:kkart_admin_meta_boxes.currency_format}))},refund_quantity_changed:function(){var a=u(this).closest("tr.item"),r=a.find("input.quantity").val(),i=u(this).val(),e=u("input.line_total",a),o=u("input.refund_line_total",a),e=accounting.unformat(e.attr("data-total"),kkart_admin.mon_decimal_point)/r;o.val(parseFloat(accounting.formatNumber(e*i,kkart_admin_meta_boxes.rounding_precision,"")).toString().replace(".",kkart_admin.mon_decimal_point)).change(),u(".refund_line_tax",a).each(function(){var e=u(this),o=e.data("tax_id"),t=u('input.line_tax[data-tax_id="'+o+'"]',a),o=accounting.unformat(t.data("total_tax"),kkart_admin.mon_decimal_point)/r;0<o?(t="yes"===kkart_admin_meta_boxes.round_at_subtotal,t=kkart_admin_meta_boxes[t?"rounding_precision":"currency_format_num_decimals"],e.val(parseFloat(accounting.formatNumber(o*i,t,"")).toString().replace(".",kkart_admin.mon_decimal_point)).change()):e.val(0).change()}),0<i?u("#restock_refunded_items").closest("tr").show():(u("#restock_refunded_items").closest("tr").hide(),u(".kkart_order_items input.refund_order_item_qty").each(function(){0<u(this).val()&&u("#restock_refunded_items").closest("tr").show()})),u(this).trigger("refund_quantity_changed")}},item_meta:{add:function(){var e=u(this).closest("tr.item, tr.shipping"),o=e.find("tbody.meta_items"),t=o.find("tr").length+1,t='<tr data-meta_id="0"><td><input type="text" maxlength="255" placeholder="'+kkart_admin_meta_boxes_order.placeholder_name+'" name="meta_key['+e.attr("data-order_item_id")+"][new-"+t+']" /><textarea placeholder="'+kkart_admin_meta_boxes_order.placeholder_value+'" name="meta_value['+e.attr("data-order_item_id")+"][new-"+t+']"></textarea></td><td width="1%"><button class="remove_order_item_meta button">×</button></td></tr>';return o.append(t),!1},remove:function(){var e;return window.confirm(kkart_admin_meta_boxes.remove_item_meta)&&((e=u(this).closest("tr")).find(":input").val(""),e.hide()),!1}},backbone:{init:function(e,o){"kkart-modal-add-products"===o&&(u(document.body).trigger("kkart-enhanced-select-init"),u(this).on("change",".kkart-product-search",function(){var e,o;u(this).closest("tr").is(":last-child")&&(o=(e=u(this).closest("table.widefat").find("tbody")).find("tr").length,o=e.data("row").replace(/\[0\]/g,"["+o+"]"),e.append("<tr>"+o+"</tr>"),u(document.body).trigger("kkart-enhanced-select-init"))}))},response:function(e,o,t){var a,r;if("kkart-modal-add-tax"===o&&(a=t.add_order_tax,r="",t.manual_tax_rate_id&&(r=t.manual_tax_rate_id),d.backbone.add_tax(a,r)),"kkart-modal-add-products"===o){var o=u(this).find("table.widefat").find("tbody").find("tr"),i=[];return u(o).each(function(){var e=u(this).find(':input[name="item_id"]').val(),o=u(this).find(':input[name="item_qty"]').val();i.push({id:e,qty:o||1})}),d.backbone.add_items(i)}},add_items:function(e){d.block();var o={action:"kkart_add_order_item",order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce,data:e};"true"===u("button.cancel-action").attr("data-reload")&&(o.items=u("table.kkart_order_items :input[name], .kkart-order-totals-items :input[name]").serialize()),u.ajax({type:"POST",url:kkart_admin_meta_boxes.ajax_url,data:o,success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),e.data.notes_html&&(u("ul.order_notes").empty(),u("ul.order_notes").append(u(e.data.notes_html).find("li"))),d.reloaded_items(),d.unblock()):(d.unblock(),window.alert(e.data.error))},complete:function(){window.wcTracks.recordEvent("order_edit_add_products",{order_id:o.post_id,status:u("#order_status").val()})},dataType:"json"})},add_tax:function(e,o){if(o&&(e=o),!e)return!1;var t,o=u(".order-tax-id").map(function(){return u(this).val()}).get();-1===u.inArray(e,o)?(d.block(),t={action:"kkart_add_order_tax",rate_id:e,order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.order_item_nonce},u.ajax({url:kkart_admin_meta_boxes.ajax_url,data:t,dataType:"json",type:"POST",success:function(e){e.success?(u("#kkart-order-items").find(".inside").empty(),u("#kkart-order-items").find(".inside").append(e.data.html),d.reloaded_items()):window.alert(e.data.error),d.unblock()},complete:function(){window.wcTracks.recordEvent("order_edit_add_tax",{order_id:t.post_id,status:u("#order_status").val()})}})):window.alert(kkart_admin_meta_boxes.i18n_tax_rate_already_exists)}},stupidtable:{init:function(){u(".kkart_order_items").stupidtable(),u(".kkart_order_items").on("aftertablesort",this.add_arrows)},add_arrows:function(e,o){var t=u(this).find("th"),a="asc"===o.direction?"↑":"↓",o=o.column;t.find(".kkart-arrow").remove(),t.eq(o).append('<span class="kkart-arrow">'+a+"</span>")}}},e={init:function(){u("#kkart-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(u("textarea#add_order_note").val()){u("#kkart-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var o={action:"kkart_add_order_note",post_id:kkart_admin_meta_boxes.post_id,note:u("textarea#add_order_note").val(),note_type:u("select#order_note_type").val(),security:kkart_admin_meta_boxes.add_order_note_nonce};return u.post(kkart_admin_meta_boxes.ajax_url,o,function(e){u("ul.order_notes .no-items").remove(),u("ul.order_notes").prepend(e),u("#kkart-order-notes").unblock(),u("#add_order_note").val(""),window.wcTracks.recordEvent("order_edit_add_order_note",{order_id:o.post_id,note_type:o.note_type||"private",status:u("#order_status").val()})}),!1}},delete_order_note:function(){var e,o;return window.confirm(kkart_admin_meta_boxes.i18n_delete_note)&&(e=u(this).closest("li.note"),u(e).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),o={action:"kkart_delete_order_note",note_id:u(e).attr("rel"),security:kkart_admin_meta_boxes.delete_order_note_nonce},u.post(kkart_admin_meta_boxes.ajax_url,o,function(){u(e).remove()})),!1}},o={init:function(){u(".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 e=u("#grant_access_id").val();if(e){u(".order_download_permissions").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});e={action:"kkart_grant_access_to_download",product_ids:e,loop:u(".order_download_permissions .kkart-metabox").length,order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.grant_access_nonce};return u.post(kkart_admin_meta_boxes.ajax_url,e,function(e){e?u(".order_download_permissions .kkart-metaboxes").append(e):window.alert(kkart_admin_meta_boxes.i18n_download_permission_fail),u(document.body).trigger("kkart-init-datepickers"),u("#grant_access_id").val("").change(),u(".order_download_permissions").unblock()}),!1}},revoke_access:function(){var e,o,t,a;return window.confirm(kkart_admin_meta_boxes.i18n_permission_revoke)&&(e=u(this).parent().parent(),o=u(this).attr("rel").split(",")[0],t=u(this).attr("rel").split(",")[1],a=u(this).data("permission_id"),0<o?(u(e).block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a={action:"kkart_revoke_access_to_download",product_id:o,download_id:t,permission_id:a,order_id:kkart_admin_meta_boxes.post_id,security:kkart_admin_meta_boxes.revoke_access_nonce},u.post(kkart_admin_meta_boxes.ajax_url,a,function(){u(e).fadeOut("300",function(){u(e).remove()})})):u(e).fadeOut("300",function(){u(e).remove()})),!1},copy_link:function(e){wcClearClipboard(),wcSetClipboard(u(this).attr("href"),u(this)),e.preventDefault()},copy_success:function(){u(this).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()},copy_fail:function(){u(this).tipTip({attribute:"data-tip-failed",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()}};p.init(),d.init(),e.init(),o.init()});