Plugins and Themes Auto-Updates: update the state of the auto-update link on the themes screen after successfully saving the setting.

Props desrosj, pbiron, azaozz.
Fixes #50291.

git-svn-id: https://develop.svn.wordpress.org/trunk@47883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2020-06-01 20:51:10 +00:00
parent 2fed7bf581
commit 5263a96a4c
2 changed files with 21 additions and 1 deletions

View File

@ -666,7 +666,8 @@ themes.view.Details = wp.Backbone.View.extend({
'click .delete-theme': 'deleteTheme',
'click .left': 'previousTheme',
'click .right': 'nextTheme',
'click #update-theme': 'updateTheme'
'click #update-theme': 'updateTheme',
'click .toggle-auto-update': 'autoupdateState'
},
// The HTML template for the theme overlay.
@ -787,6 +788,23 @@ themes.view.Details = wp.Backbone.View.extend({
this.trigger( 'theme:collapse' );
},
// Set state of the auto-update settings link after it has been changed and saved.
autoupdateState: function() {
var callback,
_this = this;
// Support concurrent clicks in different Theme Details overlays.
callback = function( event, data ) {
if ( _this.model.get( 'id' ) === data.asset ) {
_this.model.set( { autoupdate: 'enable' === data.state } );
$( document ).off( 'wp-auto-update-setting-changed', callback );
}
}
// Triggered in updates.js
$( document ).on( 'wp-auto-update-setting-changed', callback );
},
updateTheme: function( event ) {
var _this = this;
event.preventDefault();

View File

@ -2599,6 +2599,8 @@
$parent.find( '.auto-update-time' ).addClass( 'hidden' );
wp.a11y.speak( wp.updates.l10n.autoUpdatesDisabled, 'polite' );
}
$document.trigger( 'wp-auto-update-setting-changed', { state: action, type: type, asset: asset } );
} )
.fail( function() {
$parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( wp.updates.l10n.autoUpdatesError );