Making WordPress.org

Changeset 13633

Timestamp:
04/30/2024 11:06:53 PM (3 months ago)
Author:
dufresnesteven
Message:

plugin-directory: Fix the ability to add/remove reps and committers.

Fixes: https://github.com/WordPress/wordpress.org/issues/299
Props: obenland

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-committers.php

    r13128 r13633  
    7373                <form id="add-committer" action="POST">
    7474                    <input type="text" name="committer" placeholder="<?php esc_attr_e( 'Login, Slug, or Email.', 'wporg-plugins' ); ?>">
    75                     <button type="submit" class="button button-secondary"><?php esc_attr_e( 'Add', 'wporg-plugins' ); ?></button>
     75                    <button type="submit" class="button button-secondary"><?php esc_attr_e( 'Add', 'wporg-plugins' ); ?></button>
    7676                </form>
    7777
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/class-support-reps.php

    r13128 r13633  
    7676                <form id="add-support-rep" action="POST">
    7777                    <input type="text" name="support_rep" placeholder="<?php esc_attr_e( 'Login, Slug, or Email.', 'wporg-plugins' ); ?>">
    78                     <button type="submit" class="button button-secondary"><?php esc_attr_e( 'Add', 'wporg-plugins' ); ?></button>
     78                    <button type="submit" class="button button-secondary"><?php esc_attr_e( 'Add', 'wporg-plugins' ); ?></button>
    7979                </form>
    8080
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/js/committers.js

    r13128 r13633  
    1 (
    2     /**
    3      * @param {Object} $
    4      * @param {Object} wp
    5      * @param {Object} pluginDir
    6      * @param {String} pluginDir.restUrl
    7      * @param {String} pluginDir.restNonce
    8      * @param {String} pluginDir.pluginSlug
    9      */
    10     function( $, wp, pluginDir ) {
    11         var logError = function( result ) {
    12             $( '.spinner' ).removeClass( 'spinner' );
    13             result = $.parseJSON( result.responseText );
    14             if ( typeof result.message !== 'undefined' ) {
    15                 alert( result.message );
    16             }
    17         };
    18 
    19         $( '#committer-list' )
    20             .on( 'click', '.remove', function() {
    21                 var $this = $( this ),
    22                     $row = $this.parents( 'li' ),
    23                     user_id = $row.data( 'user' ),
    24                     url;
    25 
    26                 if (
    27                     ! window.confirm(
    28                         pluginDir.removeCommitterAYS.replace(
    29                             /%(1[$])?s/,
    30                             $row.find('a').first().text().trim()
     1document.addEventListener( 'DOMContentLoaded' , function() {
     2    (
     3        /**
     4         * @param {Object} $
     5         * @param {Object} wp
     6         * @param {Object} pluginDir
     7         * @param {String} pluginDir.restUrl
     8         * @param {String} pluginDir.restNonce
     9         * @param {String} pluginDir.pluginSlug
     10         */
     11        function( $, wp, pluginDir ) {
     12            var logError = function( result ) {
     13                $( '.spinner' ).removeClass( 'spinner' );
     14                result = $.parseJSON( result.responseText );
     15                if ( typeof result.message !== 'undefined' ) {
     16                    alert( result.message );
     17                }
     18            };
     19   
     20            $( '#committer-list' )
     21                .on( 'click', '.remove', function() {
     22                    var $this = $( this ),
     23                        $row = $this.parents( 'li' ),
     24                        user_id = $row.data( 'user' ),
     25                        url;
     26   
     27                    if (
     28                        ! window.confirm(
     29                            pluginDir.removeCommitterAYS.replace(
     30                                /%(1[$])?s/,
     31                                $row.find('a').first().text().trim()
     32                            )
    3133                        )
    32                     )
    33                 ) {
    34                     return;
    35                 }
    36 
    37                 $this.addClass( 'spinner' );
    38 
    39                 url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/' + user_id + '/?_wpnonce=' + pluginDir.restNonce;
    40 
    41                 $.post( {
    42                     url: url,
    43                     method: 'DELETE',
    44                 } ).success( function( result ) {
    45                     if ( true === result ) {
    46                         $row.slideUp( 500, function() {
    47                             $row.remove()
    48                         } );
     34                    ) {
     35                        return;
    4936                    }
    50                 } ).fail( logError );
    51             } )
    52             .on( 'submit', '#add-committer', function( event ) {
    53                 event.preventDefault();
    54 
    55                 var $row = $( this ).parents( 'li' ),
    56                     $newUserInput = $row.find( 'input[name="committer"]' ),
    57                     $button = $row.find( '.button-small' ).addClass( 'spinner' ),
    58                     url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/?_wpnonce=' + pluginDir.restNonce;
    59 
    60                 $.post( {
    61                     url: url,
    62                     dataType: 'json',
    63                     data: {
    64                         committer: $newUserInput.val()
    65                     }
    66                 } ).done( function( result ) {
    67                     if ( typeof result.name !== 'undefined' ) {
    68                         $row.before( wp.template( 'new-committer' )( result ) );
    69                         $newUserInput.val( '' );
    70                         $button.removeClass( 'spinner' );
    71                     }
    72                 } ).fail( logError );
    73             } );
    74     } )( window.jQuery, window.wp, window.committersWidget );
     37   
     38                    $this.addClass( 'spinner' );
     39   
     40                    url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/' + user_id + '/?_wpnonce=' + pluginDir.restNonce;
     41   
     42                    $.post( {
     43                        url: url,
     44                        method: 'DELETE',
     45                    } ).success( function( result ) {
     46                        if ( true === result ) {
     47                            $row.slideUp( 500, function() {
     48                                $row.remove()
     49                            } );
     50                        }
     51                    } ).fail( logError );
     52                } )
     53                .on( 'submit', '#add-committer', function( event ) {
     54                    event.preventDefault();
     55   
     56                    var $row = $( this ).parents( 'li' ),
     57                        $newUserInput = $row.find( 'input[name="committer"]' ),
     58                        $button = $row.find( '.button-small' ).addClass( 'spinner' ),
     59                        url = pluginDir.restUrl + 'plugins/v1/plugin/' + pluginDir.pluginSlug + '/committers/?_wpnonce=' + pluginDir.restNonce;
     60   
     61                    $.post( {
     62                        url: url,
     63                        dataType: 'json',
     64                        data: {
     65                            committer: $newUserInput.val()
     66                        }
     67                    } ).done( function( result ) {
     68                        if ( typeof result.name !== 'undefined' ) {
     69                            $row.before( wp.template( 'new-committer' )( result ) );
     70                            $newUserInput.val( '' );
     71                            $button.removeClass( 'spinner' );
     72                        }
     73                    } ).fail( logError );
     74                } );
     75        } )( window.jQuery, window.wp, window.committersWidget );
     76} );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/widgets/js/support-reps.js

    r13128 r13633  
    1 (
     1document.addEventListener( 'DOMContentLoaded' , function() {
     2    (
    23    /**
    34     * @param {Object} $
     
    7374            } );
    7475    } )( window.jQuery, window.wp, window.supportRepsWidget );
     76
Note: See TracChangeset for help on using the changeset viewer.