From a216627419c95c1620b465264196e6665613965c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 2 May 2016 19:12:37 +0000 Subject: [PATCH] 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 --- src/wp-admin/js/customize-controls.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index d5f2a0fb04..1e134bd9ad 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -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 ); + } } ); };