Class: ContactsController
- Inherits:
-
EntitiesController
- Object
- ActionController::Base
- ApplicationController
- EntitiesController
- ContactsController
- Defined in:
- app/controllers/entities/contacts_controller.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Instance Method Summary collapse
-
#create ⇒ Object
POST /contacts —————————————————————————-.
-
#destroy ⇒ Object
DELETE /contacts/1 —————————————————————————-.
-
#edit ⇒ Object
GET /contacts/1/edit AJAX —————————————————————————-.
-
#index ⇒ Object
GET /contacts —————————————————————————-.
-
#new ⇒ Object
GET /contacts/new —————————————————————————-.
-
#redraw ⇒ Object
GET /contacts/redraw AJAX —————————————————————————-.
-
#show ⇒ Object
GET /contacts/1 AJAX /contacts/1 —————————————————————————-.
-
#update ⇒ Object
PUT /contacts/1 —————————————————————————-.
Methods inherited from EntitiesController
#attach, #contacts, #discard, #field_group, #leads, #opportunities, #subscribe, #unsubscribe, #versions
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
POST /contacts
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/entities/contacts_controller.rb', line 61 def create @comment_body = params[:comment_body] respond_with(@contact) do |_format| if @contact.(params.permit!) @contact.add_comment_by_user(@comment_body, current_user) @contacts = get_contacts if called_from_index_page? else unless params[:account][:id].blank? @account = Account.find(params[:account][:id]) else if request.referer =~ /\/accounts\/(\d+)\z/ @account = Account.find(Regexp.last_match[1]) # related account else @account = Account.new(user: current_user) end end @opportunity = Opportunity.my.find(params[:opportunity]) unless params[:opportunity].blank? end end end |
#destroy ⇒ Object
DELETE /contacts/1
98 99 100 101 102 103 104 105 |
# File 'app/controllers/entities/contacts_controller.rb', line 98 def destroy @contact.destroy respond_with(@contact) do |format| format.html { respond_to_destroy(:html) } format.js { respond_to_destroy(:ajax) } end end |
#edit ⇒ Object
GET /contacts/1/edit AJAX
50 51 52 53 54 55 56 57 |
# File 'app/controllers/entities/contacts_controller.rb', line 50 def edit @account = @contact.account || Account.new(user: current_user) if params[:previous].to_s =~ /(\d+)\z/ @previous = Contact.my.find_by_id(Regexp.last_match[1]) || Regexp.last_match[1].to_i end respond_with(@contact) end |
#index ⇒ Object
GET /contacts
11 12 13 14 15 16 17 18 |
# File 'app/controllers/entities/contacts_controller.rb', line 11 def index @contacts = get_contacts(page: params[:page], per_page: params[:per_page]) respond_with @contacts do |format| format.xls { render layout: 'header' } format.csv { render csv: @contacts } end end |
#new ⇒ Object
GET /contacts/new
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/entities/contacts_controller.rb', line 32 def new @contact.attributes = { user: current_user, access: Setting.default_access, assigned_to: nil } @account = Account.new(user: current_user) if params[:related] model, id = params[:related].split('_') if = model.classify.constantize.my.find_by_id(id) instance_variable_set("@#{model}", ) else (model) && return end end respond_with(@contact) end |
#redraw ⇒ Object
GET /contacts/redraw AJAX
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/entities/contacts_controller.rb', line 121 def redraw current_user.pref[:contacts_per_page] = params[:per_page] if params[:per_page] # Sorting and naming only: set the same option for Leads if the hasn't been set yet. if params[:sort_by] current_user.pref[:contacts_sort_by] = Contact.sort_by_map[params[:sort_by]] if Lead.sort_by_fields.include?(params[:sort_by]) current_user.pref[:leads_sort_by] ||= Lead.sort_by_map[params[:sort_by]] end end if params[:naming] current_user.pref[:contacts_naming] = params[:naming] current_user.pref[:leads_naming] ||= params[:naming] end @contacts = get_contacts(page: 1, per_page: params[:per_page]) # Start on the first page. # Refresh options respond_with(@contacts) do |format| format.js { render :index } end end |
#show ⇒ Object
GET /contacts/1 AJAX /contacts/1
23 24 25 26 27 28 |
# File 'app/controllers/entities/contacts_controller.rb', line 23 def show @stage = Setting.unroll(:opportunity_stage) @comment = Comment.new @timeline = timeline(@contact) respond_with(@contact) end |
#update ⇒ Object
PUT /contacts/1
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/entities/contacts_controller.rb', line 84 def update respond_with(@contact) do |_format| unless @contact.(params.permit!) if @contact.account @account = @contact.account else @account = Account.new(user: current_user) end end end end |