Module: Crm::SmsMessagesHelper
- Defined in:
- app/helpers/crm/sms_messages_helper.rb
Overview
View helpers for the CRM SMS message screens: action links, status badges,
sender/recipient links, and the participant filter collection.
Instance Method Summary collapse
-
#sms_message_command_options(sms_message) ⇒ Array<String>
Builds the action links available for an SMS message (resend, edit, block/unblock sender, forward, delete), filtered by direction and ability.
-
#sms_message_recipient_link(sms_message) ⇒ String
Renders the recipient's phone number as a link to the filtered message list, flagged when the recipient is do-not-text, plus a link to the associated party when present.
-
#sms_message_sender_link(sms_message) ⇒ String
Renders the sender's phone number as a link to the filtered message list, flagged when the sender is do-not-text or blocked, plus a link to the associated party when present.
-
#sms_message_status_label(sms_message) ⇒ String
Renders a colored Bootstrap badge for an SMS message state, with a direction arrow and the exception reason as tooltip when applicable.
-
#sms_participants_collection ⇒ Array<Array(String, String)>
Builds the select collection of SMS participants: global numbers plus active employee numbers, extended with any numbers already selected via the current filter params.
Instance Method Details
#sms_message_command_options(sms_message) ⇒ Array<String>
Builds the action links available for an SMS message (resend, edit,
block/unblock sender, forward, delete), filtered by direction and ability.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/crm/sms_messages_helper.rb', line 13 def () links = [] if can?(:update, ) if .outbound? links << link_to(fa_icon('share', text: 'Resend'), (, return_path: @return_path)) links << link_to(fa_icon('pen-to-square', text: 'Edit'), (, return_path: @return_path)) if .draft? end end if .inbound? # Reply and mark read/unread live inline in the thread now — not here. if .sender_blocked? links << link_to(fa_icon('check', text: 'Unblock Sender'), (, return_path: @return_path), data: { turbo_method: :post }) else links << link_to(fa_icon('ban', text: 'Block Sender'), (, return_path: @return_path), data: { turbo_method: :post }) if can?(:destroy, ) links << link_to(fa_icon('ban', text: 'Delete and Block Sender'), (, return_path: @return_path), data: { turbo_confirm: 'Are you sure? this will delete this message and block sender', turbo_method: :delete }) end end end if .inbound? && can?(:update, ) links << link_to(fa_icon('share-from-square', text: 'Forward'), (, return_path: @return_path)) end if can?(:destroy, ) links << link_to(fa_icon('trash', text: 'Delete'), (, return_path: @return_path), data: { turbo_confirm: "Are you sure?", turbo_method: :delete }) end links end |
#sms_message_recipient_link(sms_message) ⇒ String
Renders the recipient's phone number as a link to the filtered message
list, flagged when the recipient is do-not-text, plus a link to the
associated party when present.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/helpers/crm/sms_messages_helper.rb', line 99 def () capture do if .recipient_do_not_text concat link_to(fa_icon('ban', class: 'text-danger'), do_not_call_path(.recipient_do_not_text)) concat tag.del(link_to(number_to_phone(.recipient), (q: { between_participants: [.recipient] }))) else concat link_to(number_to_phone(.recipient), (q: { between_participants: [.recipient] })) end if .recipient_party concat ' • ' concat link_to(party_icon(.recipient_party), polymorphic_path(.recipient_party, tab: "sms")) end end end |
#sms_message_sender_link(sms_message) ⇒ String
Renders the sender's phone number as a link to the filtered message list,
flagged when the sender is do-not-text or blocked, plus a link to the
associated party when present.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/crm/sms_messages_helper.rb', line 75 def () capture do if .sender_do_not_text concat link_to(fa_icon('ban', class: 'text-danger'), do_not_call_path(.sender_do_not_text)) concat tag.del(link_to(number_to_phone(.sender), (q: { between_participants: [.sender] }))) elsif .sender_blocked? concat fa_icon('ban', text: 'Sender Blocked', class: 'text-danger') concat tag.del(link_to(number_to_phone(.sender), (q: { between_participants: [.sender] }))) else concat link_to(number_to_phone(.sender), (q: { between_participants: [.sender] })) end if .sender_party concat ' • ' concat link_to(party_icon(.sender_party), polymorphic_path(.sender_party, tab: "sms")) end end end |
#sms_message_status_label(sms_message) ⇒ String
Renders a colored Bootstrap badge for an SMS message state, with a
direction arrow and the exception reason as tooltip when applicable.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/crm/sms_messages_helper.rb', line 51 def () label_class = { draft: 'light', queued: 'warning', sent: 'info', delivered: 'success', exception: 'danger', received_queue: 'info', received: 'info' }[.state.to_sym] || 'info' display_state = if .outbound? .human_state_name.upcase + fa_icon('arrow-right-long', class: 'ms-2') else fa_icon('arrow-left-long', class: 'me-2') + .human_state_name.upcase end content_tag :span, display_state.html_safe, class: "badge bg-#{label_class}", title: .exception? ? .exception_reason : nil end |
#sms_participants_collection ⇒ Array<Array(String, String)>
Builds the select collection of SMS participants: global numbers plus
active employee numbers, extended with any numbers already selected via
the current filter params.
119 120 121 122 123 124 125 126 |
# File 'app/helpers/crm/sms_messages_helper.rb', line 119 def sms_participants_collection # Create the participant collection based on passed in filters combined with our employee sms numbers participant_collection = SmsMessage.global_numbers_for_select + Employee.all_active_employees_sms_numbers(format_for_select: true) filter_participant_collection = (params.dig(:q, :recipient_or_sender_in) || []).filter_map(&:presence).uniq unlisted_participants = filter_participant_collection - participant_collection.map(&:last) participant_collection += unlisted_participants.map { |n| [n, n] } participant_collection.filter_map(&:presence).uniq end |