Ticket #1199: 1199.diff
File 1199.diff, 7.7 KB (added by , 9 years ago) |
---|
-
inc/parsed-content.php
122 122 <a href="#detach-ticket" class="button secondary <?php echo $ticket ? '' : 'hidden'; ?>" id="wporg_ticket_detach" name="wporg_ticket_detach" aria-label="<?php esc_attr_e( 'Detach the Trac ticket', 'wporg' ); ?>" data-nonce="<?php echo wp_create_nonce( 'wporg-detach-ticket' ); ?>" data-id="<?php the_ID(); ?>"> 123 123 <?php esc_attr_e( 'Detach Ticket', 'wporg' ); ?> 124 124 </a> 125 <span class="spinner"></span> 125 126 </span> 126 127 <div id="ticket_status"> 127 <span class="spinner"></span>128 128 <span class="ticket_info_icon <?php echo $ticket ? 'dashicons dashicons-external' : ''; ?>"></span> 129 129 <span id="wporg_ticket_info"><em><?php echo $ticket_message; ?></em></span> 130 130 </div> … … 166 166 wp_enqueue_style( 'wporg-admin', get_template_directory_uri() . '/stylesheets/admin.css', array(), '20140826' ); 167 167 wp_enqueue_script( 'wporg-parsed-content', get_template_directory_uri() . '/js/parsed-content.js', array( 'jquery', 'utils' ), '20140826', true ); 168 168 169 wp_localize_script( 'wporg-parsed-content', 'wporg ', array(169 wp_localize_script( 'wporg-parsed-content', 'wporgParsedContent', array( 170 170 'ajaxURL' => admin_url( 'admin-ajax.php' ), 171 171 'searchText' => __( 'Searching ...', 'wporg' ), 172 'retryText' => __( 'Invalid ticket number, please try again.', 'wporg' ) 172 173 ) ); 173 174 } 174 175 } … … 215 216 $link = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $ticket_url ), apply_filters( 'the_title', $title ) ); 216 217 217 218 // 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 ) ); 222 223 223 224 } else { 224 225 // Ticket number is invalid. 225 $message =array(226 ' type' => 'invalid',227 ' message' => __( 'Invalid ticket number.', 'wporg' ),228 ) ;226 wp_send_json_error( array( 227 'message' => __( 'Invalid ticket number.', 'wporg' ), 228 'new_nonce' => wp_create_nonce( 'wporg-attach-ticket' ) 229 ) ); 229 230 } 230 231 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 ) ); 232 die( 0 ); 235 233 } 236 234 237 235 /** … … 248 246 if ( delete_post_meta( $post_id, 'wporg_ticket_number' ) 249 247 && delete_post_meta( $post_id, 'wporg_ticket_title' ) 250 248 ) { 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 255 255 } else { 256 256 // Still attached. 257 $message =array(258 ' type' => 'failure',259 ' message' => __( 'Ticket still attached.', 'wporg' )260 ) ;257 wp_send_json_error( array( 258 'message' => __( 'Ticket still attached.', 'wporg' ), 259 'new_nonce' => wp_create_nonce( 'wporg-detach-ticket' ) 260 ) ); 261 261 } 262 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 ) ); 263 die( 0 ); 267 264 } 268 265 269 266 } // WPORG_Edit_Parsed_Content -
js/parsed-content.js
7 7 attachButton = $( '#wporg_ticket_attach' ), 8 8 detachButton = $( '#wporg_ticket_detach' ), 9 9 ticketInfo = $( '#wporg_ticket_info' ), 10 spinner = $( ' #ticket_status .spinner' );10 spinner = $( '.attachment_controls .spinner' ); 11 11 12 12 var handleTicket = function( event ) { 13 13 event.preventDefault(); … … 15 15 var $this = $(this), 16 16 attachAction = 'attach' == event.data.action; 17 17 18 spinner. css( 'display', 'inline-block' );18 spinner.addClass( 'is-active' ); 19 19 20 // Searching ... text. 20 21 if ( attachAction ) { 21 ticketInfo.text( wporg .searchText );22 ticketInfo.text( wporgParsedContent.searchText ); 22 23 } 23 24 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', { 26 26 ticket: ticketNumber.val(), 27 27 nonce: $this.data( 'nonce' ), 28 28 post_id: $this.data( 'id' ) 29 } ;29 } ); 30 30 31 $.post( wporg.ajaxURL, data, function( resp ) { 31 // Success. 32 request.done( function( response ) { 32 33 // Refresh the nonce. 33 $this.data( 'nonce', resp .new_nonce );34 $this.data( 'nonce', response.new_nonce ); 34 35 35 spinner.hide(); 36 // Hide or show the parsed content boxes. 37 $( '.wporg_parsed_content' ).each( function() { 38 attachAction ? $(this).show() : $(this).hide(); 39 }); 36 40 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 }); 39 44 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; 46 46 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' ); 50 50 51 var otherButton = attachAction ? detachButton : attachButton; 51 // Update the ticket info text. 52 ticketInfo.html( response.message ).show(); 52 53 53 // Toggle the buttons. 54 $this.hide(); 55 otherButton.css( 'display', 'inline-block' ); 54 // Clear the ticket number when detaching. 55 if ( ! attachAction ) { 56 ticketNumber.val( '' ); 57 } 56 58 57 // Clear the ticket number when detaching. 58 if ( ! attachAction ) { 59 ticketNumber.val( '' ); 60 } 59 spinner.removeClass( 'is-active' ); 61 60 62 63 61 // Set or unset the ticket link icon. 62 $( '.ticket_info_icon' ).toggleClass( 'dashicons dashicons-external', attachAction ); 64 63 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 ); 69 } 64 // Set the ticket number to readonly when a ticket is attached. 65 attachAction ? ticketNumber.prop( 'readonly', 'readonly' ) : ticketNumber.removeAttr( 'readonly' ); 66 } ); 70 67 71 }, 'json' ); 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 } ); 72 78 }; 73 79 74 80 attachButton.on( 'click', { action: 'attach' }, handleTicket ); -
scss/admin.scss
10 10 color: #a00; 11 11 } 12 12 13 #ticket_status .spinner {13 .attachment_controls .spinner { 14 14 position: relative; 15 margin-top: 3px; 15 16 bottom: 4px; 16 17 float: none; 17 18 } -
stylesheets/admin.css
9 9 color: #a00; 10 10 } 11 11 12 #ticket_status .spinner {12 .attachment_controls .spinner { 13 13 position: relative; 14 margin-top: 3px; 14 15 bottom: 4px; 15 16 float: none; 16 17 }