Plugins: add dismissible notices to update failures.

Adds unit test.

Props afercia, mehulkaklotar.
Fixes #33465.

Built from https://develop.svn.wordpress.org/trunk@35681


git-svn-id: http://core.svn.wordpress.org/trunk@35645 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-11-18 20:10:26 +00:00
parent 68b8f41780
commit 8caf5d9759
10 changed files with 93 additions and 28 deletions

View File

@ -1578,6 +1578,21 @@ div.action-links,
display: inline; display: inline;
} }
.plugin-card-update-failed .update-now {
font-weight: 600;
}
.plugin-card-update-failed .notice-error {
margin: 0;
padding-right: 16px;
-webkit-box-shadow: 0 -1px 0 #dedede;
box-shadow: 0 -1px 0 #dedede;
}
.plugin-card-update-failed .plugin-card-bottom {
display: none;
}
.plugin-card .column-rating { .plugin-card .column-rating {
line-height: 23px; line-height: 23px;
} }

View File

@ -1578,6 +1578,21 @@ div.action-links,
display: inline; display: inline;
} }
.plugin-card-update-failed .update-now {
font-weight: 600;
}
.plugin-card-update-failed .notice-error {
margin: 0;
padding-left: 16px;
-webkit-box-shadow: 0 -1px 0 #dedede;
box-shadow: 0 -1px 0 #dedede;
}
.plugin-card-update-failed .plugin-card-bottom {
display: none;
}
.plugin-card .column-rating { .plugin-card .column-rating {
line-height: 23px; line-height: 23px;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -400,24 +400,29 @@ $document.ready( function() {
$( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $( '.wrap' ).children( ':header' ).first() ); $( 'div.updated, div.error, div.notice' ).not( '.inline, .below-h2' ).insertAfter( $( '.wrap' ).children( ':header' ).first() );
// Make notices dismissible // Make notices dismissible
$( '.notice.is-dismissible' ).each( function() { function makeNoticesDismissible() {
var $this = $( this ), $( '.notice.is-dismissible' ).each( function() {
$button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ), var $el = $( this ),
btnText = commonL10n.dismiss || ''; $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
btnText = commonL10n.dismiss || '';
// Ensure plain text // Ensure plain text
$button.find( '.screen-reader-text' ).text( btnText ); $button.find( '.screen-reader-text' ).text( btnText );
$button.on( 'click.wp-dismiss-notice', function( event ) {
$this.append( $button ); event.preventDefault();
$el.fadeTo( 100, 0, function() {
$button.on( 'click.wp-dismiss-notice', function( event ) { $el.slideUp( 100, function() {
event.preventDefault(); $el.remove();
$this.fadeTo( 100 , 0, function() { });
$(this).slideUp( 100, function() {
$(this).remove();
}); });
}); });
$el.append( $button );
}); });
}
$document.on( 'wp-plugin-update-error', function() {
makeNoticesDismissible();
}); });
// Init screen meta // Init screen meta
@ -895,6 +900,7 @@ $document.ready( function() {
window.wpResponsive.init(); window.wpResponsive.init();
setPinMenu(); setPinMenu();
currentMenuItemHasPopup(); currentMenuItemHasPopup();
makeNoticesDismissible();
$document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu ); $document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
}); });

File diff suppressed because one or more lines are too long

View File

@ -146,13 +146,17 @@ window.wp = window.wp || {};
* @param {string} slug * @param {string} slug
*/ */
wp.updates.updatePlugin = function( plugin, slug ) { wp.updates.updatePlugin = function( plugin, slug ) {
var $message, name; var $message, name,
$card = $( '.plugin-card-' + slug );
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
$message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' ); $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' );
} else if ( 'plugin-install' === pagenow ) { } else if ( 'plugin-install' === pagenow ) {
$message = $( '.plugin-card-' + slug ).find( '.update-now' ); $message = $card.find( '.update-now' );
name = $message.data( 'name' ); name = $message.data( 'name' );
$message.attr( 'aria-label', wp.updates.l10n.updatingLabel.replace( '%s', 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' ); $message.addClass( 'updating-message' );
@ -248,23 +252,47 @@ window.wp = window.wp || {};
* @param {object} response * @param {object} response
*/ */
wp.updates.updateError = function( response ) { wp.updates.updateError = function( response ) {
var $message, name; var $card = $( '.plugin-card-' + response.slug ),
$message,
$button,
name,
error_message;
wp.updates.updateDoneSuccessfully = false; wp.updates.updateDoneSuccessfully = false;
if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' && wp.updates.shouldRequestFilesystemCredentials ) { if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' && wp.updates.shouldRequestFilesystemCredentials ) {
wp.updates.credentialError( response, 'update-plugin' ); wp.updates.credentialError( response, 'update-plugin' );
return; return;
} }
error_message = wp.updates.l10n.updateFailed.replace( '%s', response.error );
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
$message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' ); $message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' );
$message.html( error_message ).removeClass( 'updating-message' );
} else if ( 'plugin-install' === pagenow ) { } else if ( 'plugin-install' === pagenow ) {
$message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); $button = $card.find( '.update-now' );
name = $button.data( 'name' );
name = $message.data( 'name' ); $card
$message.attr( 'aria-label', wp.updates.l10n.updateFailedLabel.replace( '%s', name ) ); .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( error_message, 'assertive' );
wp.a11y.speak( wp.updates.l10n.updateFailed );
/* /*
* The lock can be released since this failure was * The lock can be released since this failure was

File diff suppressed because one or more lines are too long

View File

@ -583,6 +583,7 @@ function wp_default_scripts( &$scripts ) {
'l10n' => array( 'l10n' => array(
'updating' => __( 'Updating...' ), // no ellipsis 'updating' => __( 'Updating...' ), // no ellipsis
'updated' => __( 'Updated!' ), 'updated' => __( 'Updated!' ),
'updateFailedShort' => __( 'Update Failed!' ),
/* translators: Error string for a failed update */ /* translators: Error string for a failed update */
'updateFailed' => __( 'Update Failed: %s' ), 'updateFailed' => __( 'Update Failed: %s' ),
/* translators: Plugin name and version */ /* translators: Plugin name and version */

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-beta4-35680'; $wp_version = '4.4-beta4-35681';
/** /**
* 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.