Skip to:
Content

BuddyPress.org

Changeset 8417


Ignore:
Timestamp:
05/12/2014 08:36:26 PM (7 years ago)
Author:
boonebgorges
Message:

Improve logic for adding a user to a group in the Dashboard

On submit, the JS converts the dynamically created <li> items to a proper
comma-separated list of user logins. This creates greater consistency with the
noscript workflow, and also fixes a bug where users who were found via
autocomplete but then removed from the list of users to add would be added
anyway.

Fixes #5633

Props imath

Location:
trunk/src/bp-groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/admin/js/admin.js

    r8378 r8417  
    33(function($) {
    44    function add_member_to_list( e, ui ) {
    5         var remove_id = 'bp-groups-remove-new-member-' + ui.item.value;
    6         $('#bp-groups-new-members-list').append('<li><a href="#" class="bp-groups-remove-new-member" id="' + remove_id + '">x</a> ' + ui.item.label + '</li>');
    7         $('#' + remove_id).bind('click', function(e) { remove_member_from_list(e); return false; });
    8 
    9         $('#bp-groups-new-members-list').after('<input name="new_members[]" type="hidden" value="' + ui.item.value + '" />');
    10     }
    11 
    12     function remove_member_from_list( e ) {
    13         $(e.target).closest('li').remove();
     5        $('#bp-groups-new-members-list').append('<li data-login="' + ui.item.value + '"><a href="#" class="bp-groups-remove-new-member">x</a> ' + ui.item.label + '</li>');
    146    }
    157
     
    2820            select:    function( event, ui ) { add_member_to_list( event, ui ); }
    2921        });
    30        
     22
    3123        /* Replace noscript placeholder */
    32         $( '#bp-groups-new-members' ).attr( 'placeholder', BP_Group_Admin.add_member_placeholder );
     24        $( '#bp-groups-new-members' ).prop( 'placeholder', BP_Group_Admin.add_member_placeholder );
     25
     26        /* Remove a member on 'x' click */
     27        $( '#bp_group_add_members' ).on( 'click', '.bp-groups-remove-new-member', function( e ) {
     28            e.preventDefault();
     29            $( e.target.parentNode ).remove();
     30        } );
    3331
    3432        /* Warn before leaving unsaved changes */
     
    3836
    3937        $( 'input#save' ).on( 'click', function() {
     38            /* Check for users to add */
     39            var users_to_add = [];
     40
     41            $( '#bp-groups-new-members-list li' ).each( function() {
     42                users_to_add.push( $(this).data('login' ) );
     43            } );
     44
     45            /* There are users to add, include a comma separated list of users login in the main field */
     46            if ( users_to_add.length ) {
     47                $( '#bp-groups-new-members' ).val( '' ).val( users_to_add.join( ', ' ) );
     48            }
     49
    4050            window.warn_on_leave = false;
    4151        });
  • trunk/src/bp-groups/bp-groups-admin.php

    r8412 r8417  
    229229        if ( ! empty( $_POST['bp-groups-new-members'] ) ) {
    230230            $user_names = array_merge( $user_names, explode( ',', $_POST['bp-groups-new-members'] ) );
    231         }
    232 
    233         if ( ! empty( $_POST['new_members'] ) ) {
    234             $user_names = array_merge( $user_names, $_POST['new_members'] );
    235231        }
    236232
Note: See TracChangeset for help on using the changeset viewer.