Class: AccountsController
- Inherits:
-
EntitiesController
- Object
- ActionController::Base
- ApplicationController
- EntitiesController
- AccountsController
- Defined in:
- app/controllers/entities/accounts_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 /accounts —————————————————————————-.
-
#destroy ⇒ Object
DELETE /accounts/1 —————————————————————————-.
-
#edit ⇒ Object
GET /accounts/1/edit AJAX —————————————————————————-.
-
#filter ⇒ Object
POST /accounts/filter AJAX —————————————————————————-.
-
#index ⇒ Object
GET /accounts —————————————————————————-.
-
#new ⇒ Object
GET /accounts/new —————————————————————————-.
-
#redraw ⇒ Object
GET /accounts/redraw AJAX —————————————————————————-.
-
#show ⇒ Object
GET /accounts/1 AJAX /accounts/1 —————————————————————————-.
-
#update ⇒ Object
PUT /accounts/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 /accounts
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/entities/accounts_controller.rb', line 57 def create @comment_body = params[:comment_body] respond_with(@account) do |_format| if @account.save @account.add_comment_by_user(@comment_body, current_user) # 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 end end end |
#destroy ⇒ Object
DELETE /accounts/1
82 83 84 85 86 87 88 89 |
# File 'app/controllers/entities/accounts_controller.rb', line 82 def destroy @account.destroy respond_with(@account) do |format| format.html { respond_to_destroy(:html) } format.js { respond_to_destroy(:ajax) } end end |
#edit ⇒ Object
GET /accounts/1/edit AJAX
47 48 49 50 51 52 53 |
# File 'app/controllers/entities/accounts_controller.rb', line 47 def edit if params[:previous].to_s =~ /(\d+)\z/ @previous = Account.my(current_user).find_by_id(Regexp.last_match[1]) || Regexp.last_match[1].to_i end respond_with(@account) end |
#filter ⇒ Object
POST /accounts/filter AJAX
118 119 120 121 122 123 124 125 |
# File 'app/controllers/entities/accounts_controller.rb', line 118 def filter session[:accounts_filter] = params[:category] @accounts = get_accounts(page: 1, per_page: per_page_param) respond_with(@accounts) do |format| format.js { render :index } end end |
#index ⇒ Object
GET /accounts
13 14 15 16 17 18 19 20 |
# File 'app/controllers/entities/accounts_controller.rb', line 13 def index @accounts = get_accounts(page: page_param, per_page: per_page_param) respond_with @accounts do |format| format.xls { render layout: 'header' } format.csv { render csv: @accounts } end end |
#new ⇒ Object
GET /accounts/new
34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/entities/accounts_controller.rb', line 34 def new @account.attributes = { user: current_user, access: Setting.default_access, assigned_to: nil } if params[:related] model, id = params[:related].split('_') instance_variable_set("@#{model}", model.classify.constantize.find(id)) end respond_with(@account) end |
#redraw ⇒ Object
GET /accounts/redraw AJAX
105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/entities/accounts_controller.rb', line 105 def redraw current_user.pref[:accounts_per_page] = per_page_param if per_page_param current_user.pref[:accounts_sort_by] = Account.sort_by_map[params[:sort_by]] if params[:sort_by] @accounts = get_accounts(page: 1, per_page: per_page_param) # Refresh options respond_with(@accounts) do |format| format.js { render :index } end end |
#show ⇒ Object
GET /accounts/1 AJAX /accounts/1
25 26 27 28 29 30 |
# File 'app/controllers/entities/accounts_controller.rb', line 25 def show @stage = Setting.unroll(:opportunity_stage) @comment = Comment.new @timeline = timeline(@account) respond_with(@account) end |
#update ⇒ Object
PUT /accounts/1
72 73 74 75 76 77 78 |
# File 'app/controllers/entities/accounts_controller.rb', line 72 def update respond_with(@account) do |_format| # Must set access before user_ids, because user_ids= method depends on access value. @account.access = params[:account][:access] if params[:account][:access] if @account.update_attributes(resource_params) end end |