Class: ContactsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/contacts_controller.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



44
45
46
47
48
49
50
51
52
# File 'app/controllers/contacts_controller.rb', line 44

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

  respond_to do |format|
    format.js
  end
end

#editObject



25
26
27
# File 'app/controllers/contacts_controller.rb', line 25

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

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/contacts_controller.rb', line 4

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.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.actor_id.to_s, 'value' => self.class.helpers.truncate_name(c.name) } }.to_json }
  end
end

#pendingObject



54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/contacts_controller.rb', line 54

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 { Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
    format.json { render :text => @contacts.map{ |c| { 'key' => c.actor_id.to_s, 'value' => self.class.helpers.truncate_name(c.name) } }.to_json }
  end
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/contacts_controller.rb', line 29

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