diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56c146d..1d99f4d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,9 +14,12 @@ def search format.json do results = { :suggestions => [], :data => [], :query => params[:query] } user_search(params[:query]).each do |user| + if params[:exclude] && params[:exclude].include?(user._id.to_s) + next + end results[:suggestions] << "#{user.firstname} #{user.lastname} [#{user.email_address}]" results[:data] << { - '_id' => user._id, + '_id' => user._id.to_s, 'firstname' => user.firstname, 'lastname' => user.lastname, 'email_address' => user.email_address, diff --git a/app/views/_user_multiselect.html.haml b/app/views/_user_multiselect.html.haml index 0fb094c..697189e 100644 --- a/app/views/_user_multiselect.html.haml +++ b/app/views/_user_multiselect.html.haml @@ -16,8 +16,14 @@ %input.span3.new-user{type: 'text'} %i.icon-plus +- user_search_params = {} +- if local_assigns[:exclude].nil? == false + - user_search_params["exclude"] = exclude.map(&:_id) + - content_for :page_scripts do + :javascript + var user_search_params = #{user_search_params.to_json}; = javascript_include_tag '/javascripts/jquery.autocomplete.js' = javascript_include_tag '/javascripts/userSelector.js' diff --git a/public/javascripts/userSelector.js b/public/javascripts/userSelector.js index b43f271..294d25a 100644 --- a/public/javascripts/userSelector.js +++ b/public/javascripts/userSelector.js @@ -1,9 +1,13 @@ $(function(){ // Autocomplete $(".user-multi-select").each(function(){ + if (typeof user_search_params !== 'undefined') { + console.log(user_search_params); + } var ums = $(this); var userAutocomplete = ums.find("input.new-user").autocomplete({ serviceUrl:'/users/search.json', + params: user_search_params, minChars: 3, maxHeight: 400, width: 350,