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
POST /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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/entities/opportunities_controller.rb', line 66 def create @comment_body = params[:comment_body] respond_with(@opportunity) do |format| if @opportunity.(params) @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.order('name') unless params[:account][:id].blank? @account = Account.find(params[:account][:id]) else if request.referer =~ /\/accounts\/(.+)$/ @account = Account.find($1) # related account else @account = Account.new(:user => current_user) end end @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
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/entities/opportunities_controller.rb', line 121 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
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/entities/opportunities_controller.rb', line 53 def edit @account = @opportunity.account || Account.new(:user => current_user) @accounts = Account.my.order('name') if params[:previous].to_s =~ /(\d+)\z/ @previous = Opportunity.my.find_by_id($1) || $1.to_i end respond_with(@opportunity) end |
#filter ⇒ Object
POST /opportunities/filter AJAX
160 161 162 163 164 165 |
# File 'app/controllers/entities/opportunities_controller.rb', line 160 def filter @opportunities = get_opportunities(:page => 1, :per_page => params[:per_page]) respond_with(@opportunities) do |format| format.js { render :index } end end |
#index ⇒ Object
GET /opportunities
13 14 15 16 17 18 19 20 |
# File 'app/controllers/entities/opportunities_controller.rb', line 13 def index @opportunities = get_opportunities(:page => params[:page], :per_page => params[:per_page]) respond_with @opportunities do |format| format.xls { render :layout => 'header' } format.csv { render :csv => @opportunities } end end |
#new ⇒ Object
GET /opportunities/new
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/entities/opportunities_controller.rb', line 33 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.order('name') if params[:related] model, id = params[:related].split('_') if = model.classify.constantize.my.find_by_id(id) instance_variable_set("@#{model}", ) @account = .account if .respond_to?(:account) else (model) and return end end respond_with(@opportunity) end |
#redraw ⇒ Object
POST /opportunities/redraw AJAX
149 150 151 152 153 154 155 156 |
# File 'app/controllers/entities/opportunities_controller.rb', line 149 def redraw @opportunities = get_opportunities(:page => 1, :per_page => params[:per_page]) # Refresh options respond_with(@opportunities) do |format| format.js { render :index } end end |
#show ⇒ Object
GET /opportunities/1 AJAX /opportunities/1
25 26 27 28 29 |
# File 'app/controllers/entities/opportunities_controller.rb', line 25 def show @comment = Comment.new @timeline = timeline(@opportunity) respond_with(@opportunity) end |
#update ⇒ Object
PUT /opportunities/1
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/entities/opportunities_controller.rb', line 98 def update respond_with(@opportunity) do |format| if @opportunity.(params) if called_from_index_page? elsif called_from_landing_page?(:accounts) (:account) elsif called_from_landing_page?(:campaigns) (:campaign) end else @accounts = Account.my.order('name') if @opportunity.account @account = Account.find(@opportunity.account.id) else @account = Account.new(:user => current_user) end end end end |