]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/updates.js
WordPress 4.4
[autoinstalls/wordpress.git] / wp-admin / js / updates.js
index 6574a3cc846aba157f10d9981939a880b8cc2359..3f1dba71e3aad2751aa5e7948a73981e631c1ad2 100644 (file)
@@ -93,7 +93,7 @@ window.wp = window.wp || {};
         *
         * @since 3.9.0
         *
-        * @param {string} updateType
+        * @param {string} upgradeType
         */
        wp.updates.decrementCount = function( upgradeType ) {
                var count,
@@ -146,13 +146,17 @@ window.wp = window.wp || {};
         * @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' );
                } 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' );
@@ -248,25 +252,57 @@ window.wp = window.wp || {};
         * @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' ) {
+
+               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.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.text( wp.updates.l10n.updateFailed );
-               wp.a11y.speak( wp.updates.l10n.updateFailed );
+
+               wp.a11y.speak( error_message, 'assertive' );
+
+               /*
+                * The lock can be released since this failure was
+                * after the credentials form.
+                */
+               wp.updates.updateLock = false;
 
                $(document).trigger( 'wp-plugin-update-error', response );
+
+               wp.updates.queueChecker();
        };
 
        /**
@@ -467,6 +503,11 @@ window.wp = window.wp || {};
                        wp.updates.requestForCredentialsModalCancel();
                });
 
+               // Hide SSH fields when not selected
+               $( '#request-filesystem-credentials-dialog input[name="connection_type"]' ).on( 'change', function() {
+                       $( this ).parents( 'form' ).find( '#private_key, #public_key' ).parents( 'label' ).toggle( ( 'ssh' == $( this ).val() ) );
+               }).change();
+
                // Click handler for plugin updates in List Table view.
                $( '.plugin-update-tr' ).on( 'click', '.update-link', function( e ) {
                        e.preventDefault();
@@ -490,7 +531,6 @@ window.wp = window.wp || {};
                        wp.updates.updatePlugin( $button.data( 'plugin' ), $button.data( 'slug' ) );
                } );
 
-               //
                $( '#plugin_update_from_iframe' ).on( 'click' , function( e ) {
                        var target,     data;
 
@@ -540,7 +580,7 @@ window.wp = window.wp || {};
                                        // 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( '.column-name a' ).focus();
                                        $( '.plugin-card-' + message.slug ).find( '[data-slug="' + message.slug + '"]' ).trigger( 'click' );
                                }
                                break;