base/app/controllers/contacts_controller.rb in social_stream-0.9.6 vs base/app/controllers/contacts_controller.rb in social_stream-0.9.7

- old
+ new

@@ -1,25 +1,22 @@ class ContactsController < ApplicationController before_filter :authenticate_user! before_filter :exclude_reflexive, :except => [ :index, :pending ] def index - if params[:pending].present? - pending - return - end @contacts = - Contact.sent_by(current_subject). - joins(:receiver).merge(Actor.alphabetic). - merge(Actor.letter(params[:letter])). - merge(Actor.name_search(params[:search])). - active + Contact.sent_by(current_subject). + joins(:receiver).merge(Actor.alphabetic). + merge(Actor.letter(params[:letter])). + merge(Actor.name_search(params[:search])). + related_by_param(params[:relation]). + active respond_to do |format| format.html { @contacts = @contacts.page(params[:page]).per(10) } format.js { @contacts = @contacts.page(params[:page]).per(10) } - format.json { render :text => @contacts.map{ |c| { 'key' => c.receiver_id.to_s, 'value' => self.class.helpers.truncate_name(c.receiver.name) } }.to_json } + format.json { render :text => to_json(@contacts) } end end def edit end @@ -49,13 +46,18 @@ def pending @contacts = current_subject.pending_contacts respond_to do |format| - format.html { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) } - format.js { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) } - format.json { render :text => @contacts.map{ |c| { 'key' => c.receiver_id.to_s, 'value' => self.class.helpers.truncate_name(c.receiver.name) } }.to_json } + format.html { + @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) + render :action => :index + } + format.js { + @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) + render :action => :index + } end end private @@ -63,7 +65,26 @@ @contact = current_subject.sent_contacts.find params[:id] if @contact.reflexive? redirect_to home_path end + end + + def to_json(contacts) + contacts.map{ |c| + if params[:form].present? + { + 'key' => c.receiver_id.to_s, + 'value' => self.class.helpers.truncate_name(c.receiver.name) + } + else + { + 'name' => c.receiver.name, + 'url' => polymorphic_url(c.receiver_subject), + 'image' => { + 'url' => root_url + c.receiver.logo.url + } + } + end + }.to_json end end