Module: Crm::SmsMessagesHelper

Defined in:
app/helpers/crm/sms_messages_helper.rb

Instance Method Summary collapse

Instance Method Details

#sms_message_command_options(sms_message) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
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 2

def sms_message_command_options(sms_message)
  links = []
  if can?(:update, sms_message)
    if sms_message.outbound?
      links << link_to(fa_icon('share', text: 'Resend'), resend_sms_message_path(sms_message, return_path: @return_path), data: { turbo_method: :post })

      if sms_message.draft?
        links << link_to(fa_icon('pen-to-square', text: 'Edit'), edit_sms_message_path(sms_message, return_path: @return_path))
      end
    end
  end
  if sms_message.inbound?
    links << link_to(fa_icon('reply', text: 'Reply'), new_sms_message_path(sms_message: { sender: sms_message.recipient,
                                                             sender_party_id: sms_message.recipient_party_id,
                                                             recipient: sms_message.sender,
                                                             recipient_party_id: sms_message.sender_party_id },
                                                             mark_as_read_sms_message_id: sms_message.id,
                                                             return_path: @return_path))
    links << link_to(fa_icon('envelope-open', text: (sms_message.unread ? 'Mark Read' : 'Mark Unread')),
                     toggle_unread_sms_message_path(sms_message, return_path: @return_path),
                     data: { turbo_method: :post }
                    )
    if sms_message.sender_blocked?
      links << link_to(fa_icon('check', text: 'Unblock Sender'), unblock_sender_sms_message_path(sms_message, return_path: @return_path), data: { turbo_method: :post })
    else
      links << link_to(fa_icon('ban', text: 'Block Sender'), block_sender_sms_message_path(sms_message, return_path: @return_path), data: { turbo_method: :post })
      if can?(:destroy, sms_message)
        links << link_to(fa_icon('ban', text: 'Delete and Block Sender'),
                        destroy_and_block_sender_sms_message_path(sms_message, 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 sms_message.inbound? && can?(:update, sms_message)
    links << link_to(fa_icon('share-from-square', text: 'Forward'),
                     forward_sms_message_path(sms_message, return_path: @return_path))
  end
  if can?(:destroy, sms_message)
    links << link_to(fa_icon('trash', text: 'Delete'), sms_message_path(sms_message, return_path: @return_path),
                data: { turbo_confirm: "Are you sure?", turbo_method: :delete })
  end
  links
end


81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/crm/sms_messages_helper.rb', line 81

def sms_message_recipient_link(sms_message)
  capture do
    if sms_message.recipient_do_not_text
      concat link_to(fa_icon('ban', class: 'text-danger'), do_not_call_path(sms_message.recipient_do_not_text))
      concat tag.del(link_to(number_to_phone(sms_message.recipient), sms_messages_path(q: { between_participants: [sms_message.recipient]})))
    else
      concat link_to(number_to_phone(sms_message.recipient), sms_messages_path(q: { between_participants: [sms_message.recipient]}))
    end
    if sms_message.recipient_party
      concat ''
      concat link_to(party_icon(sms_message.recipient_party), polymorphic_path(sms_message.recipient_party, tab: "sms"))
    end
  end
end


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/crm/sms_messages_helper.rb', line 63

def sms_message_sender_link(sms_message)
  capture do
    if sms_message.sender_do_not_text
      concat link_to(fa_icon('ban', class: 'text-danger'), do_not_call_path(sms_message.sender_do_not_text))
      concat tag.del(link_to(number_to_phone(sms_message.sender), sms_messages_path(q: { between_participants: [sms_message.sender]})))
    elsif sms_message.sender_blocked?
      concat fa_icon('ban', text: 'Sender Blocked', class: 'text-danger')
      concat tag.del(link_to(number_to_phone(sms_message.sender), sms_messages_path(q: { between_participants: [sms_message.sender]})))
    else
      concat link_to(number_to_phone(sms_message.sender), sms_messages_path(q: { between_participants: [sms_message.sender]}))
    end
    if sms_message.sender_party
      concat ''
      concat link_to(party_icon(sms_message.sender_party), polymorphic_path(sms_message.sender_party, tab: "sms"))
    end
  end
end

#sms_message_status_label(sms_message) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/crm/sms_messages_helper.rb', line 46

def sms_message_status_label(sms_message)
  label_class = { draft: 'light',
                  queued: 'warning',
                  sent: 'info',
                  delivered: 'success',
	              exception: 'danger',
                  received_queue: 'info',
                  received: 'info' }[sms_message.state.to_sym] || 'info'

  if sms_message.outbound?
    display_state = sms_message.human_state_name.upcase + fa_icon('arrow-right-long', class: 'ms-2')
  else
    display_state = fa_icon('arrow-left-long', class: 'me-2') + sms_message.human_state_name.upcase
  end
   :span, display_state.html_safe, class: "badge bg-#{label_class}"
end

#sms_participants_collectionObject



96
97
98
99
100
101
102
103
# File 'app/helpers/crm/sms_messages_helper.rb', line 96

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) || []).map(&:presence).compact.uniq
  unlisted_participants = filter_participant_collection - participant_collection.map(&:last)
  participant_collection += unlisted_participants.map{|n| [n,n]}
  participant_collection = participant_collection.map(&:presence).compact.uniq
end