From 7044243aa297352514aa8ed7f9fb717b7acfd994 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 9 Aug 2016 01:13:08 +0000 Subject: [PATCH] Updates: Improve experience for Bulk Actions when FTP is dismissed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, when a bulk update was canceled due dismissing the FTP credentials modal, part of the actions didn't get canceled. This meant the "There is a new version of…” notices become blank and the updates you had checked became unchecked. Now, the notices remain and you are essentially returned to the screen you had before. Strings are also updated to improve ARIA usage. Fixes #37563. Props ocean90, swissspidy, obenland, afercia. git-svn-id: https://develop.svn.wordpress.org/trunk@38221 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-plugin-install-list-table.php | 7 ++-- src/wp-admin/js/updates.js | 36 ++++++++++++------- src/wp-includes/script-loader.php | 4 ++- tests/qunit/fixtures/updates.js | 2 ++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugin-install-list-table.php b/src/wp-admin/includes/class-wp-plugin-install-list-table.php index 99aad1210b..6e389b1a2e 100644 --- a/src/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/src/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -476,6 +476,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { $action_links[] = ''; } elseif ( current_user_can( 'activate_plugins' ) ) { $button_text = __( 'Activate' ); + /* translators: %s: Plugin name */ + $button_label = _x( 'Activate %s', 'plugin' ); $activate_url = add_query_arg( array( '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ), 'action' => 'activate', @@ -484,14 +486,15 @@ class WP_Plugin_Install_List_Table extends WP_List_Table { if ( is_network_admin() ) { $button_text = __( 'Network Activate' ); + /* translators: %s: Plugin name */ + $button_label = _x( 'Network Activate %s', 'plugin' ); $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url ); } $action_links[] = sprintf( '%3$s', esc_url( $activate_url ), - /* translators: %s: Plugin name */ - esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin['name'] ) ), + esc_attr( sprintf( $button_label, $plugin['name'] ) ), $button_text ); } else { diff --git a/src/wp-admin/js/updates.js b/src/wp-admin/js/updates.js index 688ddb1f05..9c932056e9 100644 --- a/src/wp-admin/js/updates.js +++ b/src/wp-admin/js/updates.js @@ -523,11 +523,14 @@ $message = $( '[data-slug="' + args.slug + '"]' ); } - $message.text( wp.updates.l10n.installing ); + if ( $message.html() !== wp.updates.l10n.installing ) { + $message.data( 'originaltext', $message.html() ); + } $message .addClass( 'updating-message' ) - .attr( 'aria-label', wp.updates.l10n.pluginInstallingLabel.replace( '%s', $message.data( 'name' ) ) ); + .attr( 'aria-label', wp.updates.l10n.pluginInstallingLabel.replace( '%s', $message.data( 'name' ) ) ) + .text( wp.updates.l10n.installing ); wp.a11y.speak( wp.updates.l10n.installingMsg, 'polite' ); @@ -1505,7 +1508,7 @@ // Restore callbacks. response = wp.updates._addCallbacks( response, action ); - wp.updates.queue.push( { + wp.updates.queue.unshift( { action: action, /* @@ -1708,13 +1711,11 @@ $updatingMessage.removeClass( 'updating-message' ); } else if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { $message = $( 'tr[data-plugin="' + job.data.plugin + '"]' ).find( '.update-message' ); - } else if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) { - $message = $( '.update-now.updating-message' ); } else { $message = $updatingMessage; } - if ( $message ) { + if ( $message && $message.hasClass( 'updating-message' ) ) { originalText = $message.data( 'originaltext' ); if ( 'undefined' === typeof originalText ) { @@ -1724,6 +1725,14 @@ $message .removeClass( 'updating-message' ) .html( originalText ); + + if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) { + if ( 'update-plugin' === job.action ) { + $message.attr( 'aria-label', wp.updates.l10n.updateNowLabel.replace( '%s', $message.data( 'name' ) ) ); + } else if ( 'install-plugin' === job.action ) { + $message.attr( 'aria-label', wp.updates.l10n.installNowLabel.replace( '%s', $message.data( 'name' ) ) ); + } + } } wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' ); @@ -1999,14 +2008,14 @@ // Find all the checkboxes which have been checked. itemsSelected.each( function( index, element ) { - var $checkbox = $( element ), + var $checkbox = $( element ), $itemRow = $checkbox.parents( 'tr' ); - // Un-check the box. - $checkbox.prop( 'checked', false ); - // Only add update-able items to the update queue. if ( 'update-selected' === bulkAction && ( ! $itemRow.hasClass( 'update' ) || $itemRow.find( 'notice-error' ).length ) ) { + + // Un-check the box. + $checkbox.prop( 'checked', false ); return; } @@ -2022,17 +2031,20 @@ // Display bulk notification for updates of any kind. $document.on( 'wp-plugin-update-success wp-plugin-update-error wp-theme-update-success wp-theme-update-error', function( event, response ) { - var $bulkActionNotice, itemName; + var $itemRow = $( '[data-slug="' + response.slug + '"]' ), + $bulkActionNotice, itemName; if ( 'wp-' + response.update + '-update-success' === event.type ) { success++; } else { - itemName = response.pluginName ? response.pluginName : $( '[data-slug="' + response.slug + '"]' ).find( '.column-primary strong' ).text(); + itemName = response.pluginName ? response.pluginName : $itemRow.find( '.column-primary strong' ).text(); error++; errorMessages.push( itemName + ': ' + response.errorMessage ); } + $itemRow.find( 'input[name="checked[]"]:checked' ).prop( 'checked', false ); + wp.updates.adminNotice = wp.template( 'wp-bulk-updates-admin-notice' ); wp.updates.addAdminNotice( { diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 3a1ec18e7b..b2008230b7 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -616,6 +616,8 @@ function wp_default_scripts( &$scripts ) { 'updated' => __( 'Updated!' ), 'update' => __( 'Update' ), 'updateNow' => __( 'Update Now' ), + /* translators: %s: Plugin name and version */ + 'updateNowLabel' => __( 'Update %s now' ), 'updateFailedShort' => __( 'Update Failed!' ), /* translators: %s: Error string for a failed update */ 'updateFailed' => __( 'Update Failed: %s' ), @@ -634,7 +636,7 @@ function wp_default_scripts( &$scripts ) { 'beforeunload' => __( 'Updates may not complete if you navigate away from this page.' ), 'installNow' => __( 'Install Now' ), /* translators: %s: Plugin name */ - 'installNowLabel' => __( 'Install %s' ), + 'installNowLabel' => __( 'Install %s now' ), 'installing' => __( 'Installing...' ), 'installed' => __( 'Installed!' ), 'installFailedShort' => __( 'Install Failed!' ), diff --git a/tests/qunit/fixtures/updates.js b/tests/qunit/fixtures/updates.js index 013536c2b5..1d318d89b6 100644 --- a/tests/qunit/fixtures/updates.js +++ b/tests/qunit/fixtures/updates.js @@ -9,6 +9,7 @@ window._wpUpdatesSettings = { 'updated': 'Updated!', 'update': 'Update', 'updateNow': 'Update Now', + 'updateNowLabel': 'Update %s now', 'updateFailedShort': 'Update Failed!', 'updateFailed': 'Update Failed: %s', 'updatingLabel': 'Updating %s...', @@ -19,6 +20,7 @@ window._wpUpdatesSettings = { 'updateCancel': 'Update canceled.', 'beforeunload': 'Updates may not complete if you navigate away from this page.', 'installNow': 'Install Now', + 'installNowLabel': 'Install %s now', 'installing': 'Installing...', 'installed': 'Installed!', 'installFailedShort': 'Install Failed!',