Ajax in the contacts for mentioning after page load

This commit is contained in:
Raphael Sofaer 2011-07-15 14:23:44 -04:00
parent 37e939d476
commit f60a748c21
5 changed files with 22 additions and 10 deletions

View file

@ -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 }

View file

@ -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"

View file

@ -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 @@
.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(',')

View file

@ -254,15 +254,16 @@ 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 ,
function(data){
Publisher.input().autocomplete(data,
Publisher.autocompletion.options()); Publisher.autocompletion.options());
Publisher.input().result(Publisher.autocompletion.selectItemCallback); Publisher.input().result(Publisher.autocompletion.selectItemCallback);
Publisher.oldInputContent = Publisher.input().val(); Publisher.oldInputContent = Publisher.input().val();
} }
);
}
}, },
determineSubmitAvailability: function(){ determineSubmitAvailability: function(){
var onlyWhitespaces = (Publisher.input().val().trim() === ''); var onlyWhitespaces = (Publisher.input().val().trim() === '');

View file

@ -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")