Module: EffectiveResourcesWizardHelper

Defined in:
app/helpers/effective_resources_wizard_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_wizard_sidebar(resource, numbers: true, horizontal: false, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/effective_resources_wizard_helper.rb', line 5

def render_wizard_sidebar(resource, numbers: true, horizontal: false, &block)
  klasses = ['wizard-sidebar', 'list-group', ('list-group-horizontal' if horizontal)].compact.join(' ')

  sidebar = (:div, class: klasses) do
    resource.required_steps.map.with_index do |nav_step, index|
      render_wizard_sidebar_item(resource, nav_step, (index + 1 if numbers))
    end.join.html_safe
  end

  return sidebar unless block_given?

  (:div, class: 'row') do
    (:div, class: 'col-3') { sidebar } +
    (:div, class: 'col-9') { yield }
  end
end

#render_wizard_sidebar_item(resource, nav_step, index = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/effective_resources_wizard_helper.rb', line 22

def render_wizard_sidebar_item(resource, nav_step, index = nil)
  # From Controller
  current = (nav_step == step)
  title = resource_wizard_step_title(resource, nav_step)

  # From Model
  disabled = !resource.can_visit_step?(nav_step)

  label = [index, title].compact.join('. ')
  klass = ['list-group-item', ('active' if current), ('disabled' if disabled && !current)].compact.join(' ')

  if (current || disabled)
    (:li, label, class: klass)
  else
    link_to(label, wizard_path(nav_step), class: klass)
  end
end