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:
Weston Ruter 2016-05-02 19:13:26 +00:00
parent aba14233d9
commit a0d7e83beb
3 changed files with 25 additions and 6 deletions

View File

@ -3327,10 +3327,16 @@
var self = this, var self = this,
processing = api.state( 'processing' ), processing = api.state( 'processing' ),
submitWhenDoneProcessing, submitWhenDoneProcessing,
submit; submit,
modifiedWhileSaving = {};
body.addClass( 'saving' ); body.addClass( 'saving' );
function captureSettingModifiedDuringSave( setting ) {
modifiedWhileSaving[ setting.id ] = true;
}
api.bind( 'change', captureSettingModifiedDuringSave );
submit = function () { submit = function () {
var request, query; var request, query;
query = $.extend( self.query(), { query = $.extend( self.query(), {
@ -3338,10 +3344,15 @@
} ); } );
request = wp.ajax.post( 'customize_save', query ); request = wp.ajax.post( 'customize_save', query );
// Disable save button during the save request.
saveBtn.prop( 'disabled', true );
api.trigger( 'save', request ); api.trigger( 'save', request );
request.always( function () { request.always( function () {
body.removeClass( 'saving' ); body.removeClass( 'saving' );
saveBtn.prop( 'disabled', false );
api.unbind( 'change', captureSettingModifiedDuringSave );
} ); } );
request.fail( function ( response ) { request.fail( function ( response ) {
@ -3365,14 +3376,22 @@
} ); } );
request.done( function( response ) { request.done( function( response ) {
// Clear setting dirty states
api.each( function ( value ) { // Clear setting dirty states, if setting wasn't modified while saving.
value._dirty = false; api.each( function( setting ) {
if ( ! modifiedWhileSaving[ setting.id ] ) {
setting._dirty = false;
}
} ); } );
api.previewer.send( 'saved', response ); api.previewer.send( 'saved', response );
api.trigger( '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 );
}
} ); } );
}; };

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.6-alpha-37345'; $wp_version = '4.6-alpha-37346';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.