diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index aeecaae08..22499dfde 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -6,22 +6,29 @@ class ContactsController < ApplicationController before_filter :authenticate_user! def index - @aspect = :manage - - if 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) - 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.includes(:profile).to_json - 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) - elsif params[:set] != "all" - @contacts = current_user.contacts.receiving.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) + @contacts = case params[:set] + when "only_sharing" + current_user.contacts.only_sharing + when "all" + current_user.contacts else - @contacts = current_user.contacts.includes(:aspects, :person => :profile).order('profiles.last_name ASC').paginate(:page => params[:page], :per_page => 25) + if params[:a_id] + @aspect = current_user.aspects.find(params[:a_id]) + @aspect.contacts + else + current_user.contacts.receiving + end + end + + respond_to do |format| + format.html { @contacts = sort_and_paginate_profiles(@contacts) } + 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.includes(:profile).to_json + } end end @@ -30,4 +37,12 @@ class ContactsController < ApplicationController render :layout => false end + private + + def sort_and_paginate_profiles contacts + contacts. + includes(:aspects, :person => :profile). + order('profiles.last_name ASC'). + paginate(:page => params[:page], :per_page => 25) + end end diff --git a/app/views/contacts/index.html.haml b/app/views/contacts/index.html.haml index 0a7d1a309..e6d73ad94 100644 --- a/app/views/contacts/index.html.haml +++ b/app/views/contacts/index.html.haml @@ -20,32 +20,32 @@ .span-18.last #people_stream.stream.contacts - - if @aspect_ + - if @aspect #aspect_controls - suggested_limit = 16 - conv_opts = { :class => "button conversation_button", :rel => "facebox"} - conv_opts[:title] = t('.many_people_are_you_sure', :suggested_limit => suggested_limit) if @contacts.size > suggested_limit - = link_to t('.start_a_conversation'), new_conversation_path(:aspect_id => @aspect_.id, :name => @aspect_.name), conv_opts + = link_to t('.start_a_conversation'), new_conversation_path(:aspect_id => @aspect.id, :name => @aspect.name), conv_opts - if @contacts.size > suggested_limit = javascript_tag "$('.conversation_button').tipsy({trigger: 'hover', gravity: 'n'});" - = link_to t('.edit_aspect', :name => @aspect_.name), edit_aspect_path(@aspect_), :rel => "facebox" + = link_to t('.edit_aspect', :name => @aspect.name), edit_aspect_path(@aspect), :rel => "facebox" - if @contacts.size > 0 - for contact in @contacts .stream_element{:id => contact.person.id} .right - - if @aspect_ + - if @aspect = link_to(image_tag('/images/icons/monotone_close_exit_delete.png', :height => 20, :width => 20), {:controller => "aspect_memberships", :action => 'destroy', :id => 42, - :aspect_id => @aspect_.id, + :aspect_id => @aspect.id, :person_id => contact.person.id}, - :title => t('.remove_person_from_aspect', :person_name => contact.person.first_name, :aspect_name => @aspect_.name), + :title => t('.remove_person_from_aspect', :person_name => contact.person.first_name, :aspect_name => @aspect.name), :method => 'delete') - - else + - else = render :partial => 'people/relationship_action', :locals => { :person => contact.person, :contact => contact, :current_user => current_user } diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index d362f135e..929aefd1f 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -33,11 +33,6 @@ describe ContactsController do response.should be_success end - it "assigns aspect to manage" do - get :index - assigns(:aspect).should == :manage - end - it "assigns contacts" do get :index contacts = assigns(:contacts)