Class: OpportunitiesController
- Inherits:
-
EntitiesController
- Object
- ActionController::Base
- ApplicationController
- EntitiesController
- OpportunitiesController
- Defined in:
- app/controllers/entities/opportunities_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 /opportunities —————————————————————————-.
-
#destroy ⇒ Object
DELETE /opportunities/1 —————————————————————————-.
-
#edit ⇒ Object
GET /opportunities/1/edit AJAX —————————————————————————-.
-
#filter ⇒ Object
POST /opportunities/filter AJAX —————————————————————————-.
-
#index ⇒ Object
GET /opportunities —————————————————————————-.
-
#new ⇒ Object
GET /opportunities/new —————————————————————————-.
-
#redraw ⇒ Object
GET /opportunities/redraw AJAX —————————————————————————-.
-
#show ⇒ Object
GET /opportunities/1 AJAX /opportunities/1 —————————————————————————-.
-
#update ⇒ Object
PUT /opportunities/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 /opportunities
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/entities/opportunities_controller.rb', line 67 def create @comment_body = params[:comment_body] respond_with(@opportunity) do |_format| if @opportunity.(params.permit!) @opportunity.add_comment_by_user(@comment_body, current_user) if called_from_index_page? @opportunities = get_opportunities elsif called_from_landing_page?(:accounts) (:account) elsif called_from_landing_page?(:campaigns) (:campaign) end else @accounts = Account.my(current_user).order('name') @account = (params[:account][:id], request.referer, current_user) @contact = Contact.find(params[:contact]) unless params[:contact].blank? @campaign = Campaign.find(params[:campaign]) unless params[:campaign].blank? end end end |
#destroy ⇒ Object
DELETE /opportunities/1
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/entities/opportunities_controller.rb', line 114 def destroy if called_from_landing_page?(:accounts) @account = @opportunity.account # Reload related account if any. elsif called_from_landing_page?(:campaigns) @campaign = @opportunity.campaign # Reload related campaign if any. end @opportunity.destroy respond_with(@opportunity) do |format| format.html { respond_to_destroy(:html) } format.js { respond_to_destroy(:ajax) } end end |
#edit ⇒ Object
GET /opportunities/1/edit AJAX
56 57 58 59 60 61 62 63 |
# File 'app/controllers/entities/opportunities_controller.rb', line 56 def edit @account = @opportunity.account || Account.new(user: current_user) @accounts = Account.my(current_user).order('name') @previous = Opportunity.my(current_user).find_by_id(detect_previous_id) || detect_previous_id if detect_previous_id respond_with(@opportunity) end |
#filter ⇒ Object
POST /opportunities/filter AJAX
153 154 155 156 157 158 |
# File 'app/controllers/entities/opportunities_controller.rb', line 153 def filter @opportunities = get_opportunities(page: 1, per_page: per_page_param) respond_with(@opportunities) do |format| format.js { render :index } end end |
#index ⇒ Object
GET /opportunities
15 16 17 18 19 20 21 22 |
# File 'app/controllers/entities/opportunities_controller.rb', line 15 def index @opportunities = get_opportunities(page: page_param, per_page: per_page_param) respond_with @opportunities do |format| format.xls { render layout: 'header' } format.csv { render csv: @opportunities } end end |
#new ⇒ Object
GET /opportunities/new
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/entities/opportunities_controller.rb', line 35 def new @opportunity.attributes = { user: current_user, stage: Opportunity.default_stage, access: Setting.default_access, assigned_to: nil } @account = Account.new(user: current_user, access: Setting.default_access) @accounts = Account.my(current_user).order('name') if params[:related] model, id = params[:related].split('_') if = model.classify.constantize.my(current_user).find_by_id(id) instance_variable_set("@#{model}", ) @account = .account if .respond_to?(:account) && !.account.nil? @campaign = .campaign if .respond_to?(:campaign) else (model) && return end end respond_with(@opportunity) end |
#redraw ⇒ Object
GET /opportunities/redraw AJAX
142 143 144 145 146 147 148 149 |
# File 'app/controllers/entities/opportunities_controller.rb', line 142 def redraw @opportunities = get_opportunities(page: 1, per_page: per_page_param) # Refresh options respond_with(@opportunities) do |format| format.js { render :index } end end |
#show ⇒ Object
GET /opportunities/1 AJAX /opportunities/1
27 28 29 30 31 |
# File 'app/controllers/entities/opportunities_controller.rb', line 27 def show @comment = Comment.new @timeline = timeline(@opportunity) respond_with(@opportunity) end |
#update ⇒ Object
PUT /opportunities/1
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/entities/opportunities_controller.rb', line 91 def update respond_with(@opportunity) do |_format| if @opportunity.(params.permit!) if called_from_index_page? elsif called_from_landing_page?(:accounts) (:account) elsif called_from_landing_page?(:campaigns) (:campaign) end else @accounts = Account.my(current_user).order('name') @account = if @opportunity.account Account.find(@opportunity.account.id) else Account.new(user: current_user) end end end end |