Customize: Ensure settings modified during an open save request remain dirty when save request completes.
Also disables Save & Publish button while save request is open. After the save request completes, any settings changed during the request can then be saved via an additional click to the button. Props chandrapatel, westonruter. Fixes #32941. Built from https://develop.svn.wordpress.org/trunk@37346 git-svn-id: http://core.svn.wordpress.org/trunk@37312 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -3327,10 +3327,16 @@
|
||||
var self = this,
|
||||
processing = api.state( 'processing' ),
|
||||
submitWhenDoneProcessing,
|
||||
submit;
|
||||
submit,
|
||||
modifiedWhileSaving = {};
|
||||
|
||||
body.addClass( 'saving' );
|
||||
|
||||
function captureSettingModifiedDuringSave( setting ) {
|
||||
modifiedWhileSaving[ setting.id ] = true;
|
||||
}
|
||||
api.bind( 'change', captureSettingModifiedDuringSave );
|
||||
|
||||
submit = function () {
|
||||
var request, query;
|
||||
query = $.extend( self.query(), {
|
||||
@@ -3338,10 +3344,15 @@
|
||||
} );
|
||||
request = wp.ajax.post( 'customize_save', query );
|
||||
|
||||
// Disable save button during the save request.
|
||||
saveBtn.prop( 'disabled', true );
|
||||
|
||||
api.trigger( 'save', request );
|
||||
|
||||
request.always( function () {
|
||||
body.removeClass( 'saving' );
|
||||
saveBtn.prop( 'disabled', false );
|
||||
api.unbind( 'change', captureSettingModifiedDuringSave );
|
||||
} );
|
||||
|
||||
request.fail( function ( response ) {
|
||||
@@ -3365,14 +3376,22 @@
|
||||
} );
|
||||
|
||||
request.done( function( response ) {
|
||||
// Clear setting dirty states
|
||||
api.each( function ( value ) {
|
||||
value._dirty = false;
|
||||
|
||||
// Clear setting dirty states, if setting wasn't modified while saving.
|
||||
api.each( function( setting ) {
|
||||
if ( ! modifiedWhileSaving[ setting.id ] ) {
|
||||
setting._dirty = false;
|
||||
}
|
||||
} );
|
||||
|
||||
api.previewer.send( 'saved', response );
|
||||
|
||||
api.trigger( 'saved', response );
|
||||
|
||||
// Restore the global dirty state if any settings were modified during save.
|
||||
if ( ! _.isEmpty( modifiedWhileSaving ) ) {
|
||||
api.state( 'saved' ).set( false );
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user