Class: LeadsController
- Inherits:
-
EntitiesController
- Object
- ActionController::Base
- ApplicationController
- EntitiesController
- LeadsController
- Defined in:
- app/controllers/entities/leads_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
-
#convert ⇒ Object
GET /leads/1/convert —————————————————————————-.
-
#create ⇒ Object
POST /leads —————————————————————————-.
-
#destroy ⇒ Object
DELETE /leads/1 —————————————————————————-.
-
#edit ⇒ Object
GET /leads/1/edit AJAX —————————————————————————-.
-
#filter ⇒ Object
POST /leads/filter AJAX —————————————————————————-.
-
#index ⇒ Object
GET /leads —————————————————————————-.
-
#new ⇒ Object
GET /leads/new —————————————————————————-.
-
#promote ⇒ Object
PUT /leads/1/promote —————————————————————————-.
-
#redraw ⇒ Object
GET /leads/redraw AJAX —————————————————————————-.
-
#reject ⇒ Object
PUT /leads/1/reject —————————————————————————-.
-
#show ⇒ Object
GET /leads/1 AJAX /leads/1 —————————————————————————-.
-
#update ⇒ Object
PUT /leads/1 —————————————————————————-.
Methods inherited from EntitiesController
#attach, #contacts, #discard, #field_group, #leads, #opportunities, #subscribe, #unsubscribe, #versions
Methods inherited from ApplicationController
Instance Method Details
#convert ⇒ Object
GET /leads/1/convert
106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/entities/leads_controller.rb', line 106 def convert @account = Account.new(user: current_user, name: @lead.company, access: "Lead") @accounts = Account.my(current_user).order('name') @opportunity = Opportunity.new(user: current_user, access: "Lead", stage: "prospecting", campaign: @lead.campaign, source: @lead.source) @previous = Lead.my(current_user).find_by_id(detect_previous_id) || detect_previous_id if detect_previous_id respond_with(@lead) end |
#create ⇒ Object
POST /leads
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/entities/leads_controller.rb', line 62 def create get_campaigns @comment_body = params[:comment_body] respond_with(@lead) do |_format| if @lead.(params.permit!) @lead.add_comment_by_user(@comment_body, current_user) if called_from_index_page? @leads = get_leads else (:campaign) end end end end |
#destroy ⇒ Object
DELETE /leads/1
95 96 97 98 99 100 101 102 |
# File 'app/controllers/entities/leads_controller.rb', line 95 def destroy @lead.destroy respond_with(@lead) do |format| format.html { respond_to_destroy(:html) } format.js { respond_to_destroy(:ajax) } end end |
#edit ⇒ Object
GET /leads/1/edit AJAX
52 53 54 55 56 57 58 |
# File 'app/controllers/entities/leads_controller.rb', line 52 def edit get_campaigns @previous = Lead.my(current_user).find_by_id(detect_previous_id) || detect_previous_id if detect_previous_id respond_with(@lead) end |
#filter ⇒ Object
POST /leads/filter AJAX
185 186 187 188 189 190 191 192 |
# File 'app/controllers/entities/leads_controller.rb', line 185 def filter session[:leads_filter] = params[:status] @leads = get_leads(page: 1, per_page: per_page_param) # Start one the first page. respond_with(@leads) do |format| format.js { render :index } end end |
#index ⇒ Object
GET /leads
14 15 16 17 18 19 20 21 |
# File 'app/controllers/entities/leads_controller.rb', line 14 def index @leads = get_leads(page: page_param) respond_with @leads do |format| format.xls { render layout: 'header' } format.csv { render csv: @leads } end end |
#new ⇒ Object
GET /leads/new
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/entities/leads_controller.rb', line 34 def new @lead.attributes = { user: current_user, access: Setting.default_access, assigned_to: nil } get_campaigns 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(@lead) end |
#promote ⇒ Object
PUT /leads/1/promote
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/controllers/entities/leads_controller.rb', line 118 def promote @account, @opportunity, @contact = @lead.promote(params.permit!) @accounts = Account.my(current_user).order('name') @stage = Setting.unroll(:opportunity_stage) respond_with(@lead) do |format| if @account.errors.empty? && @opportunity.errors.empty? && @contact.errors.empty? @lead.convert else format.json { render json: @account.errors + @opportunity.errors + @contact.errors, status: :unprocessable_entity } format.xml { render xml: @account.errors + @opportunity.errors + @contact.errors, status: :unprocessable_entity } end end end |
#redraw ⇒ Object
GET /leads/redraw AJAX
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/controllers/entities/leads_controller.rb', line 162 def redraw current_user.pref[:leads_per_page] = per_page_param if per_page_param # Sorting and naming only: set the same option for Contacts if the hasn't been set yet. if params[:sort_by] current_user.pref[:leads_sort_by] = Lead.sort_by_map[params[:sort_by]] current_user.pref[:contacts_sort_by] ||= Contact.sort_by_map[params[:sort_by]] if Contact.sort_by_fields.include?(params[:sort_by]) end if params[:naming] current_user.pref[:leads_naming] = params[:naming] current_user.pref[:contacts_naming] ||= params[:naming] end @leads = get_leads(page: 1, per_page: per_page_param) # Start one the first page. # Refresh options respond_with(@leads) do |format| format.js { render :index } end end |
#reject ⇒ Object
PUT /leads/1/reject
136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/controllers/entities/leads_controller.rb', line 136 def reject @lead.reject respond_with(@lead) do |format| format.html do flash[:notice] = t(:msg_asset_rejected, @lead.full_name) redirect_to leads_path end end end |
#show ⇒ Object
GET /leads/1 AJAX /leads/1
26 27 28 29 30 |
# File 'app/controllers/entities/leads_controller.rb', line 26 def show @comment = Comment.new @timeline = timeline(@lead) respond_with(@lead) end |
#update ⇒ Object
PUT /leads/1
81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/entities/leads_controller.rb', line 81 def update respond_with(@lead) do |_format| # Must set access before user_ids, because user_ids= method depends on access value. @lead.access = resource_params[:access] if resource_params[:access] if @lead.update_with_lead_counters(resource_params) else @campaigns = Campaign.my(current_user).order('name') end end end |