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
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/entities/accounts_controller.rb', line 55 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
80 81 82 83 84 85 86 87 |
# File 'app/controllers/entities/accounts_controller.rb', line 80 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
45 46 47 48 49 50 51 |
# File 'app/controllers/entities/accounts_controller.rb', line 45 def edit if params[:previous].to_s =~ /(\d+)\z/ @previous = Account.my.find_by_id($1) || $1.to_i end respond_with(@account) end |
#filter ⇒ Object
POST /accounts/filter AJAX
116 117 118 119 120 121 122 123 |
# File 'app/controllers/entities/accounts_controller.rb', line 116 def filter session[:accounts_filter] = params[:category] @accounts = get_accounts(:page => 1, :per_page => params[:per_page]) respond_with(@accounts) do |format| format.js { render :index } end end |
#index ⇒ Object
GET /accounts
11 12 13 14 15 16 17 18 |
# File 'app/controllers/entities/accounts_controller.rb', line 11 def index @accounts = get_accounts(:page => params[:page], :per_page => params[:per_page]) respond_with @accounts do |format| format.xls { render :layout => 'header' } format.csv { render :csv => @accounts } end end |
#new ⇒ Object
GET /accounts/new
32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/entities/accounts_controller.rb', line 32 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
103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/entities/accounts_controller.rb', line 103 def redraw current_user.pref[:accounts_per_page] = params[:per_page] if params[:per_page] current_user.pref[:accounts_sort_by] = Account::sort_by_map[params[:sort_by]] if params[:sort_by] @accounts = get_accounts(:page => 1, :per_page => params[:per_page]) # Refresh options respond_with(@accounts) do |format| format.js { render :index } end end |
#show ⇒ Object
GET /accounts/1 AJAX /accounts/1
23 24 25 26 27 28 |
# File 'app/controllers/entities/accounts_controller.rb', line 23 def show @stage = Setting.unroll(:opportunity_stage) @comment = Comment.new @timeline = timeline(@account) respond_with(@account) end |
#update ⇒ Object
PUT /accounts/1
70 71 72 73 74 75 76 |
# File 'app/controllers/entities/accounts_controller.rb', line 70 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(params[:account]) end end |