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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/entities/contacts_controller.rb', line 63 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 if params[:account] @account = if params[:account][:id].blank? if request.referer =~ /\/accounts\/(\d+)\z/ Account.find(Regexp.last_match[1]) # related account else Account.new(user: current_user) end else Account.find(params[:account][:id]) end end @opportunity = Opportunity.my(current_user).find(params[:opportunity]) unless params[:opportunity].blank? end end end |
#destroy ⇒ Object
DELETE /contacts/1
102 103 104 105 106 107 108 109 |
# File 'app/controllers/entities/contacts_controller.rb', line 102 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
52 53 54 55 56 57 58 59 |
# File 'app/controllers/entities/contacts_controller.rb', line 52 def edit @account = @contact.account || Account.new(user: current_user) if params[:previous].to_s =~ /(\d+)\z/ @previous = Contact.my(current_user).find_by_id(Regexp.last_match[1]) || Regexp.last_match[1].to_i end respond_with(@contact) end |
#index ⇒ Object
GET /contacts
13 14 15 16 17 18 19 20 |
# File 'app/controllers/entities/contacts_controller.rb', line 13 def index @contacts = get_contacts(page: page_param, per_page: per_page_param) respond_with @contacts do |format| format.xls { render layout: 'header' } format.csv { render csv: @contacts } end end |
#new ⇒ Object
GET /contacts/new
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/entities/contacts_controller.rb', line 34 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(current_user).find_by_id(id) instance_variable_set("@#{model}", ) else (model) && return end end respond_with(@contact) end |
#redraw ⇒ Object
GET /contacts/redraw AJAX
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/controllers/entities/contacts_controller.rb', line 125 def redraw current_user.pref[:contacts_per_page] = per_page_param if per_page_param # 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: per_page_param) # 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
25 26 27 28 29 30 |
# File 'app/controllers/entities/contacts_controller.rb', line 25 def show @stage = Setting.unroll(:opportunity_stage) @comment = Comment.new @timeline = timeline(@contact) respond_with(@contact) end |
#update ⇒ Object
PUT /contacts/1
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/entities/contacts_controller.rb', line 88 def update respond_with(@contact) do |_format| unless @contact.(params.permit!) @account = if @contact.account @contact.account else Account.new(user: current_user) end end end end |