Skip to content
Extraits de code Groupes Projets
Valider f60a748c rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Ajax in the contacts for mentioning after page load

parent 37e939d4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -39,7 +39,7 @@ class AspectsController < ApplicationController ...@@ -39,7 +39,7 @@ class AspectsController < ApplicationController
all_selected_people = Person.joins(:contacts => :aspect_memberships). all_selected_people = Person.joins(:contacts => :aspect_memberships).
where(:contacts => {:user_id => current_user.id}, where(:contacts => {:user_id => current_user.id},
:aspect_memberships => {:aspect_id => aspect_ids}) :aspect_memberships => {:aspect_id => aspect_ids})
@selected_people = all_selected_people.select("DISTINCT people.*").includes(:profile) @selected_people = all_selected_people.select("DISTINCT people.*").limit(20).includes(:profile)
end end
@aspect_ids = @aspects.map { |a| a.id } @aspect_ids = @aspects.map { |a| a.id }
......
...@@ -11,6 +11,11 @@ class ContactsController < ApplicationController ...@@ -11,6 +11,11 @@ class ContactsController < ApplicationController
if params[:a_id] if params[:a_id]
@aspect_ = current_user.aspects.find(params["a_id"]) @aspect_ = current_user.aspects.find(params["a_id"])
@contacts = @aspect_.contacts.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) @contacts = @aspect_.contacts.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25)
elsif params[:aspect_ids] && request.format == "json"
@people = Person.joins(:contacts => :aspect_memberships).
where(:contacts => {:user_id => current_user.id},
:aspect_memberships => {:aspect_id => params[:aspect_ids]})
render :json => @people.to_json
elsif params[:set] == "only_sharing" elsif params[:set] == "only_sharing"
@contacts = current_user.contacts.only_sharing.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) @contacts = current_user.contacts.only_sharing.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25)
elsif params[:set] != "all" elsif params[:set] != "all"
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )} #publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )}
.content_creation .content_creation
= form_for(StatusMessage.new, :remote => true, :html => {"data-type" => "json"}) do |status| = form_for(StatusMessage.new, :remote => true, :html => {"data-type" => "json"}) do |status|
- if @selected_people
= hidden_field_tag :contact_json, @selected_people.to_json
= status.error_messages = status.error_messages
%p %p
%params %params
...@@ -52,6 +50,8 @@ ...@@ -52,6 +50,8 @@
.facebox_content .facebox_content
#question_mark_pane #question_mark_pane
= render 'shared/public_explain' = render 'shared/public_explain'
= link_to '', contacts_path(:aspect_ids => aspect_ids), :class => 'selected_contacts_link hidden'
#publisher_photo_upload #publisher_photo_upload
= render 'photos/new_photo', :aspect_ids => aspect_ids.join(',') = render 'photos/new_photo', :aspect_ids => aspect_ids.join(',')
......
...@@ -254,14 +254,15 @@ var Publisher = { ...@@ -254,14 +254,15 @@ var Publisher = {
return ''; return '';
} }
}, },
contactsJSON: function(){
return $.parseJSON($('#contact_json').val());
},
initialize: function(){ initialize: function(){
Publisher.input().autocomplete(Publisher.autocompletion.contactsJSON(), $.getJSON($("#publisher .selected_contacts_link").attr("href"), undefined ,
Publisher.autocompletion.options()); function(data){
Publisher.input().result(Publisher.autocompletion.selectItemCallback); Publisher.input().autocomplete(data,
Publisher.oldInputContent = Publisher.input().val(); Publisher.autocompletion.options());
Publisher.input().result(Publisher.autocompletion.selectItemCallback);
Publisher.oldInputContent = Publisher.input().val();
}
);
} }
}, },
determineSubmitAvailability: function(){ determineSubmitAvailability: function(){
......
...@@ -62,6 +62,12 @@ describe ContactsController do ...@@ -62,6 +62,12 @@ describe ContactsController do
contacts.to_set.should == bob.contacts.to_set contacts.to_set.should == bob.contacts.to_set
end end
it 'will return the contacts for multiple aspects' do
get :index, :aspect_ids => bob.aspect_ids, :format => 'json'
assigns[:people].should == bob.contacts.map(&:person)
response.should be_success
end
it "generates a jasmine fixture", :fixture => true do it "generates a jasmine fixture", :fixture => true do
get :index get :index
save_fixture(html_for("body"), "aspects_manage") save_fixture(html_for("body"), "aspects_manage")
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter