From 17481af671ea036a514f7ffd909eb128e1330c41 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 17 Jan 2017 15:50:19 +0000 Subject: [PATCH] Allow html in description --- assets/js/admin/wc-shipping-zone-methods.js | 2 +- assets/js/admin/wc-shipping-zone-methods.min.js | 2 +- .../views/html-admin-page-shipping-zone-methods.php | 5 ++--- .../settings/views/html-admin-page-shipping-zones.php | 2 +- includes/class-wc-shipping-zone.php | 9 +++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/assets/js/admin/wc-shipping-zone-methods.js b/assets/js/admin/wc-shipping-zone-methods.js index e22bc9961b5..c3ec5efc753 100644 --- a/assets/js/admin/wc-shipping-zone-methods.js +++ b/assets/js/admin/wc-shipping-zone-methods.js @@ -362,7 +362,7 @@ onChangeShippingMethodSelector: function() { var description = $( this ).find( 'option:selected' ).data( 'description' ); $( this ).parent().find( '.wc-shipping-zone-method-description' ).remove(); - $( this ).after( '

' + description + '

' ); + $( this ).after( '
' + description + '
' ); $( this ).closest( 'article' ).height( $( this ).parent().height() ); }, onTogglePostcodes: function( event ) { diff --git a/assets/js/admin/wc-shipping-zone-methods.min.js b/assets/js/admin/wc-shipping-zone-methods.min.js index 593ede9331b..375e7d8f870 100644 --- a/assets/js/admin/wc-shipping-zone-methods.min.js +++ b/assets/js/admin/wc-shipping-zone-methods.min.js @@ -1 +1 @@ -!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=''+b.strings.yes+"":c.enabled_icon=''+b.strings.no+"",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=b.data.view,d=c.model,e=_.indexBy(d.get("methods"),"instance_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f.methods=f.methods||{methods:{}},f.methods[g]=_.extend(f.methods[g]||{},{deleted:"deleted"}),d.set("methods",e),d.logChanges(f),c.render()},onToggleEnabled:function(b){var c=b.data.view,d=a(b.target),e=c.model,f=_.indexBy(e.get("methods"),"instance_id"),g=d.closest("tr").data("id"),h="yes"===d.closest("tr").data("enabled")?"no":"yes",i={};b.preventDefault(),f[g].enabled=h,i.methods=i.methods||{methods:{}},i.methods[g]=_.extend(i.methods[g]||{},{enabled:h}),e.set("methods",f),e.logChanges(i),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){if(a.data.view.needsUnloadConfirm)return a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("methods"),"instance_id"),i={};h[e][f]!==g&&(i.methods[e]={},i.methods[e][f]=g,h[e][f]=g),c.logChanges(i)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("methods"),"instance_id"),f={};_.each(d,function(a){var b=parseInt(a.method_order,10),c=parseInt(e.find('tr[data-id="'+a.instance_id+'"]').index()+1,10);b!==c&&(d[a.instance_id].method_order=c,f.methods=f.methods||{methods:{}},f.methods[a.instance_id]=_.extend(f.methods[a.instance_id]||{},{method_order:c}))}),_.size(f)&&c.logChanges(f)},onConfigureShippingMethod:function(b){var c=a(this).closest("tr").data("id"),d=b.data.view.model,e=_.indexBy(d.get("methods"),"instance_id"),f=e[c];return!f.settings_html||(b.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-shipping-method-settings",variable:{instance_id:c,method:f},data:{instance_id:c,method:f}}),void a(document.body).trigger("init_tooltips"))},onConfigureShippingMethodSubmitted:function(c,e,f){"wc-modal-shipping-method-settings"===e&&(m.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_settings",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,instance_id:f.instance_id,data:f},function(c,d){"success"===d&&c.success?(a("table.wc-shipping-zone-methods").parent().find("#woocommerce_errors").remove(),c.data.errors.length>0&&this.showErrors(c.data.errors),_.size(m.model.changes)?m.model.save():m.model.onSaveResponse(c,d)):(window.alert(b.strings.save_failed),m.unblock())},"json"))},showErrors:function(b){var c='
';a(b).each(function(a,b){c=c+"

"+b+"

"}),c+="
",a("table.wc-shipping-zone-methods").before(c)},onAddShippingMethod:function(c){c.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-add-shipping-method",variable:{zone_id:b.zone_id}}),a(".wc-shipping-zone-method-selector select").change()},onAddShippingMethodSubmitted:function(c,e,f){"wc-modal-add-shipping-method"===e&&(m.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:f.add_method_id,zone_id:b.zone_id},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)),_.size(m.model.changes)?m.model.save():(m.model.set("methods",a.data.methods),m.model.trigger("change:methods"),m.model.changes={},m.model.trigger("saved:methods"))),m.unblock()},"json"))},onChangeShippingMethodSelector:function(){var b=a(this).find("option:selected").data("description");a(this).parent().find(".wc-shipping-zone-method-description").remove(),a(this).after('

'+b+"

"),a(this).closest("article").height(a(this).parent().height())},onTogglePostcodes:function(b){b.preventDefault();var c=a(this).closest("tr");c.find(".wc-shipping-zone-postcodes").show(),c.find(".wc-shipping-zone-postcodes-toggle").hide()}}),l=new j({methods:b.methods,zone_name:b.zone_name}),m=new k({model:l,el:f});m.render(),f.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl); \ No newline at end of file +!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=''+b.strings.yes+"":c.enabled_icon=''+b.strings.no+"",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=b.data.view,d=c.model,e=_.indexBy(d.get("methods"),"instance_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f.methods=f.methods||{methods:{}},f.methods[g]=_.extend(f.methods[g]||{},{deleted:"deleted"}),d.set("methods",e),d.logChanges(f),c.render()},onToggleEnabled:function(b){var c=b.data.view,d=a(b.target),e=c.model,f=_.indexBy(e.get("methods"),"instance_id"),g=d.closest("tr").data("id"),h="yes"===d.closest("tr").data("enabled")?"no":"yes",i={};b.preventDefault(),f[g].enabled=h,i.methods=i.methods||{methods:{}},i.methods[g]=_.extend(i.methods[g]||{},{enabled:h}),e.set("methods",f),e.logChanges(i),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){if(a.data.view.needsUnloadConfirm)return a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("methods"),"instance_id"),i={};h[e][f]!==g&&(i.methods[e]={},i.methods[e][f]=g,h[e][f]=g),c.logChanges(i)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("methods"),"instance_id"),f={};_.each(d,function(a){var b=parseInt(a.method_order,10),c=parseInt(e.find('tr[data-id="'+a.instance_id+'"]').index()+1,10);b!==c&&(d[a.instance_id].method_order=c,f.methods=f.methods||{methods:{}},f.methods[a.instance_id]=_.extend(f.methods[a.instance_id]||{},{method_order:c}))}),_.size(f)&&c.logChanges(f)},onConfigureShippingMethod:function(b){var c=a(this).closest("tr").data("id"),d=b.data.view.model,e=_.indexBy(d.get("methods"),"instance_id"),f=e[c];return!f.settings_html||(b.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-shipping-method-settings",variable:{instance_id:c,method:f},data:{instance_id:c,method:f}}),void a(document.body).trigger("init_tooltips"))},onConfigureShippingMethodSubmitted:function(c,e,f){"wc-modal-shipping-method-settings"===e&&(m.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_settings",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,instance_id:f.instance_id,data:f},function(c,d){"success"===d&&c.success?(a("table.wc-shipping-zone-methods").parent().find("#woocommerce_errors").remove(),c.data.errors.length>0&&this.showErrors(c.data.errors),_.size(m.model.changes)?m.model.save():m.model.onSaveResponse(c,d)):(window.alert(b.strings.save_failed),m.unblock())},"json"))},showErrors:function(b){var c='
';a(b).each(function(a,b){c=c+"

"+b+"

"}),c+="
",a("table.wc-shipping-zone-methods").before(c)},onAddShippingMethod:function(c){c.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-add-shipping-method",variable:{zone_id:b.zone_id}}),a(".wc-shipping-zone-method-selector select").change()},onAddShippingMethodSubmitted:function(c,e,f){"wc-modal-add-shipping-method"===e&&(m.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:f.add_method_id,zone_id:b.zone_id},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)),_.size(m.model.changes)?m.model.save():(m.model.set("methods",a.data.methods),m.model.trigger("change:methods"),m.model.changes={},m.model.trigger("saved:methods"))),m.unblock()},"json"))},onChangeShippingMethodSelector:function(){var b=a(this).find("option:selected").data("description");a(this).parent().find(".wc-shipping-zone-method-description").remove(),a(this).after('
'+b+"
"),a(this).closest("article").height(a(this).parent().height())},onTogglePostcodes:function(b){b.preventDefault();var c=a(this).closest("tr");c.find(".wc-shipping-zone-postcodes").show(),c.find(".wc-shipping-zone-postcodes-toggle").hide()}}),l=new j({methods:b.methods,zone_name:b.zone_name}),m=new k({model:l,el:f});m.render(),f.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl); \ No newline at end of file diff --git a/includes/admin/settings/views/html-admin-page-shipping-zone-methods.php b/includes/admin/settings/views/html-admin-page-shipping-zone-methods.php index cb3e9f2094e..c5e6fa86195 100644 --- a/includes/admin/settings/views/html-admin-page-shipping-zone-methods.php +++ b/includes/admin/settings/views/html-admin-page-shipping-zone-methods.php @@ -112,7 +112,7 @@ if ( ! defined( 'ABSPATH' ) ) { {{ data.method_title }} {{{ data.enabled_icon }}} - {{ data.method_description }} + {{{ data.method_description }}} @@ -170,8 +170,7 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! $method->supports( 'shipping-zones' ) ) { continue; } - - echo '