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

1 line
29 KiB
JavaScript
Raw Normal View History

2021-12-10 12:03:04 +00:00
jQuery(function(u){window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){};var p={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=JSON.parse(woocommerce_admin_meta_boxes_order.countries.replace(/&quot;/g,'"'))),u(".js_field-country").selectWoo().on("change",this.change_country),u(".js_field-country").trigger("change",[!0]),u(document.body).on("change","select.js_field-state",this.change_state),u("#woocommerce-order-actions input, #woocommerce-order-actions a").on("click",function(){window.onbeforeunload=""}),u("a.edit_address").on("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,r,a,i,n,d,c,_,s,m,l;void 0===o&&(o=!1),null!==p.states&&(r=(t=u(this)).val(),m=(a=t.parents("div.edit_address").find(":input.js_field-state")).parent(),i=a.val(),n=a.attr("name"),d=a.attr("id"),c=t.data("woocommerce.stickState-"+r)?t.data("woocommerce.stickState-"+r):i,_=a.attr("placeholder"),o&&t.data("woocommerce.stickState-"+r,c),m.show().find(".select2-container").remove(),u.isEmptyObject(p.states[r])?(l=u('<input type="text" />').prop("id",d).prop("name",n).prop("placeholder",_).addClass("js_field-state").val(i),a.replaceWith(l)):(s=p.states[r],m=u('<option value=""></option>').text(woocommerce_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),a.replaceWith(l),l.show().selectWoo().hide().trigger("change")),u(document.body).trigger("contry-change.woocommerce",[r,u(this).closest("div")]),u(document.body).trigger("country-change.woocommerce",[r,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("woocommerce.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"),r=t.find("div.edit_address"),a=t.find("div.address"),i=r.find(".js_field-country"),e=r.find(".js_field-state"),t=Boolean(r.find('input[name^="_billing_"]').length);a.hide(),o.parent().find("a").toggle(),i.val()||(i.val(woocommerce_admin_meta_boxes_order.default_country).trigger("change"),e.val(woocommerce_admin_meta_boxes_order.default_state).trigger("change")),r.show();t=t?"order_edit_billing_address_click":"order_edit_shipping_address_click";window.wcTracks.recordEvent(t,{order_id:woocommerce_admin_meta_boxes.post_id,status:u("#order_status").val()})},change_customer_user:function(){u("#_billing_country").val()||(u("a.edit_address").trigger("click"),p.load_billing(!0),p.load_shipping(!0))},load_billing:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_billing)){e=u("#customer_user").val();if(!e)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;e={user_id:e,action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};u(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),u.ajax({url:woocommerce_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).trigger("change")}),u("div.edit_address").unblock()}})}return!1},load_shipping:function(e){if(!0===e||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){e=u("#customer_user").val();if(!e)return window.a