2018-08-30 16:56:26 +00:00
|
|
|
!function(c,r,p,l){c(function(){var s=c(".wc-shipping-zone-methods"),e=c(".wc-shipping-zone-method-rows"),n=c(".wc-shipping-zone-method-save"),t=p.template("wc-shipping-zone-method-row"),o=p.template("wc-shipping-zone-method-row-blank"),i=Backbone.Model.extend({changes:{},logChanges:function(e){var t=this.changes||{};_.each(e.methods,function(e,n){t.methods=t.methods||{methods:{}},t.methods[n]=_.extend(t.methods[n]||{instance_id:n},e)}),"undefined"!=typeof e.zone_name&&(t.zone_name=e.zone_name),"undefined"!=typeof e.zone_locations&&(t.zone_locations=e.zone_locations),"undefined"!=typeof e.zone_postcodes&&(t.zone_postcodes=e.zone_postcodes),this.changes=t,this.trigger("change:methods")},save:function(){c.post(l+(0<l.indexOf("?")?"&":"?")+"action=woocommerce_shipping_zone_methods_save_changes",{wc_shipping_zones_nonce:r.wc_shipping_zones_nonce,changes:this.changes,zone_id:r.zone_id},this.onSaveResponse,"json")},onSaveResponse:function(e,n){"success"===n&&(e.success?(e.data.zone_id!==r.zone_id&&(r.zone_id=e.data.zone_id,window.history.pushState&&window.history.pushState({},"","admin.php?page=wc-settings&tab=shipping&zone_id="+e.data.zone_id)),a.set("methods",e.data.methods),a.trigger("change:methods"),a.changes={},a.trigger("saved:methods")):window.alert(r.strings.save_failed))}}),d=Backbone.View.extend({rowTemplate:t,initialize:function(){this.listenTo(this.model,"change:methods",this.setUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.render),e.on("change",{view:this},this.updateModelOnChange),e.on("sortupdate",{view:this},this.updateModelOnSort),c(window).on("beforeunload",{view:this},this.unloadConfirmation),n.on("click",{view:this},this.onSubmit),c(document.body).on("input change","#zone_name, #zone_locations, #zone_postcodes",{view:this},this.onUpdateZone),c(document.body).on("click",".wc-shipping-zone-method-settings",{view:this},this.onConfigureShippingMethod),c(document.body).on("click",".wc-shipping-zone-add-method",{view:this},this.onAddShippingMethod),c(document.body).on("wc_backbone_modal_response",this.onConfigureShippingMethodSubmitted),c(document.body).on("wc_backbone_modal_response",this.onAddShippingMethodSubmitted),c(document.body).on("change",".wc-shipping-zone-method-selector select",this.onChangeShippingMethodSelector),c(document.body).on("click",".wc-shipping-zone-postcodes-toggle",this.onTogglePostcodes)},onUpdateZone:function(e){var n=e.data.view,t=n.model,o=c(this).val(),i=c(e.target).data("attribute"),s={};e.preventDefault(),s[i]=o,t.set(i,o),t.logChanges(s),n.render()},block:function(){c(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){c(this.el).unblock()},render:function(){var e=_.indexBy(this.model.get("methods"),"instance_id"),n=this.model.get("zone_name"),i=this;c(".wc-shipping-zone-name").text(n||r.strings.default_zone_name),this.$el.empty(),this.unblock(),_.size(e)?(e=_.sortBy(e,function(e){return parseInt(e.method_order,10)}),c.each(e,function(e,n){"yes"===n.enabled?n.enabled_icon='<span class="woocommerce-input-toggle woocommerce-input-toggle--enabled">'+r.strings.yes+"</span>":n.enabled_icon='<span class="woocommerce-input-toggle woocommerce-input-toggle--disabled">'+r.strings.no+"</span>",i.$el.append(i.rowTemplate(n));var t=i.$el.find('tr[data-id="'+n.instance_id+'"]');if(!n.has_settings){t.find(".wc-shipping-zone-method-title > a").replaceWith("<span>"+t.find(".wc-shipping-zone-method-title > a").text()+"</span>");var o=t.find(".wc-shipping-zone-method-delete");t.find(".wc-shipping-zone-method-title .row-actions").empty().html(o)}}),this.$el.find(".wc-shipping-zone-method-delete").on("click",{view:this},this.onDeleteRow),this.$el.find(".wc-shipping-zone-method-enabled a").on("click",{view:this},this.onToggleEnabled)):i.$el.append(o),this.initTooltips()},initTooltips:function(){c("#tiptip_holder").removeAttr("style"),c("#tiptip_arrow").removeAttr("style"),c(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(e){e.data
|