Module: AccountsHelper

Defined in:
app/helpers/accounts_helper.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

Instance Method Details

#account_category_checbox(category, count) ⇒ Object

Sidebar checkbox control for filtering accounts by category.




22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/accounts_helper.rb', line 22

def (category, count)
  checked = (session[:accounts_filter] ? session[:accounts_filter].split(",").include?(category.to_s) : count.to_i > 0)
  onclick = remote_function(
    :url      => { :action => :filter },
    :with     => h(%Q/"category=" + $$("input[name='category[]']").findAll(function (el) { return el.checked }).pluck("value")/),
    :loading  => "$('loading').show()",
    :complete => "$('loading').hide()"
  )
  check_box_tag("category[]", category, checked, :id => category, :onclick => onclick)
end

#account_select(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/helpers/accounts_helper.rb', line 44

def (options = {})
    # Generates a select list with the first 25 accounts,
    # and prepends the currently selected account, if available
    options[:selected] = (@account && @account.id) || 0
    accounts = ([@account] + Account.my.order(:name).limit(25)).compact.uniq
    collection_select :account, :id, accounts, :id, :name, options,
                      {:"data-placeholder" => t(:select_an_account),
                       :style => "width:330px; display:none;" }
end

#account_select_or_create(form) {|options| ... } ⇒ Object

Select an existing account or create a new one.


Yields:

  • (options)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/accounts_helper.rb', line 56

def (form, &block)
  options = {}
  yield options if block_given?
  
  (:div, :class => 'label') do
    t(:account).html_safe +
  
    (:span, :id => 'account_create_title') do
      "(#{t :create_new} #{t :or} <a href='#' onclick='crm.select_account(1); return false;'>#{t :select_existing}</a>):".html_safe
    end.html_safe +
  
    (:span, :id => 'account_select_title') do
      "(<a href='#' onclick='crm.create_account(1); return false;'>#{t :create_new}</a> #{t :or} #{t :select_existing}):".html_safe
    end.html_safe +
  
    (:span, ':', :id => 'account_disabled_title').html_safe
  end.html_safe +
  
  (options).html_safe +
  form.text_field(:name, :style => 'width:324px; display:none;')
end

#account_summary(account) ⇒ Object

Quick account summary for RSS/ATOM feeds.




35
36
37
38
39
40
41
42
# File 'app/helpers/accounts_helper.rb', line 35

def ()
  [ number_to_currency(.opportunities.pipeline.map(&:weighted_amount).sum, :precision => 0),
    t(:added_by, :time_ago => time_ago_in_words(.created_at), :user => .user_id_full_name),
    t('pluralize.contact', .contacts.count),
    t('pluralize.opportunity', .opportunities.count),
    t('pluralize.comment', .comments.count)
  ].join(', ')
end