Class: ContactsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/contacts_controller.rb', line 57

def destroy
  relation_ids = []

  if params[:reject].present?
    relation_ids << Relation::Reject.instance.id
  end

  @contact.relation_ids = []

  respond_to do |format|
    format.js
  end
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/contacts_controller.rb', line 5

def index
  subject = profile_or_current_subject!

  params[:d]    ||= 'sent'
  params[:type] ||= subject.class.contact_index_models.first.to_s

  @contacts = Contact

  @contacts =
  if params[:d] == 'received'
    @contacts.received_by(subject).joins(:sender)
  else
    @contacts.sent_by(subject).joins(:receiver)
  end

  @contacts =
    @contacts.
      positive.
      merge(Actor.subject_type(params[:type])).
      merge(Actor.name_search(params[:q])).
      related_by_param(params[:relation]).
      page(params[:page])

  respond_to do |format|
    format.html { render @contacts if request.xhr? }
    format.json { render json: @contacts.map(&:receiver), helper: self }
  end
end

#pendingObject



81
82
83
84
85
86
87
88
# File 'app/controllers/contacts_controller.rb', line 81

def pending
  @contact = current_subject.pending_contacts.last

  respond_to do |format|
    format.html { @contact.present? ? render(partial: @contact) : render(text: "") }
    format.json { render json: @contact }
  end
end

#suggestionObject

Return a suggestion for this contact



72
73
74
75
76
77
78
79
# File 'app/controllers/contacts_controller.rb', line 72

def suggestion
  @contact = current_subject.suggestions.first

  respond_to do |format|
    format.html { @contact.present? ? render(partial: @contact) : render(text: "") }
    format.json { render json: @contact }
  end
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/contacts_controller.rb', line 34

def update
  # Record who is manipulating the contact, mainly in groups
  @contact.user_author = current_user

  # FIXME: This should be in the model
  params[:contact][:relation_ids].present? &&
    params[:contact][:relation_ids].delete("0")

  @contact.update_attributes(params[:contact])

  respond_to do |format|
    format.html {
      if @contact.errors.blank?
        redirect_to @contact.receiver_subject
      else
        render :action => 'edit'
      end
    }

    format.js
  end
end