OSDN Git Service

multiselect for ajax-users-select2
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Wed, 13 Mar 2013 19:42:14 +0000 (21:42 +0200)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Wed, 13 Mar 2013 21:19:09 +0000 (23:19 +0200)
app/assets/javascripts/users_select.js.coffee
app/controllers/team_members_controller.rb

index 70e5bb9..8dad599 100644 (file)
@@ -11,9 +11,12 @@ $ ->
     markup += "</div>"
     markup
 
+  userFormatSelection = (user) ->
+    user.name
 
   $('.ajax-users-select').select2
     placeholder: "Search for a user"
+    multiple: true
     minimumInputLength: 0
     ajax: # instead of writing the function to execute the request we use Select2's convenient helper
       url: "/api/v3/users.json"
@@ -40,7 +43,7 @@ $ ->
 
 
     formatResult: userFormatResult # omitted for brevity, see the source of this page
-    #formatSelection: userFormatSelection # omitted for brevity, see the source of this page
+    formatSelection: userFormatSelection # omitted for brevity, see the source of this page
     dropdownCssClass: "ajax-users-dropdown" # apply css that makes the dropdown taller
     escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results
       m
index 7de5a68..ba55648 100644 (file)
@@ -16,7 +16,7 @@ class TeamMembersController < ProjectResourceController
   end
 
   def create
-    users = User.where(id: params[:user_ids])
+    users = User.where(id: params[:user_ids].split(','))
 
     @project.team << [users, params[:project_access]]