Merged in feature/280-dev-dev01 (pull request #21)
auto-patch 280-dev-dev01-2024-01-19T16_41_58 * auto-patch 280-dev-dev01-2024-01-19T16_41_58
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
events: {
|
||||
'click .modal-close': 'closeButton',
|
||||
'click #btn-ok' : 'addButton',
|
||||
'click #btn-back' : 'backButton',
|
||||
'click #btn-next' : 'nextButton',
|
||||
'touchstart #btn-ok': 'addButton',
|
||||
'keydown' : 'keyboardActions',
|
||||
@@ -111,6 +112,10 @@
|
||||
$( document.body ).trigger( 'wc_backbone_modal_response', [ this._target, this.getFormData() ] );
|
||||
this.closeButton( e, true );
|
||||
},
|
||||
backButton: function( e ) {
|
||||
$( document.body ).trigger( 'wc_backbone_modal_back_response', [ this._target, this.getFormData() ] );
|
||||
this.closeButton( e, false );
|
||||
},
|
||||
nextButton: function( e ) {
|
||||
var context = this;
|
||||
function closeModal() {
|
||||
|
||||
@@ -1 +1 @@
|
||||
!function(t,e,n){"use strict";t.fn.WCBackboneModal=function(e){return this.each(function(){new t.WCBackboneModal(t(this),e)})},t.WCBackboneModal=function(e,n){var o=t.extend({},t.WCBackboneModal.defaultOptions,n);o.template&&new t.WCBackboneModal.View({target:o.template,string:o.variable})},t.WCBackboneModal.defaultOptions={template:"",variable:{}},t.WCBackboneModal.View=e.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:undefined,_string:undefined,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","click #btn-next":"nextButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions",input:"handleInputValidation"},resizeContent:function(){var e=t(".wc-backbone-modal-content").find("article"),n=.75*t(window).height();e.css({"max-height":n+"px"})},initialize:function(e){var o=this;this._target=e.target,this._string=e.string,n.bindAll(this,"render"),this.render(),t(window).on("resize",function(){o.resizeContent()})},render:function(){var e=wp.template(this._target);this.$el.append(e(this._string)),t(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),this.$(".wc-backbone-modal-content").attr("tabindex","0").trigger("focus"),t(document.body).trigger("init_tooltips"),t(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(e,n){e.preventDefault(),t(document.body).trigger("wc_backbone_modal_before_remove",[this._target,this.getFormData(),!!n]),this.undelegateEvents(),t(document).off("focusin"),t(document.body).css({overflow:"auto"}),this.remove(),t(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(e){t(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(e,!0)},nextButton:function(e){var n=this;t(document.body).trigger("wc_backbone_modal_next_response",[this._target,this.getFormData(),function(){n.closeButton(e)}])},getFormData:function(e=!0){var n={};return e&&t(document.body).trigger("wc_backbone_modal_before_update",this._target),t.each(t("form",this.$el).serializeArray(),function(e,o){-1!==o.name.indexOf("[]")?(o.name=o.name.replace("[]",""),n[o.name]=t.makeArray(n[o.name]),n[o.name].push(o.value)):n[o.name]=o.value}),n},handleInputValidation:function(){t(document.body).trigger("wc_backbone_modal_validation",[this._target,this.getFormData(!1)])},keyboardActions:function(e){var n=e.keyCode||e.which;13!==n||e.target.tagName&&("input"===e.target.tagName.toLowerCase()||"textarea"===e.target.tagName.toLowerCase())||(t("#btn-ok").length?this.addButton(e):t("#btn-next").length&&this.nextButton(e)),27===n&&this.closeButton(e)}})}(jQuery,Backbone,_);
|
||||
!function(t,e,n){"use strict";t.fn.WCBackboneModal=function(e){return this.each(function(){new t.WCBackboneModal(t(this),e)})},t.WCBackboneModal=function(e,n){var o=t.extend({},t.WCBackboneModal.defaultOptions,n);o.template&&new t.WCBackboneModal.View({target:o.template,string:o.variable})},t.WCBackboneModal.defaultOptions={template:"",variable:{}},t.WCBackboneModal.View=e.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:undefined,_string:undefined,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","click #btn-back":"backButton","click #btn-next":"nextButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions",input:"handleInputValidation"},resizeContent:function(){var e=t(".wc-backbone-modal-content").find("article"),n=.75*t(window).height();e.css({"max-height":n+"px"})},initialize:function(e){var o=this;this._target=e.target,this._string=e.string,n.bindAll(this,"render"),this.render(),t(window).on("resize",function(){o.resizeContent()})},render:function(){var e=wp.template(this._target);this.$el.append(e(this._string)),t(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),this.$(".wc-backbone-modal-content").attr("tabindex","0").trigger("focus"),t(document.body).trigger("init_tooltips"),t(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(e,n){e.preventDefault(),t(document.body).trigger("wc_backbone_modal_before_remove",[this._target,this.getFormData(),!!n]),this.undelegateEvents(),t(document).off("focusin"),t(document.body).css({overflow:"auto"}),this.remove(),t(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(e){t(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(e,!0)},backButton:function(e){t(document.body).trigger("wc_backbone_modal_back_response",[this._target,this.getFormData()]),this.closeButton(e,!1)},nextButton:function(e){var n=this;t(document.body).trigger("wc_backbone_modal_next_response",[this._target,this.getFormData(),function(){n.closeButton(e)}])},getFormData:function(e=!0){var n={};return e&&t(document.body).trigger("wc_backbone_modal_before_update",this._target),t.each(t("form",this.$el).serializeArray(),function(e,o){-1!==o.name.indexOf("[]")?(o.name=o.name.replace("[]",""),n[o.name]=t.makeArray(n[o.name]),n[o.name].push(o.value)):n[o.name]=o.value}),n},handleInputValidation:function(){t(document.body).trigger("wc_backbone_modal_validation",[this._target,this.getFormData(!1)])},keyboardActions:function(e){var n=e.keyCode||e.which;13!==n||e.target.tagName&&("input"===e.target.tagName.toLowerCase()||"textarea"===e.target.tagName.toLowerCase())||(t("#btn-ok").length?this.addButton(e):t("#btn-next").length&&this.nextButton(e)),27===n&&this.closeButton(e)}})}(jQuery,Backbone,_);
|
||||
@@ -1440,7 +1440,7 @@ jQuery( function ( $ ) {
|
||||
grant_access: function() {
|
||||
var products = $( '#grant_access_id' ).val();
|
||||
|
||||
if ( ! products ) {
|
||||
if ( ! products || 0 === products.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1462,7 +1462,7 @@ jQuery( function ( $ ) {
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
if ( response ) {
|
||||
if ( response && -1 !== parseInt( response ) ) {
|
||||
$( '.order_download_permissions .wc-metaboxes' ).append( response );
|
||||
} else {
|
||||
window.alert( woocommerce_admin_meta_boxes.i18n_download_permission_fail );
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -176,7 +176,10 @@ jQuery( function ( $ ) {
|
||||
function change_product_type_tip( content ) {
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
$( '#tiptip_arrow' ).removeAttr( 'style' );
|
||||
$( '.woocommerce-product-type-tip' ).tipTip( {
|
||||
$( '.woocommerce-product-type-tip' )
|
||||
.attr( 'tabindex', '0' )
|
||||
.attr( 'aria-label', $( '<div />' ).html( content ).text() ) // Remove HTML tags.
|
||||
.tipTip( {
|
||||
attribute: 'data-tip',
|
||||
content: content,
|
||||
fadeIn: 50,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,35 @@
|
||||
/*global woocommerce_admin_meta_boxes, wcTracks */
|
||||
jQuery( document ).ready( ( $ ) => {
|
||||
'use strict';
|
||||
|
||||
// Stand-in wcTracks.recordEvent in case Tracks is not available (for any reason).
|
||||
window.wcTracks = window.wcTracks || {};
|
||||
window.wcTracks.recordEvent = window.wcTracks.recordEvent || ( () => {} );
|
||||
|
||||
// Handle the "Details" container toggle.
|
||||
$( '.woocommerce-order-attribution-details-toggle' )
|
||||
.on( 'click', ( e ) => {
|
||||
const $this = $( e.target ).closest( '.woocommerce-order-attribution-details-toggle');
|
||||
const $container = $this.closest( '.order-attribution-metabox' )
|
||||
.find( '.woocommerce-order-attribution-details-container' );
|
||||
let toggle = '';
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$container.fadeToggle( 250 );
|
||||
$this.find( '.toggle-text' ).toggle();
|
||||
if ( $container.hasClass( 'closed' ) ) {
|
||||
$this.attr( 'aria-expanded', 'true' );
|
||||
toggle = 'opened';
|
||||
} else {
|
||||
$this.attr( 'aria-expanded', 'false' );
|
||||
toggle = 'closed';
|
||||
}
|
||||
$container.toggleClass( 'closed' );
|
||||
|
||||
window.wcTracks.recordEvent( 'order_attribution_details_toggle', {
|
||||
order_id: window.woocommerce_admin_meta_boxes.order_id,
|
||||
details: toggle
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/admin/order-attribution-admin.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/admin/order-attribution-admin.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(document).ready(e=>{"use strict";window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||(()=>{}),e(".woocommerce-order-attribution-details-toggle").on("click",o=>{const t=e(o.target).closest(".woocommerce-order-attribution-details-toggle"),r=t.closest(".order-attribution-metabox").find(".woocommerce-order-attribution-details-container");let d="";o.preventDefault(),r.fadeToggle(250),t.find(".toggle-text").toggle(),r.hasClass("closed")?(t.attr("aria-expanded","true"),d="opened"):(t.attr("aria-expanded","false"),d="closed"),r.toggleClass("closed"),window.wcTracks.recordEvent("order_attribution_details_toggle",{order_id:window.woocommerce_admin_meta_boxes.order_id,details:d})})});
|
||||
@@ -103,6 +103,7 @@
|
||||
$( document.body ).on( 'wc_region_picker_update', this.onUpdateZoneRegionPicker );
|
||||
$( document.body ).on( 'wc_backbone_modal_next_response', this.onAddShippingMethodSubmitted );
|
||||
$( document.body ).on( 'wc_backbone_modal_before_remove', this.onCloseConfigureShippingMethod );
|
||||
$( document.body ).on( 'wc_backbone_modal_back_response', this.onConfigureShippingMethodBack );
|
||||
$( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector );
|
||||
$( document.body ).on( 'click', '.wc-shipping-zone-postcodes-toggle', this.onTogglePostcodes );
|
||||
$( document.body ).on( 'wc_backbone_modal_validation', { view: this }, this.validateFormArguments );
|
||||
@@ -344,6 +345,8 @@
|
||||
}
|
||||
});
|
||||
|
||||
shippingMethodView.highlightOnFocus( '.wc-shipping-modal-price' );
|
||||
|
||||
$( document.body ).trigger( 'init_tooltips' );
|
||||
},
|
||||
onConfigureShippingMethodSubmitted: function( event, target, posted_data ) {
|
||||
@@ -382,6 +385,11 @@
|
||||
);
|
||||
}
|
||||
},
|
||||
onConfigureShippingMethodBack: function( event, target ) {
|
||||
if ( 'wc-modal-shipping-method-settings' === target ) {
|
||||
shippingMethodView.onAddShippingMethod( event );
|
||||
}
|
||||
},
|
||||
showErrors: function( errors ) {
|
||||
var error_html = '<div id="woocommerce_errors" class="error notice is-dismissible">';
|
||||
|
||||
@@ -392,6 +400,12 @@
|
||||
|
||||
$( 'table.wc-shipping-zone-methods' ).before( error_html );
|
||||
},
|
||||
highlightOnFocus: function( query ) {
|
||||
const inputs = $( query );
|
||||
inputs.focus( function() {
|
||||
$( this ).select();
|
||||
} );
|
||||
},
|
||||
onAddShippingMethod: function( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -403,6 +417,15 @@
|
||||
});
|
||||
|
||||
$( '.wc-shipping-zone-method-selector select' ).trigger( 'change' );
|
||||
|
||||
$('.wc-shipping-zone-method-input input').change( function() {
|
||||
const selected = $('.wc-shipping-zone-method-input input:checked');
|
||||
const id = selected.attr( 'id' );
|
||||
const description = $( `#${ id }-description` );
|
||||
const descriptions = $( '.wc-shipping-zone-method-input-help-text' );
|
||||
descriptions.css( 'display', 'none' );
|
||||
description.css( 'display', 'block' );
|
||||
});
|
||||
},
|
||||
/**
|
||||
* The settings HTML is controlled and built by the settings api, so in order to refactor the
|
||||
@@ -501,14 +524,15 @@
|
||||
return htmlContent.prop( 'outerHTML' );
|
||||
},
|
||||
replaceHTMLTables: function ( html ) {
|
||||
// Wrap the html content in a div
|
||||
const htmlContent = $( '<div>' + html + '</div>' );
|
||||
|
||||
// `<table class="form-table" />` elements added by the Settings API need to be removed.
|
||||
// Modern browsers won't interpret other table elements like `td` not in a `table`, so
|
||||
// Removing the `table` is sufficient.
|
||||
const htmlContent = $( html );
|
||||
const tables = htmlContent.find( 'table.form-table' );
|
||||
|
||||
tables.each( ( i ) => {
|
||||
const table = $( tables[ i ] );
|
||||
const innerTables = htmlContent.find( 'table.form-table' );
|
||||
innerTables.each( ( i ) => {
|
||||
const table = $( innerTables[ i ] );
|
||||
const div = $( '<div class="wc-shipping-zone-method-fields" />' );
|
||||
div.html( table.html() );
|
||||
table.replaceWith( div );
|
||||
@@ -520,7 +544,7 @@
|
||||
if ( 'wc-modal-add-shipping-method' === target ) {
|
||||
shippingMethodView.block();
|
||||
|
||||
$('#btn-next').html('<img alt="processing" src="images/wpspin_light.gif" class="waiting" />');
|
||||
$('#btn-next').addClass( 'is-busy' );
|
||||
|
||||
// Add method to zone via ajax call
|
||||
$.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', {
|
||||
@@ -569,6 +593,8 @@
|
||||
status : 'new'
|
||||
}
|
||||
});
|
||||
|
||||
shippingMethodView.highlightOnFocus( '.wc-shipping-modal-price' );
|
||||
} else {
|
||||
shippingMethodView.model.trigger( 'change:methods' );
|
||||
shippingMethodView.model.trigger( 'saved:methods' );
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -136,11 +136,14 @@
|
||||
$tr.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||
},
|
||||
initRows: function() {
|
||||
const isEven = 0 !== ( $( 'tbody.wc-shipping-zone-rows tr' ).length % 2 );
|
||||
const tfoot = $( 'tfoot.wc-shipping-zone-rows-tfoot' );
|
||||
|
||||
// Stripe
|
||||
if ( 0 === ( $( 'tbody.wc-shipping-zone-rows tr' ).length % 2 ) ) {
|
||||
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' );
|
||||
if ( isEven ) {
|
||||
tfoot.find( 'tr' ).addClass( 'even' );
|
||||
} else {
|
||||
$table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' );
|
||||
tfoot.find( 'tr' ).removeClass( 'even' );
|
||||
}
|
||||
// Tooltips
|
||||
$( '#tiptip_holder' ).removeAttr( 'style' );
|
||||
|
||||
@@ -1 +1 @@
|
||||
!function(e,n,i,o){e(function(){var t=e(".wc-shipping-zones"),s=e(".wc-shipping-zone-rows"),d=e(".wc-shipping-zone-save"),a=i.template("wc-shipping-zone-row"),r=i.template("wc-shipping-zone-row-blank"),l=Backbone.Model.extend({changes:{},logChanges:function(e){var n=this.changes||{};_.each(e,function(e,i){n[i]=_.extend(n[i]||{zone_id:i},e)}),this.changes=n,this.trigger("change:zones")},discardChanges:function(e){var n=this.changes||{},i=null,o=_.indexBy(this.get("zones"),"zone_id");n[e]&&n[e].zone_order!==undefined&&(i=n[e].zone_order),delete n[e],null!==i&&o[e]&&o[e].zone_order!==i&&(n[e]=_.extend(n[e]||{},{zone_id:e,zone_order:i})),this.changes=n,0===_.size(this.changes)&&p.clearUnloadConfirmation()},save:function(){_.size(this.changes)?e.post(o+(o.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zones_save_changes",{wc_shipping_zones_nonce:n.wc_shipping_zones_nonce,changes:this.changes},this.onSaveResponse,"json"):h.trigger("saved:zones")},onSaveResponse:function(e,i){"success"===i&&(e.success?(h.set("zones",e.data.zones),h.trigger("change:zones"),h.changes={},h.trigger("saved:zones")):window.alert(n.strings.save_failed))}}),c=Backbone.View.extend({rowTemplate:a,initialize:function(){this.listenTo(this.model,"change:zones",this.setUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.render),s.on("change",{view:this},this.updateModelOnChange),s.on("sortupdate",{view:this},this.updateModelOnSort),e(window).on("beforeunload",{view:this},this.unloadConfirmation),e(document.body).on("click",".wc-shipping-zone-add",{view:this},this.onAddNewRow)},onAddNewRow:function(){var n=e(this);window.location.href=n.attr("href")},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},render:function(){var n=_.indexBy(this.model.get("zones"),"zone_id"),i=this;i.$el.empty(),i.unblock(),_.size(n)?(n=_(n).chain().sortBy(function(e){return parseInt(e.zone_id,10)}).sortBy(function(e){return parseInt(e.zone_order,10)}).value(),e.each(n,function(e,n){i.renderRow(n)})):i.$el.append(r),i.initRows()},renderRow:function(e){this.$el.append(this.rowTemplate(e)),this.initRow(e)},initRow:function(e){var n=this.$el.find('tr[data-id="'+e.zone_id+'"]');this.renderShippingMethods(e.zone_id,e.shipping_methods),n.find(".wc-shipping-zone-delete").on("click",{view:this},this.onDeleteRow)},initRows:function(){0==e("tbody.wc-shipping-zone-rows tr").length%2?t.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").addClass("odd"):t.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").removeClass("odd"),e("#tiptip_holder").removeAttr("style"),e("#tiptip_arrow").removeAttr("style"),e(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},renderShippingMethods:function(i,o){var t=e('.wc-shipping-zones tr[data-id="'+i+'"]').find(".wc-shipping-zone-methods ul");t.find(".wc-shipping-zone-method").remove(),_.size(o)?(o=_.sortBy(o,function(e){return parseInt(e.method_order,10)}),_.each(o,function(e){var n="method_disabled";"yes"===e.enabled&&(n="method_enabled"),t.append('<li class="wc-shipping-zone-method '+n+'">'+e.title+"</li>")})):t.append('<li class="wc-shipping-zone-method">'+n.strings.no_shipping_methods_offered+"</li>")},onDeleteRow:function(i){var o=i.data.view.model,t=_.indexBy(o.get("zones"),"zone_id"),s={},d=e(this).closest("tr").data("id");i.preventDefault(),window.confirm(n.strings.delete_confirmation_msg)&&t[d]&&(delete t[d],s[d]=_.extend(s[d]||{},{deleted:"deleted"}),o.set("zones",t),o.logChanges(s),i.data.view.block(),i.data.view.model.save())},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,d.prop("disabled",!1)},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,d.prop("disabled",!0)},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=n.strings.unload_confirmation_msg,window.event.returnValue=n.strings.unload_confirmation_msg,n.strings.unload_confirmation_msg},updateModelOnChange:function(n){var i=n.data.view.model,o=e(n.target),t=o.closest("tr").data("id"),s=o.data("attribute"),d=o.val(),a=_.indexBy(i.get("zones"),"zone_id"),r={};a[t]&&a[t][s]===d||(r[t]={},r[t][s]=d),i.logChanges(r)},updateModelOnSort:function(n){var i=n.data.view.model,o=_.indexBy(i.get("zones"),"zone_id"),t=e("tbody.wc-shipping-zone-rows tr"),s={};_.each(t,function(n){var i=e(n).data("id"),t=null,d=parseInt(e(n).index(),10);o[i]&&(t=parseInt(o[i].zone_order,10)),t!==d&&(s[i]=_.extend(s[i]||{},{zone_order:d}))}),_.size(s)&&(i.logChanges(s),n.data.view.block(),n.data.view.model.save())}}),h=new l({zones:n.zones}),p=new c({model:h,el:s});p.render(),s.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-sort",scrollSensitivity:40})})}(jQuery,shippingZonesLocalizeScript,wp,ajaxurl);
|
||||
!function(e,n,i,o){e(function(){e(".wc-shipping-zones");var t=e(".wc-shipping-zone-rows"),s=e(".wc-shipping-zone-save"),a=i.template("wc-shipping-zone-row"),d=i.template("wc-shipping-zone-row-blank"),r=Backbone.Model.extend({changes:{},logChanges:function(e){var n=this.changes||{};_.each(e,function(e,i){n[i]=_.extend(n[i]||{zone_id:i},e)}),this.changes=n,this.trigger("change:zones")},discardChanges:function(e){var n=this.changes||{},i=null,o=_.indexBy(this.get("zones"),"zone_id");n[e]&&n[e].zone_order!==undefined&&(i=n[e].zone_order),delete n[e],null!==i&&o[e]&&o[e].zone_order!==i&&(n[e]=_.extend(n[e]||{},{zone_id:e,zone_order:i})),this.changes=n,0===_.size(this.changes)&&h.clearUnloadConfirmation()},save:function(){_.size(this.changes)?e.post(o+(o.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zones_save_changes",{wc_shipping_zones_nonce:n.wc_shipping_zones_nonce,changes:this.changes},this.onSaveResponse,"json"):c.trigger("saved:zones")},onSaveResponse:function(e,i){"success"===i&&(e.success?(c.set("zones",e.data.zones),c.trigger("change:zones"),c.changes={},c.trigger("saved:zones")):window.alert(n.strings.save_failed))}}),l=Backbone.View.extend({rowTemplate:a,initialize:function(){this.listenTo(this.model,"change:zones",this.setUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.render),t.on("change",{view:this},this.updateModelOnChange),t.on("sortupdate",{view:this},this.updateModelOnSort),e(window).on("beforeunload",{view:this},this.unloadConfirmation),e(document.body).on("click",".wc-shipping-zone-add",{view:this},this.onAddNewRow)},onAddNewRow:function(){var n=e(this);window.location.href=n.attr("href")},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},render:function(){var n=_.indexBy(this.model.get("zones"),"zone_id"),i=this;i.$el.empty(),i.unblock(),_.size(n)?(n=_(n).chain().sortBy(function(e){return parseInt(e.zone_id,10)}).sortBy(function(e){return parseInt(e.zone_order,10)}).value(),e.each(n,function(e,n){i.renderRow(n)})):i.$el.append(d),i.initRows()},renderRow:function(e){this.$el.append(this.rowTemplate(e)),this.initRow(e)},initRow:function(e){var n=this.$el.find('tr[data-id="'+e.zone_id+'"]');this.renderShippingMethods(e.zone_id,e.shipping_methods),n.find(".wc-shipping-zone-delete").on("click",{view:this},this.onDeleteRow)},initRows:function(){const n=0!=e("tbody.wc-shipping-zone-rows tr").length%2,i=e("tfoot.wc-shipping-zone-rows-tfoot");n?i.find("tr").addClass("even"):i.find("tr").removeClass("even"),e("#tiptip_holder").removeAttr("style"),e("#tiptip_arrow").removeAttr("style"),e(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},renderShippingMethods:function(i,o){var t=e('.wc-shipping-zones tr[data-id="'+i+'"]').find(".wc-shipping-zone-methods ul");t.find(".wc-shipping-zone-method").remove(),_.size(o)?(o=_.sortBy(o,function(e){return parseInt(e.method_order,10)}),_.each(o,function(e){var n="method_disabled";"yes"===e.enabled&&(n="method_enabled"),t.append('<li class="wc-shipping-zone-method '+n+'">'+e.title+"</li>")})):t.append('<li class="wc-shipping-zone-method">'+n.strings.no_shipping_methods_offered+"</li>")},onDeleteRow:function(i){var o=i.data.view.model,t=_.indexBy(o.get("zones"),"zone_id"),s={},a=e(this).closest("tr").data("id");i.preventDefault(),window.confirm(n.strings.delete_confirmation_msg)&&t[a]&&(delete t[a],s[a]=_.extend(s[a]||{},{deleted:"deleted"}),o.set("zones",t),o.logChanges(s),i.data.view.block(),i.data.view.model.save())},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,s.prop("disabled",!1)},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,s.prop("disabled",!0)},unloadConfirmation:function(e){if(e.data.view.needsUnloadConfirm)return e.returnValue=n.strings.unload_confirmation_msg,window.event.returnValue=n.strings.unload_confirmation_msg,n.strings.unload_confirmation_msg},updateModelOnChange:function(n){var i=n.data.view.model,o=e(n.target),t=o.closest("tr").data("id"),s=o.data("attribute"),a=o.val(),d=_.indexBy(i.get("zones"),"zone_id"),r={};d[t]&&d[t][s]===a||(r[t]={},r[t][s]=a),i.logChanges(r)},updateModelOnSort:function(n){var i=n.data.view.model,o=_.indexBy(i.get("zones"),"zone_id"),t=e("tbody.wc-shipping-zone-rows tr"),s={};_.each(t,function(n){var i=e(n).data("id"),t=null,a=parseInt(e(n).index(),10);o[i]&&(t=parseInt(o[i].zone_order,10)),t!==a&&(s[i]=_.extend(s[i]||{},{zone_order:a}))}),_.size(s)&&(i.logChanges(s),n.data.view.block(),n.data.view.model.save())}}),c=new r({zones:n.zones}),h=new l({model:c,el:t});h.render(),t.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-sort",scrollSensitivity:40})})}(jQuery,shippingZonesLocalizeScript,wp,ajaxurl);
|
||||
Reference in New Issue
Block a user