Module: Crm::WorkflowsHelper
- Defined in:
- app/helpers/crm/workflows_helper.rb
Overview
View helpers for state-machine workflow UI: combo status dropdowns and
event links rendered against any object with a state machine.
Instance Method Summary collapse
-
#available_events_links(context_object, link_options = {}, confirm_options = {}, exclude_events = [], parent_object = nil) ⇒ Array<String>
Builds one link per available state-machine event on the object.
-
#dynamic_status_drop_down(context_object, return_path: nil, parent_object: nil, btn_class: nil) ⇒ String
A Hybrid combo button displaying the current state and possible events.
-
#state_workflow_button(object) ⇒ String
Renders a simple dropdown showing the object's current state, its available event links (with a confirm prompt), and a state description.
Instance Method Details
#available_events_links(context_object, link_options = {}, confirm_options = {}, exclude_events = [], parent_object = nil) ⇒ Array<String>
Builds one link per available state-machine event on the object.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/crm/workflows_helper.rb', line 29 def available_events_links(context_object, = {}, = {}, exclude_events = [], parent_object = nil) = .dup # Ensures we only operate on a copy include_link_icon = .delete(:include_link_icon).to_b return_path = .delete(:return_path) available_events = possible_events(context_object) available_events.map do |evt| next if exclude_events.include?(evt.to_s) = {} = { turbo_confirm: [:prompt] } if [:event] && ([: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: , **) end end |
#dynamic_status_drop_down(context_object, return_path: nil, parent_object: nil, btn_class: nil) ⇒ String
A Hybrid combo button displaying the current state and possible events
15 16 17 |
# File 'app/helpers/crm/workflows_helper.rb', line 15 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) ⇒ String
Renders a simple dropdown showing the object's current state, its
available event links (with a confirm prompt), and a state description.
55 56 57 58 59 60 61 |
# File 'app/helpers/crm/workflows_helper.rb', line 55 def (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 |