Sha256: 99705cef7c2e7a5fb418a8ee9bb69a560c48ec70330c1711a2f57f924930a140

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

class ContactsController < ApplicationController
  before_filter :authenticate_user!
  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

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

  def edit
    @contact = current_subject.sent_contacts.find params[:id]
  end

  def update
    @contact = current_subject.sent_contacts.find params[:id]

    # This should be in the model
    if params[:contact][:relation_ids].present?
      params[:contact][:relation_ids].delete("gotcha")
    end

    if @contact.update_attributes(params[:contact])
      redirect_to @contact.receiver_subject
    else
      render :action => 'edit'
    end
  end

  def destroy
    @contact = current_subject.sent_contacts.find params[:id]

    @contact.relation_ids = [current_subject.relation_reject.id]

    respond_to do |format|
      format.js
    end
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
social_stream-base-0.9.5 app/controllers/contacts_controller.rb
social_stream-base-0.9.4 app/controllers/contacts_controller.rb
social_stream-base-0.9.3 app/controllers/contacts_controller.rb
social_stream-base-0.9.2 app/controllers/contacts_controller.rb
social_stream-base-0.9.1 app/controllers/contacts_controller.rb
social_stream-base-0.9.0 app/controllers/contacts_controller.rb