Make WordPress Core

Changeset 37346


Ignore:
Timestamp:
05/02/2016 07:12:37 PM (10 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-controls.js

    r37339 r37346  
    33283328                                        processing = api.state( 'processing' ),
    33293329                                        submitWhenDoneProcessing,
    3330                                         submit;
     3330                                        submit,
     3331                                        modifiedWhileSaving = {};
    33313332
    33323333                                body.addClass( 'saving' );
     3334
     3335                                function captureSettingModifiedDuringSave( setting ) {
     3336                                        modifiedWhileSaving[ setting.id ] = true;
     3337                                }
     3338                                api.bind( 'change', captureSettingModifiedDuringSave );
    33333339
    33343340                                submit = function () {
    … …  
    33393345                                        request = wp.ajax.post( 'customize_save', query );
    33403346
     3347                                        // Disable save button during the save request.
     3348                                        saveBtn.prop( 'disabled', true );
     3349
    33413350                                        api.trigger( 'save', request );
    33423351
    33433352                                        request.always( function () {
    33443353                                                body.removeClass( 'saving' );
     3354                                                saveBtn.prop( 'disabled', false );
     3355                                                api.unbind( 'change', captureSettingModifiedDuringSave );
    33453356                                        } );
    33463357
    … …  
    33663377
    33673378                                        request.done( function( response ) {
    3368                                                 // Clear setting dirty states
    3369                                                 api.each( function ( value ) {
    3370                                                         value._dirty = false;
     3379
     3380                                                // Clear setting dirty states, if setting wasn't modified while saving.
     3381                                                api.each( function( setting ) {
     3382                                                        if ( ! modifiedWhileSaving[ setting.id ] ) {
     3383                                                                setting._dirty = false;
     3384                                                        }
    33713385                                                } );
    33723386
    … …  
    33743388
    33753389                                                api.trigger( 'saved', response );
     3390
     3391                                                // Restore the global dirty state if any settings were modified during save.
     3392                                                if ( ! _.isEmpty( modifiedWhileSaving ) ) {
     3393                                                        api.state( 'saved' ).set( false );
     3394                                                }
    33763395                                        } );
    33773396                                };
Note: See TracChangeset for help on using the changeset viewer.