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