Commit bdcaf21e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Allow single/multiple user select

parent 7316055a
...@@ -16,7 +16,7 @@ $ -> ...@@ -16,7 +16,7 @@ $ ->
$('.ajax-users-select').select2 $('.ajax-users-select').select2
placeholder: "Search for a user" placeholder: "Search for a user"
multiple: true multiple: $('.ajax-users-select').hasClass('multiselect')
minimumInputLength: 0 minimumInputLength: 0
ajax: # instead of writing the function to execute the request we use Select2's convenient helper ajax: # instead of writing the function to execute the request we use Select2's convenient helper
url: "/api/v3/users.json" url: "/api/v3/users.json"
......
...@@ -13,7 +13,7 @@ class Teams::MembersController < Teams::ApplicationController ...@@ -13,7 +13,7 @@ class Teams::MembersController < Teams::ApplicationController
def create def create
unless params[:user_ids].blank? unless params[:user_ids].blank?
user_ids = params[:user_ids] user_ids = params[:user_ids].split(',')
access = params[:default_project_access] access = params[:default_project_access]
is_admin = params[:group_admin] is_admin = params[:group_admin]
user_team.add_members(user_ids, access, is_admin) user_team.add_members(user_ids, access, is_admin)
......
...@@ -170,7 +170,9 @@ module ApplicationHelper ...@@ -170,7 +170,9 @@ module ApplicationHelper
alias_method :url_to_image, :image_url alias_method :url_to_image, :image_url
def users_select_tag(id) def users_select_tag(id, opts = {})
hidden_field_tag(id, '', class: "ajax-users-select") css_class = "ajax-users-select"
css_class << " multiselect" if opts[:multiple]
hidden_field_tag(id, '', class: css_class)
end end
end end
...@@ -69,6 +69,9 @@ class UserTeam < ActiveRecord::Base ...@@ -69,6 +69,9 @@ class UserTeam < ActiveRecord::Base
end end
def add_members(users, access, group_admin) def add_members(users, access, group_admin)
# reject existing users
users.reject! { |id| member_ids.include?(id.to_i) }
users.each do |user| users.each do |user|
add_member(user, access, group_admin) add_member(user, access, group_admin)
end end
......
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
.clearfix .clearfix
= f.label :user_ids, "People" = f.label :user_ids, "People"
.input .input
= users_select_tag(:user_ids) = users_select_tag(:user_ids, multiple: true)
-#= 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})
%h6 2. Set access level for them %h6 2. Set access level for them
.clearfix .clearfix
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
%td= @team.admin?(member) ? "Admin" : "Member" %td= @team.admin?(member) ? "Admin" : "Member"
%td %td
%tr %tr
%td= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name_with_username), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5' %td
= users_select_tag(:user_ids, multiple: true)
%td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" } %td= select_tag :default_project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3" }
%td %td
%span= check_box_tag :group_admin %span= check_box_tag :group_admin
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment