Module: Crm::WorkflowsHelper

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

Instance Method Summary collapse

Instance Method Details



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/crm/workflows_helper.rb', line 7

def available_events_links(context_object, link_options = {}, confirm_options = {}, exclude_events = [], parent_object = nil)
  link_options = link_options.dup # Ensures we only operate on a copy
  include_link_icon = link_options.delete(:include_link_icon).to_b
  return_path = link_options.delete(:return_path)

  available_events = possible_events(context_object)
  available_events.map do |evt|
    next if exclude_events.include?(evt.to_s)

    data_options = {}
    data_options = { turbo_confirm: confirm_options[:prompt] } if confirm_options[:event] and confirm_options[:event] == evt
    link_title = include_link_icon ? fa_icon('right-to-bracket', text: evt.to_s.titleize) : evt.to_s.titleize
    link_to(link_title.html_safe,
            polymorphic_path([:workflow_action, *([parent_object, context_object].compact)], wf_action: evt.to_s, return_path:),
            class: 'state_machine_event',
            title: context_object.try(:event_description, evt),
            data: data_options,
            **link_options)
  end
end

#dynamic_status_drop_down(context_object, return_path: nil, parent_object: nil, btn_class: nil) ⇒ Object

A Hybrid combo button displaying the current state and possible events



3
4
5
# File 'app/helpers/crm/workflows_helper.rb', line 3

def dynamic_status_drop_down(context_object, return_path: nil, parent_object: nil, btn_class: nil)
  render partial: '/shared/dynamic_status', locals: { context_object:, return_path:, parent_object:, btn_class: }
end

#state_workflow_button(object) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/crm/workflows_helper.rb', line 28

def state_workflow_button(object)
  actions = []
  actions << object.human_state_name.titleize
  actions += available_events_links(object, data: { turbo_confirm: 'Are you sure?' })
  actions << { content: object.try(:state_description) } if object.try(:state_description).present?
  render_simple_drop_down actions, dropdown_options: { right_menu: true }
end