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. git-svn-id: https://develop.svn.wordpress.org/trunk@37346 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
32ed4fadf2
commit
a216627419
@ -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 );
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user