Making WordPress.org

Changeset 1846


Ignore:
Timestamp:
08/24/2015 07:33:54 PM (9 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Fix attach/detach ticket flow.

Fixes #1199.
Props DrewAPicture.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/parsed-content.php

    r1063 r1846  
    123123                                <?php esc_attr_e( 'Detach Ticket', 'wporg' ); ?>
    124124                            </a>
     125                            <span class="spinner"></span>
    125126                        </span>
    126127                        <div id="ticket_status">
    127                             <span class="spinner"></span>
    128128                            <span class="ticket_info_icon <?php echo $ticket ? 'dashicons dashicons-external' : ''; ?>"></span>
    129129                            <span id="wporg_ticket_info"><em><?php echo $ticket_message; ?></em></span>
     
    167167            wp_enqueue_script( 'wporg-parsed-content', get_template_directory_uri() . '/js/parsed-content.js', array( 'jquery', 'utils' ), '20140826', true );
    168168
    169             wp_localize_script( 'wporg-parsed-content', 'wporg', array(
     169            wp_localize_script( 'wporg-parsed-content', 'wporgParsedContent', array(
    170170                'ajaxURL'    => admin_url( 'admin-ajax.php' ),
    171171                'searchText' => __( 'Searching ...', 'wporg' ),
     172                'retryText'  => __( 'Invalid ticket number, please try again.', 'wporg' )
    172173            ) );
    173174        }
     
    216217
    217218            // Can haz success.
    218             $message = array(
    219                 'type'    => 'success',
    220                 'message' => $link,
    221             );
     219            wp_send_json_success( array(
     220                'message'   => $link,
     221                'new_nonce' => wp_create_nonce( 'wporg-attach-ticket' )
     222            ) );
    222223
    223224        } else {
    224225            // Ticket number is invalid.
    225             $message = array(
    226                 'type'    => 'invalid',
    227                 'message' => __( 'Invalid ticket number.', 'wporg' ),
    228             );
    229         }
    230 
    231         // Slap on a new nonce for repeat offenders.
    232         $message['new_nonce'] = wp_create_nonce( 'wporg-attach-ticket' );
    233 
    234         die( json_encode( $message ) );
     226            wp_send_json_error( array(
     227                'message'   => __( 'Invalid ticket number.', 'wporg' ),
     228                'new_nonce' =>  wp_create_nonce( 'wporg-attach-ticket' )
     229            ) );
     230        }
     231
     232        die( 0 );
    235233    }
    236234
     
    249247            && delete_post_meta( $post_id, 'wporg_ticket_title' )
    250248        ) {
    251             $message = array(
    252                 'type'    => 'success',
    253                 'message' => __( 'Ticket detached.', 'wporg' )
    254             );
     249            // Success!
     250            wp_send_json_success( array(
     251                'message'   => __( 'Ticket detached.', 'wporg' ),
     252                'new_nonce' => wp_create_nonce( 'wporg-detach-ticket' )
     253            ) );
     254
    255255        } else {
    256256            // Still attached.
    257             $message = array(
    258                 'type'    => 'failure',
    259                 'message' => __( 'Ticket still attached.', 'wporg' )
    260             );
    261         }
    262 
    263         // Slap on a new nonce for repeat offenders.
    264         $message['new_nonce'] = wp_create_nonce( 'wporg-detach-ticket' );
    265 
    266         die( json_encode( $message ) );
     257            wp_send_json_error( array(
     258                'message'   => __( 'Ticket still attached.', 'wporg' ),
     259                'new_nonce' => wp_create_nonce( 'wporg-detach-ticket' )
     260            ) );
     261        }
     262
     263        die( 0 );
    267264    }
    268265
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/parsed-content.js

    r942 r1846  
    88        detachButton   = $( '#wporg_ticket_detach' ),
    99        ticketInfo     = $( '#wporg_ticket_info' ),
    10         spinner        = $( '#ticket_status .spinner' );
     10        spinner        = $( '.attachment_controls .spinner' );
    1111
    1212    var handleTicket = function( event ) {
     
    1616            attachAction = 'attach' == event.data.action;
    1717
    18         spinner.css( 'display', 'inline-block' );
     18        spinner.addClass( 'is-active' );
    1919
     20        // Searching ... text.
    2021        if ( attachAction ) {
    21             ticketInfo.text( wporg.searchText );
     22            ticketInfo.text( wporgParsedContent.searchText );
    2223        }
    2324
    24         var data = {
    25             action:  attachAction ? 'wporg_attach_ticket' : 'wporg_detach_ticket',
     25        var request = wp.ajax.post( attachAction ? 'wporg_attach_ticket' : 'wporg_detach_ticket', {
    2626            ticket:  ticketNumber.val(),
    2727            nonce:   $this.data( 'nonce' ),
    2828            post_id: $this.data( 'id' )
    29         };
     29        } );
    3030
    31         $.post( wporg.ajaxURL, data, function( resp ) {
     31        // Success.
     32        request.done( function( response ) {
    3233            // Refresh the nonce.
    33             $this.data( 'nonce', resp.new_nonce );
     34            $this.data( 'nonce', response.new_nonce );
    3435
    35             spinner.hide();
     36            // Hide or show the parsed content boxes.
     37            $( '.wporg_parsed_content' ).each( function() {
     38                attachAction ? $(this).show() : $(this).hide();
     39            });
    3640
    37             // Update the ticket info text
    38             ticketInfo.html( resp.message ).show();
     41            $( '.wporg_parsed_readonly' ).each( function() {
     42                attachAction ? $(this).hide() : $(this).show();
     43            });
    3944
    40             // Handle the response.
    41             if ( resp.type && 'success' == resp.type ) {
    42                 // Hide or show the parsed content boxes.
    43                 $( '.wporg_parsed_content' ).each( function() {
    44                     attachAction ? $(this).show() : $(this).hide();
    45                 });
     45            var otherButton = attachAction ? detachButton : attachButton;
    4646
    47                 $( '.wporg_parsed_readonly' ).each( function() {
    48                     attachAction ? $(this).hide() : $(this).show();
    49                 });
     47            // Toggle the buttons.
     48            $this.hide();
     49            otherButton.css( 'display', 'inline-block' );
    5050
    51                 var otherButton = attachAction ? detachButton : attachButton;
     51            // Update the ticket info text.
     52            ticketInfo.html( response.message ).show();
    5253
    53                 // Toggle the buttons.
    54                 $this.hide();
    55                 otherButton.css( 'display', 'inline-block' );
    56 
    57                 // Clear the ticket number when detaching.
    58                 if ( ! attachAction ) {
    59                     ticketNumber.val( '' );
    60                 }
    61 
    62                 // Set or unset the ticket link icon.
    63                 $( '.ticket_info_icon' ).toggleClass( 'dashicons dashicons-external', attachAction );
    64 
    65                 // Set the ticket number to readonly when a ticket is attached.
    66                 attachAction ? ticketNumber.prop( 'readonly', 'readonly' ) : ticketNumber.removeAttr( 'readonly' );
    67             } else {
    68                 ticketInfo.text( wporg.retryText );
     54            // Clear the ticket number when detaching.
     55            if ( ! attachAction ) {
     56                ticketNumber.val( '' );
    6957            }
    7058
    71         }, 'json' );
     59            spinner.removeClass( 'is-active' );
     60
     61            // Set or unset the ticket link icon.
     62            $( '.ticket_info_icon' ).toggleClass( 'dashicons dashicons-external', attachAction );
     63
     64            // Set the ticket number to readonly when a ticket is attached.
     65            attachAction ? ticketNumber.prop( 'readonly', 'readonly' ) : ticketNumber.removeAttr( 'readonly' );
     66        } );
     67
     68        // Error.
     69        request.fail( function( response ) {
     70            // Refresh the nonce.
     71            $this.data( 'nonce', response.new_nonce );
     72
     73            // Retry text.
     74            ticketInfo.text( wporgParsedContent.retryText );
     75
     76            spinner.removeClass( 'is-active' );
     77        } );
    7278    };
    7379
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/admin.scss

    r1057 r1846  
    1111}
    1212
    13 #ticket_status .spinner {
     13.attachment_controls .spinner {
    1414    position: relative;
     15    margin-top: 3px;
    1516    bottom: 4px;
    1617    float: none;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/admin.css

    r1057 r1846  
    1010}
    1111
    12 #ticket_status .spinner {
     12.attachment_controls .spinner {
    1313  position: relative;
     14  margin-top: 3px;
    1415  bottom: 4px;
    1516  float: none;
Note: See TracChangeset for help on using the changeset viewer.