Module: AccountsHelper

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

Instance Method Details

#account_category_checkbox(category, count) ⇒ Object

Sidebar checkbox control for filtering accounts by category.




9
10
11
# File 'app/helpers/accounts_helper.rb', line 9

def (category, count)
  entity_filter_checkbox(:category, category, count)
end

#account_select(options = {}) ⇒ Object

Generates a select list with the first 25 accounts and prepends the currently selected account, if any.




27
28
29
30
31
32
33
34
35
# File 'app/helpers/accounts_helper.rb', line 27

def (options = {})
  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),
                    :"data-url" => auto_complete_accounts_path(format: 'json'),
                    style: "width:330px; display:none;",
                    class: 'ajax_chosen'
end

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

Select an existing account or create a new one.


Yields:

  • (options)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/accounts_helper.rb', line 39

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(); return false;'>#{t :select_existing}</a>):".html_safe
      end +

      (:span, id: 'account_select_title') do
        "(<a href='#' onclick='crm.create_account(); return false;'>#{t :create_new}</a> #{t :or} #{t :select_existing}):".html_safe
      end +

      (:span, ':', id: 'account_disabled_title')
  end +

    (options) +
    form.text_field(:name, style: 'width:324px; display:none;')
end

#account_summary(account) ⇒ Object

Quick account summary for RSS/ATOM feeds.




15
16
17
18
19
20
21
22
# File 'app/helpers/accounts_helper.rb', line 15

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

#account_with_title_and_department(contact) ⇒ Object

Output account with title and department

  • a helper so it is easy to override in plugins that allow for several accounts




71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/accounts_helper.rb', line 71

def (contact)
  text = if !contact.title.blank? && contact.
           # works_at: "{{h(job_title)}} at {{h(company)}}"
            :div, t(:works_at, job_title: h(contact.title), company: h((contact))).html_safe
         elsif !contact.title.blank?
            :div, h(contact.title)
         elsif contact.
            :div, (contact)
         else
           ""
    end
  text << t(:department_small, h(contact.department)) unless contact.department.blank?
  text
end

#account_with_url_for(contact) ⇒ Object

Output account url for a given contact

  • a helper so it is easy to override in plugins that allow for several accounts




64
65
66
# File 'app/helpers/accounts_helper.rb', line 64

def (contact)
  contact. ? link_to(h(contact..name), (contact.)) : ""
end

#brief_account_info(contact) ⇒ Object

“title, department at Account name” used in index_brief and index_long

  • a helper so it is easy to override in plugins that allow for several accounts




89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/accounts_helper.rb', line 89

def (contact)
  text = ""
  title = contact.title
  department = contact.department
   = contact.
   = ""
   = link_to_if(can?(:read, ), h(.name), ()) if .present?

  text << if title.present? && department.present?
            t(:account_with_title_department, title: h(title), department: h(department), account: )
          elsif title.present?
            t(:account_with_title, title: h(title), account: )
          elsif department.present?
            t(:account_with_title, title: h(department), account: )
          elsif .present?
            t(:works_at, job_title: "", company: )
          else
            ""
      end
  text.html_safe
end