*
* @since 3.9.0
*
- * @param {string} updateType
+ * @param {string} upgradeType
*/
wp.updates.decrementCount = function( upgradeType ) {
var count,
* @param {string} slug
*/
wp.updates.updatePlugin = function( plugin, slug ) {
- var $message, name;
+ var $message, name,
+ $card = $( '.plugin-card-' + slug );
+
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
- $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
+ $message = $( '[data-plugin="' + plugin + '"]' ).next().find( '.update-message' );
} else if ( 'plugin-install' === pagenow ) {
- $message = $( '.plugin-card-' + slug ).find( '.update-now' );
+ $message = $card.find( '.update-now' );
name = $message.data( 'name' );
$message.attr( 'aria-label', wp.updates.l10n.updatingLabel.replace( '%s', name ) );
+ // Remove previous error messages, if any.
+ $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove();
}
$message.addClass( 'updating-message' );
wp.updates.updateSuccess = function( response ) {
var $updateMessage, name, $pluginRow, newText;
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
- $pluginRow = $( '[data-slug="' + response.slug + '"]' ).first();
+ $pluginRow = $( '[data-plugin="' + response.plugin + '"]' ).first();
$updateMessage = $pluginRow.next().find( '.update-message' );
$pluginRow.addClass( 'updated' ).removeClass( 'update' );
* @param {object} response
*/
wp.updates.updateError = function( response ) {
- var $message, name;
+ var $card = $( '.plugin-card-' + response.slug ),
+ $message,
+ $button,
+ name,
+ error_message;
+
wp.updates.updateDoneSuccessfully = false;
+
if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' && wp.updates.shouldRequestFilesystemCredentials ) {
wp.updates.credentialError( response, 'update-plugin' );
return;
}
+
+ error_message = wp.updates.l10n.updateFailed.replace( '%s', response.error );
+
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
- $message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' );
+ $message = $( '[data-plugin="' + response.plugin + '"]' ).next().find( '.update-message' );
+ $message.html( error_message ).removeClass( 'updating-message' );
} else if ( 'plugin-install' === pagenow ) {
- $message = $( '.plugin-card-' + response.slug ).find( '.update-now' );
-
- name = $message.data( 'name' );
- $message.attr( 'aria-label', wp.updates.l10n.updateFailedLabel.replace( '%s', name ) );
+ $button = $card.find( '.update-now' );
+ name = $button.data( 'name' );
+
+ $card
+ .addClass( 'plugin-card-update-failed' )
+ .append( '<div class="notice notice-error is-dismissible"><p>' + error_message + '</p></div>' );
+
+ $button
+ .attr( 'aria-label', wp.updates.l10n.updateFailedLabel.replace( '%s', name ) )
+ .html( wp.updates.l10n.updateFailedShort ).removeClass( 'updating-message' );
+
+ $card.on( 'click', '.notice.is-dismissible .notice-dismiss', function() {
+ // Use same delay as the total duration of the notice fadeTo + slideUp animation.
+ setTimeout( function() {
+ $card
+ .removeClass( 'plugin-card-update-failed' )
+ .find( '.column-name a' ).focus();
+ }, 200 );
+ });
}
- $message.removeClass( 'updating-message' );
- $message.html( wp.updates.l10n.updateFailed.replace( '%s', response.error ) );
- wp.a11y.speak( wp.updates.l10n.updateFailed );
+
+ wp.a11y.speak( error_message, 'assertive' );
/*
* The lock can be released since this failure was
*/
wp.updates.requestForCredentialsModalCancel = function() {
// no updateLock and no updateQueue means we already have cleared things up
- var slug, $message;
+ var data, $message;
if( wp.updates.updateLock === false && wp.updates.updateQueue.length === 0 ){
return;
}
- slug = wp.updates.updateQueue[0].data.slug,
+ data = wp.updates.updateQueue[0].data;
// remove the lock, and clear the queue
wp.updates.updateLock = false;
wp.updates.requestForCredentialsModalClose();
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
- $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
+ $message = $( '[data-plugin="' + data.plugin + '"]' ).next().find( '.update-message' );
} else if ( 'plugin-install' === pagenow ) {
- $message = $( '.plugin-card-' + slug ).find( '.update-now' );
+ $message = $( '.plugin-card-' + data.slug ).find( '.update-now' );
}
$message.removeClass( 'updating-message' );
}
var updateRow = $( e.target ).parents( '.plugin-update-tr' );
// Return the user to the input box of the plugin's table row after closing the modal.
- wp.updates.$elToReturnFocusToFromCredentialsModal = $( '#' + updateRow.data( 'slug' ) ).find( '.check-column input' );
+ wp.updates.$elToReturnFocusToFromCredentialsModal = updateRow.prev().find( '.check-column input' );
wp.updates.updatePlugin( updateRow.data( 'plugin' ), updateRow.data( 'slug' ) );
} );
e.preventDefault();
var $button = $( e.target );
+ // Do nothing while updating and when the button is disabled.
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
+ return;
+ }
+
if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
wp.updates.requestFilesystemCredentials( e );
}
} );
$( '#plugin_update_from_iframe' ).on( 'click' , function( e ) {
- var target, data;
+ var target, job;
target = window.parent == window ? null : window.parent,
$.support.postMessage = !! window.postMessage;
e.preventDefault();
- data = {
- 'action' : 'updatePlugin',
- 'slug' : $(this).data('slug')
+ job = {
+ action: 'updatePlugin',
+ type: 'update-plugin',
+ data: {
+ plugin: $( this ).data( 'plugin' ),
+ slug: $( this ).data( 'slug' )
+ }
};
- target.postMessage( JSON.stringify( data ), window.location.origin );
+ target.postMessage( JSON.stringify( job ), window.location.origin );
});
} );
break;
case 'updatePlugin' :
tb_remove();
- if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
- // Return the user to the input box of the plugin's table row after closing the modal.
- $( '#' + message.slug ).find( '.check-column input' ).focus();
- // trigger the update
- $( '.plugin-update-tr[data-slug="' + message.slug + '"]' ).find( '.update-link' ).trigger( 'click' );
- } else if ( 'plugin-install' === pagenow ) {
- $( '.plugin-card-' + message.slug ).find( 'h4 a' ).focus();
- $( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
- }
+
+ wp.updates.updateQueue.push( message );
+ wp.updates.queueChecker();
break;
}