Class: Tenon::ContactsController

Inherits:
ResourcesController show all
Defined in:
app/controllers/tenon/contacts_controller.rb

Instance Method Summary collapse

Methods inherited from ResourcesController

#create, #destroy, #edit, #initialize, #new, #reorder, #update

Constructor Details

This class inherits a constructor from Tenon::ResourcesController

Instance Method Details

#indexObject



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

def index
  respond_to do |format|
    format.html do
      @counts = {
        all: Tenon::Contact.count,
        read: Tenon::Contact.read.count,
        unread: Tenon::Contact.unread.count,
        replied: Tenon::Contact.replied.count,
        unreplied: Tenon::Contact.unreplied.count
      }
    end
    format.json do
      @contacts = Tenon::Contact.all
      @contacts = @contacts.where(search_args) if params[:q]
      if %w(read unread replied unreplied).include?(params[:type])
        @contacts = @contacts.send(params[:type])
      end
      @contacts = @contacts.paginate(per_page: 20, page: params[:page])
      @contacts = Tenon::PaginatingDecorator.decorate(@contacts)
    end
  end
end

#toggle_readObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/tenon/contacts_controller.rb', line 28

def toggle_read
  respond_to do |format|
    if @contact.toggle_read!
      format.json { render json: @contact.to_json }
      format.html { flash[:notice] = 'Comment flagged as read.' and redirect_to contacts_path }
    else
      format.json { render status: 500, nothing: true }
      format.html { flash[:warning] = 'Error flagging contact as read.' and redirect_to contacts_path }
    end
  end
end

#toggle_repliedObject



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/tenon/contacts_controller.rb', line 40

def toggle_replied
  respond_to do |format|
    if @contact.toggle_replied!
      format.json { render json: @contact.to_json }
      format.html { flash[:notice] = 'Comment flagged as replied.' and redirect_to contacts_path }
    else
      format.json { render status: 500, nothing: true }
      format.html { flash[:warning] = 'Error flagging contact as replied.' and redirect_to contacts_path }
    end
  end
end