Class: OpportunitiesController

Inherits:
EntitiesController show all
Defined in:
app/controllers/entities/opportunities_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

Methods inherited from EntitiesController

#attach, #contacts, #discard, #leads, #opportunities, #subscribe, #unsubscribe, #versions

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#createObject

POST /opportunities




77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/entities/opportunities_controller.rb', line 77

def create
  respond_with(@opportunity) do |format|
    if @opportunity.(params)
      if called_from_index_page?
        @opportunities = get_opportunities
        get_data_for_sidebar
      elsif called_from_landing_page?(:accounts)
        get_data_for_sidebar(:account)
      elsif called_from_landing_page?(:campaigns)
        get_data_for_sidebar(:campaign)
      end
    else
      @users = User.except(@current_user)
      @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

#destroyObject

DELETE /opportunities/1




132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/entities/opportunities_controller.rb', line 132

def destroy
  if called_from_landing_page?(:accounts)
    @account = @opportunity.   # 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

#editObject

GET /opportunities/1/edit AJAX




63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/entities/opportunities_controller.rb', line 63

def edit
  @users = User.except(@current_user)
  @account  = @opportunity. || 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

#filterObject

POST /opportunities/filter AJAX




177
178
179
180
# File 'app/controllers/entities/opportunities_controller.rb', line 177

def filter
  @opportunities = get_opportunities(:page => 1)
  render :index
end

#indexObject

GET /opportunities




25
26
27
28
# File 'app/controllers/entities/opportunities_controller.rb', line 25

def index
  @opportunities = get_opportunities(:page => params[:page])
  respond_with(@opportunities)
end

#newObject

GET /opportunities/new




43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/entities/opportunities_controller.rb', line 43

def new
  @opportunity.attributes = {:user => @current_user, :stage => "prospecting", :access => Setting.default_access}
  @users       = User.except(@current_user)
  @account     = Account.new(:user => @current_user, :access => Setting.default_access)
  @accounts    = Account.my.order('name')

  if params[:related]
    model, id = params[:related].split('_')
    if related = model.classify.constantize.my.find_by_id(id)
      instance_variable_set("@#{model}", related)
    else
      respond_to_related_not_found(model) and return
    end
  end

  respond_with(@opportunity)
end

#optionsObject

GET /opportunities/options AJAX




160
161
162
163
164
165
166
# File 'app/controllers/entities/opportunities_controller.rb', line 160

def options
  unless params[:cancel].true?
    @per_page = @current_user.pref[:opportunities_per_page] || Opportunity.per_page
    @outline  = @current_user.pref[:opportunities_outline]  || Opportunity.outline
    @sort_by  = @current_user.pref[:opportunities_sort_by]  || Opportunity.sort_by
  end
end

#redrawObject

POST /opportunities/redraw AJAX




170
171
172
173
# File 'app/controllers/entities/opportunities_controller.rb', line 170

def redraw
  @opportunities = get_opportunities(:page => 1)
  render :index
end

#showObject

GET /opportunities/1




32
33
34
35
36
37
38
39
# File 'app/controllers/entities/opportunities_controller.rb', line 32

def show
  respond_with(@opportunity) do |format|
    format.html do
      @comment = Comment.new
      @timeline = timeline(@opportunity)
    end
  end
end

#updateObject

PUT /opportunities/1




108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/entities/opportunities_controller.rb', line 108

def update
  respond_with(@opportunity) do |format|
    if @opportunity.(params)
      if called_from_index_page?
        get_data_for_sidebar
      elsif called_from_landing_page?(:accounts)
        get_data_for_sidebar(:account)
      elsif called_from_landing_page?(:campaigns)
        get_data_for_sidebar(:campaign)
      end
    else
      @users = User.except(@current_user)
      @accounts = Account.my.order('name')
      if @opportunity.
        @account = Account.find(@opportunity..id)
      else
        @account = Account.new(:user => @current_user)
      end
    end
  end
end