Changeset 4301 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-committers.php
- Timestamp:
- 10/27/2016 06:31:28 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-committers.php
r4278 r4301 39 39 <style> 40 40 <?php // TODO: Yes, these need to be moved into the CSS somewhere. ?> 41 h3 a.addnew:before {42 content: '+';43 }44 41 ul.committer-list { 45 42 list-style: none; … … 53 50 ul.committer-list a.remove { 54 51 color: red; 52 cursor: pointer; 55 53 visibility: hidden; 56 54 } … … 59 57 } 60 58 </style> 61 <h3><?php _e( 'Committers', 'wporg-plugins' ); ?> <a href="#" class="addnew"><?php _e( 'Add', 'wporg-plugins' ); ?></button></h3> 59 60 <h3><?php _e( 'Committers', 'wporg-plugins' ); ?></h3> 62 61 63 62 <ul class="committer-list"> 64 63 <?php foreach ( $committers as $committer ) { 65 echo '<li >' .64 echo '<li data-user="' . esc_attr( $committer->user_nicename ) . '">' . 66 65 get_avatar( $committer->ID, 32 ) . 67 66 '<a href="' . esc_url( 'https://profiles.wordpress.org/' . $committer->user_nicename ) . '">' . Template::encode( $committer->display_name ) . '</a>' . 68 '<br><small>' . esc_html( $committer->user_email ) . ' ' . 69 '<a href="#" class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a>' . 67 '<br><small>' . 68 ( current_user_can( 'plugin_review' ) ? esc_html( $committer->user_email ) . ' ' : '' ) . 69 '<a class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a>' . 70 70 '</small>' . 71 71 '</li>'; 72 72 } ?> 73 <li class="new" data-template="<?php echo esc_attr( '<li><img src="" class="avatar avatar-32 photo" height="32" width="32"><a class="profile" href=""></a><br><small><span class="email"></span> <a class="remove">' . __( 'Remove', 'wporg-plugins' ) . '</a></small></li>' ); ?>"> 74 <input type="text" name="committer" placeholder="<?php esc_attr_e( 'Login, Slug, or Email.', 'wporg-plugins' ); ?>"> 75 <input type="submit" value="<?php esc_attr_e( 'Add', 'wporg-plugins' ); ?>"> 76 </li> 77 73 78 </ul> 79 <script> 80 var rest_api_url = <?php echo wp_json_encode( get_rest_url() ); ?>, 81 rest_api_nonce = <?php echo wp_json_encode( wp_create_nonce( 'wp_rest' ) ); ?>, 82 plugin_slug = <?php echo wp_json_encode( $post->post_name ); ?>; 74 83 84 jQuery( 'ul.committer-list' ).on( 'click', 'a.remove', function(e) { 85 e.preventDefault(); 86 87 var $this = jQuery( this ), 88 $row = $this.parents('li'), 89 user_nicename = $row.data( 'user' ), 90 url = rest_api_url + 'plugins/v1/plugin/' + plugin_slug + '/committers/' + user_nicename + '/?_wpnonce=' + rest_api_nonce; 91 92 jQuery.post({ 93 url: url, 94 method: 'DELETE', 95 }).success( function( result ) { 96 if ( true === result ) { 97 $row.slideUp( 500, function() { 98 $row.remove(); 99 } ); 100 } else { 101 alert( result.messsage ); 102 } 103 } ).fail( function( result ) { 104 result = jQuery.parseJSON( result.responseText ); 105 if ( typeof result.message !== undefined ) { 106 alert( result.message ); 107 } 108 } ); 109 } ); 110 111 jQuery( 'ul.committer-list' ).on( 'click', 'li.new input[type="submit"]', function(e) { 112 e.preventDefault(); 113 114 var $this = jQuery( this ), 115 $row = $this.parents('li'), 116 $list = $row.parents('ul'), 117 $new_user_input = $row.find( 'input[name="committer"]' ), 118 user_to_add = $new_user_input.val(), 119 url = rest_api_url + 'plugins/v1/plugin/' + plugin_slug + '/committers/?_wpnonce=' + rest_api_nonce; 120 121 jQuery.post({ 122 url: url, 123 dataType: 'json', 124 data: { 125 committer: user_to_add 126 } 127 }).done( function( result ) { 128 if ( typeof result.name !== "undefined" ) { 129 $newrow = jQuery( $row.data('template') ); 130 $newrow.data('user', result.nicename ); 131 $newrow.find('img').attr( 'src', result.avatar ); 132 $newrow.find('a.profile').attr('href', result.profile ).html( result.name ); 133 if ( typeof result.email !== "undefined" ) { 134 $newrow.find('span.email').text( result.email ); 135 } 136 $row.before( $newrow ); 137 $new_user_input.val(''); 138 } else { 139 alert( result.messsage ); 140 } 141 } ).fail( function( result ) { 142 result = jQuery.parseJSON( result.responseText ); 143 if ( typeof result.message !== undefined ) { 144 alert( result.message ); 145 } 146 } ); 147 } ); 148 149 </script> 75 150 76 151 <?php
Note: See TracChangeset
for help on using the changeset viewer.