Module: ContactsHelper

Defined in:
app/helpers/contacts_helper.rb

Overview

View helper: contacts.

Instance Method Summary collapse

Instance Method Details

#build_contact_party_hash(contact) ⇒ Object



13
14
15
16
17
18
# File 'app/helpers/contacts_helper.rb', line 13

def build_contact_party_hash(contact)
  parties_hash = {}
  parties_hash[contact.full_name.to_s] = contact
  parties_hash["#{contact.customer.full_name} (Customer)"] = { party: contact.customer, collapsed: false } if contact.customer
  parties_hash
end

#contact_command_options(contact) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/contacts_helper.rb', line 47

def contact_command_options(contact)
  [].tap do |links|
    links << link_to(fa_icon('wrench', text: 'Edit'), edit_contact_path(contact))
    # Lead Enrichment is manager-only while it's in pilot — same gate
    # as the Customer-side entry in customers_helper.rb.
    if contact.enrichable_via_research? && &.is_manager?
      links << link_to(fa_icon('wand-magic-sparkles', text: 'Enrich'),
                       new_contact_party_research_run_path(contact),
                       data: { turbo_frame: '_top' })
    end
    links << link_to('Restore', restore_contact_path(contact), data: { turbo_method: :put }) if contact.customer && contact.inactive?
    links << if contact.open_support_case_participant?
               { content: 'Cannot be deactivated because it is a participant of an open support case.', class: 'dropdown-item-text text-muted' }
             else
               confirm_message = if contact.ok_to_delete?
                                   'Are you sure? This action will permanently delete the contact.'
                                 elsif contact.support_case_participant?
                                   'This contact is a support case participant and cannot be deleted. It will be marked as inactive and the contact login (if any) will be removed.'
                                 else
                                   'Are you sure? This action will mark the contact as inactive and remove the contact login (if any). It will also unassign any open opportunities, orders or services assigned to this contact.'
                                 end
               link_to(fa_icon('trash', text: (contact.ok_to_delete? ? 'Delete' : 'Deactivate')),
                       contact_path(contact),
                       data: { turbo_confirm: confirm_message, turbo_method: :delete })
             end
  end
end


37
38
39
40
# File 'app/helpers/contacts_helper.rb', line 37

def contact_multiple_visits_link(contact, most_recent)
  display_text = "#{contact.visits.size} visit(s) (Last was #{time_ago_in_words(most_recent.started_at)} ago)"
  link_to(fa_icon('magnifying-glass-plus', text: display_text), contact_visits_path(contact))
end

#contact_quick_info(contact) ⇒ Object



20
21
22
23
24
# File 'app/helpers/contacts_helper.rb', line 20

def contact_quick_info(contact)
  info = []
  info << fa_icon('user-tie', text: contact.customer.primary_sales_rep.name_and_extension, title: 'Primary Sales Rep') if contact.customer.respond_to?(:primary_sales_rep) && contact.customer.primary_sales_rep
  info
end


42
43
44
45
# File 'app/helpers/contacts_helper.rb', line 42

def contact_single_visit_link(most_recent)
  display_text = "#{time_ago_in_words(most_recent.started_at)} ago"
  link_to(fa_icon('magnifying-glass-plus', text: display_text), visit_path(most_recent))
end

#contact_tab_options(contact = @contact) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/contacts_helper.rb', line 75

def contact_tab_options(contact = @contact)
  hsh = {}
  hsh[:main] = { remote_href: tab_main_contact_path(contact) }
  hsh[:contacts] = { remote_href: tab_contacts_contact_path(contact) }
  hsh[:activities] = { counter: contact.open_activities_counter, remote_href: contact_activities_path(contact, selected_activity: params[:selected_activity]) }
  hsh[:communications] = { remote_href: contact_communications_path(contact) }
  hsh[:sms] = { remote_href: contact_sms_messages_path(contact), counter: contact.sms_messages.where(unread: true).size }

  unless contact.supplier_contact?
    hsh[:opportunities] = { counter: contact.all_opportunities.open_opportunities.size,
                            remote_href: contact_opportunities_path(contact) }
  end
  hsh[:tickets] = { title: 'Tickets',
                    counter_html: tech_counter_badge(contact.support_cases),
                    remote_href: tab_tickets_contact_path(contact) }
  hsh[:attachments] = { counter: contact.all_uploads.size, remote_href: contact_uploads_path(contact) }
  if contact.customer && !contact.supplier_contact?
    hsh[:topics] = { remote_href: tab_profiling_contact_path(contact) }
    hsh[:training] = { remote_href: tab_training_contact_path(contact) }
    hsh[:certifications] = { remote_href: tab_certifications_contact_path(contact) }
    hsh[:orders] = { counter: contact.orders.non_credit.in_progress.size, remote_href: contact_orders_path(contact) }
    hsh[:orders_spiff] = { remote_href: tab_orders_spiff_contact_path(contact) }
    hsh[:merge] = { remote_href: tab_merge_contact_path(contact) }
  end
  hsh[:digital_assets] = { counter: contact.digital_assets.size, remote_href: tab_digital_assets_contact_path(contact) }
  hsh
end


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

def contact_visits_link(contact)
  most_recent = contact.visits.order(:started_at).reverse_order.first
  return '-' unless most_recent

  if contact.visits.size > 1
    contact_multiple_visits_link(contact, most_recent)
  else
    contact_single_visit_link(most_recent)
  end
end

#render_contact_info_bar(contact, role: nil, note: nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/helpers/contacts_helper.rb', line 103

def render_contact_info_bar(contact, role: nil, note: nil)
  list = []
  list << fa_icon('building', text: contact.customer.full_name) if contact.is_a?(Contact) && contact.customer

  list << fa_icon('diagram-project', text: role, title: 'Project Role') if role.present?

  list << fa_icon('user-tag', text: contact.job_title, title: 'Job Title') if contact.job_title.present? && contact.job_title != role

  list << fa_icon('note-sticky', text: note) if note.present?

  return if list.blank?

  (:ul, list.map { |e| (:span, e, class: 'text-muted me-2') }.join.html_safe, class: 'list-unstyled')
end

#setup_contact(contact) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/contacts_helper.rb', line 4

def setup_contact(contact)
  contact.tap do |c|
    c.contact_points.build({ category: ContactPoint::PHONE }) if c.contact_points.find_by(category: ContactPoint::PHONE).nil?
    c.contact_points.build({ category: ContactPoint::CELL }) if c.contact_points.find_by(category: ContactPoint::CELL).nil?
    c.contact_points.build({ category: ContactPoint::FAX }) if c.contact_points.find_by(category: ContactPoint::FAX).nil?
    c.contact_points.build({ category: ContactPoint::EMAIL }) if c.contact_points.find_by(category: ContactPoint::EMAIL).nil?
  end
end