Class: AccountsController

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

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

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#createObject

POST /accounts




67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/entities/accounts_controller.rb', line 67

def create
  @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




94
95
96
97
98
99
100
101
# File 'app/controllers/entities/accounts_controller.rb', line 94

def destroy
  @account.destroy

  respond_with(@account) do |format|
    format.html { respond_to_destroy(:html) }
    format.js   { respond_to_destroy(:ajax) }
  end
end

#editObject

GET /accounts/1/edit AJAX




56
57
58
59
60
61
62
63
# File 'app/controllers/entities/accounts_controller.rb', line 56

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

  respond_with(@account)
end

#filterObject

POST /accounts/filter AJAX




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

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

#indexObject

GET /accounts




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

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

#newObject

GET /accounts/new




42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/entities/accounts_controller.rb', line 42

def new
  @account.attributes = {: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

#optionsObject

GET /accounts/options AJAX




117
118
119
120
121
122
123
# File 'app/controllers/entities/accounts_controller.rb', line 117

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




127
128
129
130
131
132
133
# File 'app/controllers/entities/accounts_controller.rb', line 127

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
# File 'app/controllers/entities/accounts_controller.rb', line 30

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

#updateObject

PUT /accounts/1




82
83
84
85
86
87
88
89
90
# File 'app/controllers/entities/accounts_controller.rb', line 82

def update
  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
end