Class: LeadsController
- Inherits:
-
EntitiesController
- Object
- ActionController::Base
- ApplicationController
- EntitiesController
- LeadsController
- Defined in:
- app/controllers/entities/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 EntitiesController
#attach, #contacts, #discard, #leads, #opportunities, #subscribe, #unsubscribe, #versions
Methods inherited from ApplicationController
Instance Method Details
#convert ⇒ Object
GET /leads/1/convert
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/entities/leads_controller.rb', line 115 def convert @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_by_id($1) || $1.to_i end respond_with(@lead) end |
#create ⇒ Object
POST /leads
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/entities/leads_controller.rb', line 73 def create @users = User.except(@current_user) get_campaigns 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
104 105 106 107 108 109 110 111 |
# File 'app/controllers/entities/leads_controller.rb', line 104 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
60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/entities/leads_controller.rb', line 60 def edit @users = User.except(@current_user) get_campaigns if params[:previous].to_s =~ /(\d+)\z/ @previous = Lead.my.find_by_id($1) || $1.to_i end respond_with(@lead) end |
#filter ⇒ Object
POST /leads/filter AJAX
205 206 207 208 209 |
# File 'app/controllers/entities/leads_controller.rb', line 205 def filter session[:leads_filter] = 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/entities/leads_controller.rb', line 23 def index @leads = get_leads(:page => params[:page]) respond_with(@leads) end |
#new ⇒ Object
GET /leads/new
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/entities/leads_controller.rb', line 41 def new @lead.attributes = {:user => @current_user, :access => Setting.default_access} @users = User.except(@current_user) get_campaigns if params[:related] model, id = params[:related].split('_') if = model.classify.constantize.my.find_by_id(id) instance_variable_set("@#{model}", ) else (model) and return end end respond_with(@lead) end |
#options ⇒ Object
GET /leads/options AJAX
172 173 174 175 176 177 178 179 |
# File 'app/controllers/entities/leads_controller.rb', line 172 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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/controllers/entities/leads_controller.rb', line 130 def promote @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 end |
#redraw ⇒ Object
POST /leads/redraw AJAX
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/controllers/entities/leads_controller.rb', line 183 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
149 150 151 152 153 154 155 156 |
# File 'app/controllers/entities/leads_controller.rb', line 149 def reject @lead.reject respond_with(@lead) do |format| format.html { flash[:notice] = t(:msg_asset_rejected, @lead.full_name); redirect_to leads_path } end end |
#show ⇒ Object
GET /leads/1
30 31 32 33 34 35 36 37 |
# File 'app/controllers/entities/leads_controller.rb', line 30 def show respond_with(@lead) do |format| format.html do @comment = Comment.new @timeline = timeline(@lead) end end end |