$('.ajax-users-select').select2
placeholder: "Search for a user"
- multiple: true
+ multiple: $('.ajax-users-select').hasClass('multiselect')
minimumInputLength: 0
ajax: # instead of writing the function to execute the request we use Select2's convenient helper
url: "/api/v3/users.json"
def create
unless params[:user_ids].blank?
- user_ids = params[:user_ids]
+ user_ids = params[:user_ids].split(',')
access = params[:default_project_access]
is_admin = params[:group_admin]
user_team.add_members(user_ids, access, is_admin)
alias_method :url_to_image, :image_url
- def users_select_tag(id)
- hidden_field_tag(id, '', class: "ajax-users-select")
+ def users_select_tag(id, opts = {})
+ css_class = "ajax-users-select"
+ css_class << " multiselect" if opts[:multiple]
+ hidden_field_tag(id, '', class: css_class)
end
end
end
def add_members(users, access, group_admin)
+ # reject existing users
+ users.reject! { |id| member_ids.include?(id.to_i) }
+
users.each do |user|
add_member(user, access, group_admin)
end
.clearfix
= f.label :user_ids, "People"
.input
- = users_select_tag(:user_ids)
- -#= 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})
+ = users_select_tag(:user_ids, multiple: true)
%h6 2. Set access level for them
.clearfix
%td= @team.admin?(member) ? "Admin" : "Member"
%td
%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
%span= check_box_tag :group_admin