Module: PartyContactInfo
- Extended by:
- ActiveSupport::Concern
- Included in:
- Party
- Defined in:
- app/models/concerns/party_contact_info.rb
Overview
Email, phone, fax, and website accessors backed by ContactPoint records.
Instance Method Summary collapse
- #all_support_cases ⇒ Object
- #call_records? ⇒ Boolean (also: #has_call_records?)
- #cell_phone ⇒ Object
- #cell_phone=(value) ⇒ Object
- #cell_phone_formatted ⇒ Object
- #contact_point_options_for_select(category) ⇒ Object
- #contactable? ⇒ Boolean
- #email ⇒ Object
- #email=(value) ⇒ Object
- #email_options_for_select ⇒ Object
- #email_with_name ⇒ Object
- #emails ⇒ Object
- #fax ⇒ Object
- #fax=(value) ⇒ Object
- #fax_formatted ⇒ Object
- #fax_options_for_select ⇒ Object
- #first_callable_contact_point ⇒ Object
- #first_contact_point_by_category(category) ⇒ Object
- #phone ⇒ Object
- #phone=(value) ⇒ Object
- #phone_formatted ⇒ Object
- #phone_options_for_select ⇒ Object
- #set_email_from_account ⇒ Object
- #set_primary_contact_point(category, value) ⇒ Object
- #sms_enabled_numbers ⇒ Object
- #sms_messages ⇒ Object
- #tracking_email_address ⇒ Object
- #tracking_email_prefix ⇒ Object
- #website ⇒ Object
- #website=(value) ⇒ Object
- #website_options_for_select ⇒ Object
Instance Method Details
#all_support_cases ⇒ Object
10 11 12 |
# File 'app/models/concerns/party_contact_info.rb', line 10 def all_support_cases SupportCase.joins(support_case_participants: :party).where('parties.id = ? or parties.customer_id = ?', id, id).distinct end |
#call_records? ⇒ Boolean Also known as: has_call_records?
104 105 106 |
# File 'app/models/concerns/party_contact_info.rb', line 104 def call_records? CallRecord.party_records(id).present? end |
#cell_phone ⇒ Object
60 61 62 |
# File 'app/models/concerns/party_contact_info.rb', line 60 def cell_phone first_contact_point_by_category(ContactPoint::CELL)&.dial_string end |
#cell_phone=(value) ⇒ Object
68 69 70 |
# File 'app/models/concerns/party_contact_info.rb', line 68 def cell_phone=(value) set_primary_contact_point(ContactPoint::CELL, value) end |
#cell_phone_formatted ⇒ Object
64 65 66 |
# File 'app/models/concerns/party_contact_info.rb', line 64 def cell_phone_formatted first_contact_point_by_category(ContactPoint::CELL)&.formatted_dial_string end |
#contact_point_options_for_select(category) ⇒ Object
124 125 126 127 |
# File 'app/models/concerns/party_contact_info.rb', line 124 def (category) scope = category == :voice_callable ? contact_points.voice_callable : contact_points.by_category(category) scope.map { |cp| [cp.detail.to_s, cp.id] } end |
#contactable? ⇒ Boolean
92 93 94 |
# File 'app/models/concerns/party_contact_info.rb', line 92 def contactable? contact_points.contactable.present? || addresses.present? end |
#email ⇒ Object
18 19 20 21 22 |
# File 'app/models/concerns/party_contact_info.rb', line 18 def email # We use attributes email here in case the email was retrieved using a select custom append, # such as when loading guest in authenticable @email ||= attributes[:email] || first_contact_point_by_category(ContactPoint::EMAIL)&.detail end |
#email=(value) ⇒ Object
30 31 32 |
# File 'app/models/concerns/party_contact_info.rb', line 30 def email=(value) set_primary_contact_point(ContactPoint::EMAIL, value) end |
#email_options_for_select ⇒ Object
137 138 139 |
# File 'app/models/concerns/party_contact_info.rb', line 137 def (ContactPoint::EMAIL) end |
#email_with_name ⇒ Object
24 25 26 27 28 |
# File 'app/models/concerns/party_contact_info.rb', line 24 def email_with_name address = Mail::Address.new email address.display_name = name.dup address.format end |
#emails ⇒ Object
14 15 16 |
# File 'app/models/concerns/party_contact_info.rb', line 14 def emails contact_points.emails.reorder(:detail).distinct.pluck(:detail) end |
#fax ⇒ Object
34 35 36 37 |
# File 'app/models/concerns/party_contact_info.rb', line 34 def fax # primary_fax is sometime selected directly in advanced searches respond_to?(:primary_fax) ? primary_fax : first_contact_point_by_category(ContactPoint::FAX)&.dial_string end |
#fax=(value) ⇒ Object
43 44 45 |
# File 'app/models/concerns/party_contact_info.rb', line 43 def fax=(value) set_primary_contact_point(ContactPoint::FAX, value) end |
#fax_formatted ⇒ Object
39 40 41 |
# File 'app/models/concerns/party_contact_info.rb', line 39 def fax_formatted first_contact_point_by_category(ContactPoint::FAX)&.formatted_dial_string end |
#fax_options_for_select ⇒ Object
133 134 135 |
# File 'app/models/concerns/party_contact_info.rb', line 133 def (ContactPoint::FAX) end |
#first_callable_contact_point ⇒ Object
109 110 111 |
# File 'app/models/concerns/party_contact_info.rb', line 109 def first_callable_contact_point contact_points.voice_callable.sorted.first end |
#first_contact_point_by_category(category) ⇒ Object
113 114 115 |
# File 'app/models/concerns/party_contact_info.rb', line 113 def first_contact_point_by_category(category) contact_points.sorted.by_category(category).first end |
#phone ⇒ Object
47 48 49 50 |
# File 'app/models/concerns/party_contact_info.rb', line 47 def phone # primary_phone is sometime selected directly in advanced searches first_contact_point_by_category(ContactPoint::PHONE)&.dial_string end |
#phone=(value) ⇒ Object
56 57 58 |
# File 'app/models/concerns/party_contact_info.rb', line 56 def phone=(value) set_primary_contact_point(ContactPoint::PHONE, value) end |
#phone_formatted ⇒ Object
52 53 54 |
# File 'app/models/concerns/party_contact_info.rb', line 52 def phone_formatted first_contact_point_by_category(ContactPoint::PHONE)&.formatted_dial_string end |
#phone_options_for_select ⇒ Object
129 130 131 |
# File 'app/models/concerns/party_contact_info.rb', line 129 def (:voice_callable) end |
#set_email_from_account ⇒ Object
117 118 119 120 121 122 |
# File 'app/models/concerns/party_contact_info.rb', line 117 def set_email_from_account return unless account && account.email.present? return if contact_points.any? { |cp| cp.email? && cp.detail == account.email } contact_points.build(category: ContactPoint::EMAIL, detail: account.email) end |
#set_primary_contact_point(category, value) ⇒ Object
145 146 147 148 149 |
# File 'app/models/concerns/party_contact_info.rb', line 145 def set_primary_contact_point(category, value) cp = ContactPoint.build_from_string(value, contact_points, category) cp.move_to_top if cp&.persisted? cp end |
#sms_enabled_numbers ⇒ Object
96 97 98 |
# File 'app/models/concerns/party_contact_info.rb', line 96 def sms_enabled_numbers contact_points.sms_numbers.order(:detail).map(&:formatted_for_sms).uniq end |
#sms_messages ⇒ Object
100 101 102 |
# File 'app/models/concerns/party_contact_info.rb', line 100 def SmsMessage.for_numbers(sms_enabled_numbers) end |
#tracking_email_address ⇒ Object
82 83 84 85 86 |
# File 'app/models/concerns/party_contact_info.rb', line 82 def tracking_email_address domain = Rails.application.config.x.email_domain encrypted_id = Encryption.encrypt_string(id.to_s) "#{tracking_email_prefix}+id#{encrypted_id}@#{domain}" end |
#tracking_email_prefix ⇒ Object
88 89 90 |
# File 'app/models/concerns/party_contact_info.rb', line 88 def tracking_email_prefix type.to_s.downcase[0, 3] end |
#website ⇒ Object
72 73 74 75 76 |
# File 'app/models/concerns/party_contact_info.rb', line 72 def website first_contact_point_by_category(ContactPoint::WEBSITE).detail rescue StandardError nil end |
#website=(value) ⇒ Object
78 79 80 |
# File 'app/models/concerns/party_contact_info.rb', line 78 def website=(value) set_primary_contact_point(ContactPoint::WEBSITE, value) end |
#website_options_for_select ⇒ Object
141 142 143 |
# File 'app/models/concerns/party_contact_info.rb', line 141 def (ContactPoint::WEBSITE) end |