Class: AccountsController

Inherits:
BaseController show all
Defined in:
app/controllers/accounts_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 BaseController

#attach, #auto_complete, #discard, #field_group, #tagged, #timeline

Methods inherited from ApplicationController

#klass

Instance Method Details

#contactsObject

GET /accounts/contacts AJAX




155
156
157
# File 'app/controllers/accounts_controller.rb', line 155

def contacts
  @account = Account.my.find(params[:id])
end

#createObject

POST /accounts




75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/accounts_controller.rb', line 75

def create
  @account = Account.new(params[:account])
  @users = User.except(@current_user)

  respond_with(@account) do |format|
    if @account.save_with_permissions(params[:users])
      # None: account can only be created from the Accounts index page, so we
      # don't have to check whether we're on the index page.
      @accounts = get_accounts
      get_data_for_sidebar
    end
  end
end

#destroyObject

DELETE /accounts/1




108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/accounts_controller.rb', line 108

def destroy
  @account = Account.my.find(params[:id])
  @account.destroy if @account

  respond_with(@account) 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

#editObject

GET /accounts/1/edit AJAX




60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/accounts_controller.rb', line 60

def edit
  @account = Account.my.find(params[:id])
  @users = User.except(@current_user)
  if params[:previous].to_s =~ /(\d+)\z/
    @previous = Account.my.find($1)
  end
  respond_with(@account)

rescue ActiveRecord::RecordNotFound
  @previous ||= $1.to_i
  respond_to_not_found(:js) unless @account
end

#filterObject

POST /accounts/filter AJAX




167
168
169
170
171
# File 'app/controllers/accounts_controller.rb', line 167

def filter
  session[:filter_by_account_category] = params[:category]
  @accounts = get_accounts(:page => 1)
  render :index
end

#indexObject

GET /accounts




23
24
25
26
# File 'app/controllers/accounts_controller.rb', line 23

def index
  @accounts = get_accounts(:page => params[:page])
  respond_with(@accounts)
end

#newObject

GET /accounts/new




47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/accounts_controller.rb', line 47

def new
  @account = Account.new(:user => @current_user, :access => Setting.default_access)
  @users = User.except(@current_user)
  if params[:related]
    model, id = params[:related].split("_")
    instance_variable_set("@#{model}", model.classify.constantize.find(id))
  end

  respond_with(@account)
end

#opportunitiesObject

GET /accounts/opportunities AJAX




161
162
163
# File 'app/controllers/accounts_controller.rb', line 161

def opportunities
  @account = Account.my.find(params[:id])
end

#optionsObject

GET /accounts/options AJAX




135
136
137
138
139
140
141
# File 'app/controllers/accounts_controller.rb', line 135

def options
  unless params[:cancel].true?
    @per_page = @current_user.pref[:accounts_per_page] || Account.per_page
    @outline  = @current_user.pref[:accounts_outline]  || Account.outline
    @sort_by  = @current_user.pref[:accounts_sort_by]  || Account.sort_by
  end
end

#redrawObject

POST /accounts/redraw AJAX




145
146
147
148
149
150
151
# File 'app/controllers/accounts_controller.rb', line 145

def redraw
  @current_user.pref[:accounts_per_page] = params[:per_page] if params[:per_page]
  @current_user.pref[:accounts_outline]  = params[:outline]  if params[:outline]
  @current_user.pref[:accounts_sort_by]  = Account::sort_by_map[params[:sort_by]] if params[:sort_by]
  @accounts = get_accounts(:page => 1)
  render :index
end

#showObject

GET /accounts/1




30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/accounts_controller.rb', line 30

def show
  @account = Account.my.find(params[:id])

  respond_with(@account) do |format|
    format.html do
      @stage = Setting.unroll(:opportunity_stage)
      @comment = Comment.new
      @timeline = timeline(@account)
    end
  end

rescue ActiveRecord::RecordNotFound
  respond_to_not_found(:html, :json, :xml)
end

#updateObject

PUT /accounts/1




91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/accounts_controller.rb', line 91

def update
  @account = Account.my.find(params[:id])

  respond_with(@account) do |format|
    if @account.update_with_permissions(params[:account], params[:users])
      get_data_for_sidebar
    else
      @users = User.except(@current_user) # Need it to redraw [Edit Account] form.
    end
  end

rescue ActiveRecord::RecordNotFound
  respond_to_not_found(:js, :json, :xml)
end