Class: LeadsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- LeadsController
- Defined in:
- app/controllers/leads_controller.rb
Overview
Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.
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 —————————————————————————-.
-
#options ⇒ Object
GET /leads/options AJAX —————————————————————————-.
-
#promote ⇒ Object
PUT /leads/1/promote —————————————————————————-.
-
#redraw ⇒ Object
POST /leads/redraw AJAX —————————————————————————-.
-
#reject ⇒ Object
PUT /leads/1/reject —————————————————————————-.
-
#show ⇒ Object
GET /leads/1 —————————————————————————-.
-
#update ⇒ Object
PUT /leads/1 —————————————————————————-.
Methods inherited from BaseController
#attach, #auto_complete, #discard, #field_group, #tagged, #timeline
Methods inherited from ApplicationController
Instance Method Details
#convert ⇒ Object
GET /leads/1/convert
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/leads_controller.rb', line 130 def convert @lead = Lead.my.find(params[:id]) @users = User.except(@current_user) @account = Account.new(:user => @current_user, :name => @lead.company, :access => "Lead") @accounts = Account.my.order("name") @opportunity = Opportunity.new(:user => @current_user, :access => "Lead", :stage => "prospecting", :campaign => @lead.campaign, :source => @lead.source) if params[:previous].to_s =~ /(\d+)\z/ @previous = Lead.my.find($1) end respond_with(@lead) rescue ActiveRecord::RecordNotFound @previous ||= $1.to_i respond_to_not_found(:js, :json, :xml) unless @lead end |
#create ⇒ Object
POST /leads
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/leads_controller.rb', line 78 def create @lead = Lead.new(params[:lead]) @users = User.except(@current_user) @campaigns = Campaign.my.order("name") respond_with(@lead) do |format| if @lead.(params) if called_from_index_page? @leads = get_leads else (:campaign) end end end end |
#destroy ⇒ Object
DELETE /leads/1
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/leads_controller.rb', line 115 def destroy @lead = Lead.my.find(params[:id]) @lead.destroy if @lead respond_with(@lead) do |format| format.html { respond_to_destroy(:html) } format.js { respond_to_destroy(:ajax) } end rescue ActiveRecord::RecordNotFound respond_to_not_found(:html, :js, :json, :xml) end |
#edit ⇒ Object
GET /leads/1/edit AJAX
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/leads_controller.rb', line 62 def edit @lead = Lead.my.find(params[:id]) @users = User.except(@current_user) @campaigns = Campaign.my.order("name") if params[:previous].to_s =~ /(\d+)\z/ @previous = Lead.my.find($1) end respond_with(@lead) rescue ActiveRecord::RecordNotFound @previous ||= $1.to_i respond_to_not_found(:js) unless @lead end |
#filter ⇒ Object
POST /leads/filter AJAX
231 232 233 234 235 |
# File 'app/controllers/leads_controller.rb', line 231 def filter session[:filter_by_lead_status] = params[:status] @leads = get_leads(:page => 1) # Start one the first page. render :index end |
#index ⇒ Object
GET /leads
23 24 25 26 |
# File 'app/controllers/leads_controller.rb', line 23 def index @leads = get_leads(:page => params[:page]) respond_with(@leads) end |
#new ⇒ Object
GET /leads/new
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/leads_controller.rb', line 46 def new @lead = Lead.new(:user => @current_user, :access => Setting.default_access) @users = User.except(@current_user) @campaigns = Campaign.my.order("name") if params[:related] model, id = params[:related].split("_") instance_variable_set("@#{model}", model.classify.constantize.my.find(id)) end respond_with(@lead) rescue ActiveRecord::RecordNotFound # Kicks in if related asset was not found. (model, :js) if model end |
#options ⇒ Object
GET /leads/options AJAX
198 199 200 201 202 203 204 205 |
# File 'app/controllers/leads_controller.rb', line 198 def unless params[:cancel].true? @per_page = @current_user.pref[:leads_per_page] || Lead.per_page @outline = @current_user.pref[:leads_outline] || Lead.outline @sort_by = @current_user.pref[:leads_sort_by] || Lead.sort_by @naming = @current_user.pref[:leads_naming] || Lead.first_name_position end end |
#promote ⇒ Object
PUT /leads/1/promote
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/controllers/leads_controller.rb', line 148 def promote @lead = Lead.my.find(params[:id]) @users = User.except(@current_user) @account, @opportunity, @contact = @lead.promote(params) @accounts = Account.my.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 rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |
#redraw ⇒ Object
POST /leads/redraw AJAX
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/controllers/leads_controller.rb', line 209 def redraw @current_user.pref[:leads_per_page] = params[:per_page] if params[:per_page] @current_user.pref[:leads_outline] = params[:outline] if params[:outline] # 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]] if Contact::sort_by_fields.include?(params[:sort_by]) @current_user.pref[:contacts_sort_by] ||= Contact::sort_by_map[params[:sort_by]] end end if params[:naming] @current_user.pref[:leads_naming] = params[:naming] @current_user.pref[:contacts_naming] ||= params[:naming] end @leads = get_leads(:page => 1) # Start one the first page. render :index end |
#reject ⇒ Object
PUT /leads/1/reject
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/controllers/leads_controller.rb', line 171 def reject @lead = Lead.my.find(params[:id]) @lead.reject if @lead respond_with(@lead) do |format| format.html { flash[:notice] = t(:msg_asset_rejected, @lead.full_name); redirect_to leads_path } end rescue ActiveRecord::RecordNotFound respond_to_not_found(:html, :js, :json, :xml) end |
#show ⇒ Object
GET /leads/1
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/leads_controller.rb', line 30 def show @lead = Lead.my.find(params[:id]) respond_with(@lead) do |format| format.html do @comment = Comment.new @timeline = timeline(@lead) end end rescue ActiveRecord::RecordNotFound respond_to_not_found(:html, :json, :xml) end |
#update ⇒ Object
PUT /leads/1
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/leads_controller.rb', line 97 def update @lead = Lead.my.find(params[:id]) respond_with(@lead) do |format| if @lead.(params[:lead], params[:users]) else @users = User.except(@current_user) @campaigns = Campaign.my.order("name") end end rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |