Allow single/multiple user select
This commit is contained in:
parent
7316055ac8
commit
bdcaf21ea7
6 changed files with 12 additions and 7 deletions
|
@ -16,7 +16,7 @@ $ ->
|
|||
|
||||
$('.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"
|
||||
|
|
|
@ -13,7 +13,7 @@ class Teams::MembersController < Teams::ApplicationController
|
|||
|
||||
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)
|
||||
|
|
|
@ -170,7 +170,9 @@ module ApplicationHelper
|
|||
|
||||
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
|
||||
|
|
|
@ -69,6 +69,9 @@ class UserTeam < ActiveRecord::Base
|
|||
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
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
.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
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
%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
|
||||
|
|
Loading…
Reference in a new issue