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 |
# 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 @account = (params[:account][:id], request.referer, current_user) if params[:account] @opportunity = Opportunity.my(current_user).find(params[:opportunity]) unless params[:opportunity].blank? end end end |
#destroy ⇒ Object
DELETE /contacts/1
84 85 86 87 88 89 90 91 |
# File 'app/controllers/entities/contacts_controller.rb', line 84 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 |
# File 'app/controllers/entities/contacts_controller.rb', line 52 def edit @account = @contact.account || Account.new(user: current_user) @previous = Contact.my(current_user).find_by_id(detect_previous_id) || detect_previous_id if detect_previous_id 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/entities/contacts_controller.rb', line 107 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]] current_user.pref[:leads_sort_by] ||= Lead.sort_by_map[params[:sort_by]] if Lead.sort_by_fields.include?(params[:sort_by]) 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
76 77 78 79 80 |
# File 'app/controllers/entities/contacts_controller.rb', line 76 def update respond_with(@contact) do |_format| @account = @contact.account || Account.new(user: current_user) unless @contact.(params.permit!) end end |