Commit bdcaf21ea7b4ffb6b386d6b0e809eff10090fc80
1 parent
7316055a
Exists in
master
and in
4 other branches
Allow single/multiple user select
Showing
6 changed files
with
12 additions
and
7 deletions
Show diff stats
app/assets/javascripts/users_select.js.coffee
| @@ -16,7 +16,7 @@ $ -> | @@ -16,7 +16,7 @@ $ -> | ||
| 16 | 16 | ||
| 17 | $('.ajax-users-select').select2 | 17 | $('.ajax-users-select').select2 |
| 18 | placeholder: "Search for a user" | 18 | placeholder: "Search for a user" |
| 19 | - multiple: true | 19 | + multiple: $('.ajax-users-select').hasClass('multiselect') |
| 20 | minimumInputLength: 0 | 20 | minimumInputLength: 0 |
| 21 | ajax: # instead of writing the function to execute the request we use Select2's convenient helper | 21 | ajax: # instead of writing the function to execute the request we use Select2's convenient helper |
| 22 | url: "/api/v3/users.json" | 22 | url: "/api/v3/users.json" |
app/controllers/teams/members_controller.rb
| @@ -13,7 +13,7 @@ class Teams::MembersController < Teams::ApplicationController | @@ -13,7 +13,7 @@ class Teams::MembersController < Teams::ApplicationController | ||
| 13 | 13 | ||
| 14 | def create | 14 | def create |
| 15 | unless params[:user_ids].blank? | 15 | unless params[:user_ids].blank? |
| 16 | - user_ids = params[:user_ids] | 16 | + user_ids = params[:user_ids].split(',') |
| 17 | access = params[:default_project_access] | 17 | access = params[:default_project_access] |
| 18 | is_admin = params[:group_admin] | 18 | is_admin = params[:group_admin] |
| 19 | user_team.add_members(user_ids, access, is_admin) | 19 | user_team.add_members(user_ids, access, is_admin) |
app/helpers/application_helper.rb
| @@ -170,7 +170,9 @@ module ApplicationHelper | @@ -170,7 +170,9 @@ module ApplicationHelper | ||
| 170 | 170 | ||
| 171 | alias_method :url_to_image, :image_url | 171 | alias_method :url_to_image, :image_url |
| 172 | 172 | ||
| 173 | - def users_select_tag(id) | ||
| 174 | - hidden_field_tag(id, '', class: "ajax-users-select") | 173 | + def users_select_tag(id, opts = {}) |
| 174 | + css_class = "ajax-users-select" | ||
| 175 | + css_class << " multiselect" if opts[:multiple] | ||
| 176 | + hidden_field_tag(id, '', class: css_class) | ||
| 175 | end | 177 | end |
| 176 | end | 178 | end |
app/models/user_team.rb
| @@ -69,6 +69,9 @@ class UserTeam < ActiveRecord::Base | @@ -69,6 +69,9 @@ class UserTeam < ActiveRecord::Base | ||
| 69 | end | 69 | end |
| 70 | 70 | ||
| 71 | def add_members(users, access, group_admin) | 71 | def add_members(users, access, group_admin) |
| 72 | + # reject existing users | ||
| 73 | + users.reject! { |id| member_ids.include?(id.to_i) } | ||
| 74 | + | ||
| 72 | users.each do |user| | 75 | users.each do |user| |
| 73 | add_member(user, access, group_admin) | 76 | add_member(user, access, group_admin) |
| 74 | end | 77 | end |
app/views/team_members/_form.html.haml
| @@ -12,8 +12,7 @@ | @@ -12,8 +12,7 @@ | ||
| 12 | .clearfix | 12 | .clearfix |
| 13 | = f.label :user_ids, "People" | 13 | = f.label :user_ids, "People" |
| 14 | .input | 14 | .input |
| 15 | - = users_select_tag(:user_ids) | ||
| 16 | - -#= select_tag(:user_ids, options_from_collection_for_select(User.active.not_in_project(@project).alphabetically, :id, :name_with_username), {data: {placeholder: "Select users"}, class: "chosen xxlarge", multiple: true}) | 15 | + = users_select_tag(:user_ids, multiple: true) |
| 17 | 16 | ||
| 18 | %h6 2. Set access level for them | 17 | %h6 2. Set access level for them |
| 19 | .clearfix | 18 | .clearfix |
app/views/teams/members/new.html.haml
| @@ -20,7 +20,8 @@ | @@ -20,7 +20,8 @@ | ||
| 20 | %td= @team.admin?(member) ? "Admin" : "Member" | 20 | %td= @team.admin?(member) ? "Admin" : "Member" |
| 21 | %td | 21 | %td |
| 22 | %tr | 22 | %tr |
| 23 | - %td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_username), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' | 23 | + %td |
| 24 | + = users_select_tag(:user_ids, multiple: true) | ||
| 24 | %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } | 25 | %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } |
| 25 | %td | 26 | %td |
| 26 | %span= check_box_tag :group_admin | 27 | %span= check_box_tag :group_admin |