Module: Decidim::Proposals::ProposalWizardHelper

Defined in:
app/helpers/decidim/proposals/proposal_wizard_helper.rb

Overview

Simple helpers to handle markup variations for proposal wizard partials

Instance Method Summary collapse

Instance Method Details

#proposal_wizard_current_step_of(step) ⇒ Object

Returns a string with the current step number and the total steps number

step - A symbol of the target step



80
81
82
83
84
85
86
87
88
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 80

def proposal_wizard_current_step_of(step)
  current_step_num = proposal_wizard_step_number(step)
   :span, class: "text-small" do
    concat t(:"decidim.proposals.proposals.wizard_steps.step_of", current_step_num: current_step_num, total_steps: total_steps)
    concat " ("
    concat  :a, t(:"decidim.proposals.proposals.wizard_steps.see_steps"), "data-toggle": "steps"
    concat ")"
  end
end

#proposal_wizard_step_classes(step, current_step) ⇒ Object

Returns the css classes used for the proposal wizard for the desired step

step - A symbol of the target step current_step - A symbol of the current step

Returns a string with the css classes for the desired step



13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 13

def proposal_wizard_step_classes(step, current_step)
  step_i = step.to_s.split("_").last.to_i
  if step_i == proposal_wizard_step_number(current_step)
    %(step--active #{step} #{current_step})
  elsif step_i < proposal_wizard_step_number(current_step)
    %(step--past #{step})
  else
    %()
  end
end

#proposal_wizard_step_help_text?(step) ⇒ Boolean

Returns a boolean if the step has a help text defined

step - A symbol of the target step

Returns:

  • (Boolean)


93
94
95
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 93

def proposal_wizard_step_help_text?(step)
  translated_attribute(component_settings.try("proposal_wizard_#{step}_help_text")).present?
end

#proposal_wizard_step_name(step) ⇒ Object

Returns the name of the step, translated

step - A symbol of the target step



34
35
36
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 34

def proposal_wizard_step_name(step)
  t("decidim.proposals.#{type_of}.wizard_steps.#{step}")
end

#proposal_wizard_step_number(step) ⇒ Object

Returns the number of the step

step - A symbol of the target step



27
28
29
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 27

def proposal_wizard_step_number(step)
  step.to_s.split("_").last.to_i
end

#proposal_wizard_step_title(action_name) ⇒ Object

Returns the page title of the given step, translated

action_name - A string of the rendered action



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 41

def proposal_wizard_step_title(action_name)
  step_title = case action_name
               when "create"
                 "new"
               when "update_draft"
                 "edit_draft"
               else
                 action_name
               end

  t("decidim.proposals.#{type_of}.#{step_title}.title")
end

#proposal_wizard_stepper(current_step) ⇒ Object

Returns the list with all the steps, in html

current_step - A symbol of the current step



66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 66

def proposal_wizard_stepper(current_step)
   :ol, class: "wizard__steps" do
    %(
      #{proposal_wizard_stepper_step(:step_1, current_step)}
      #{proposal_wizard_stepper_step(:step_2, current_step)}
      #{proposal_wizard_stepper_step(:step_3, current_step)}
      #{proposal_wizard_stepper_step(:step_4, current_step)}
    ).html_safe
  end
end

#proposal_wizard_stepper_step(step, current_step) ⇒ Object

Returns the list item of the given step, in html

step - A symbol of the target step current_step - A symbol of the current step



58
59
60
61
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 58

def proposal_wizard_stepper_step(step, current_step)
  return if step == :step_4 && type_of == :collaborative_drafts
  (:li, proposal_wizard_step_name(step), class: proposal_wizard_step_classes(step, current_step).to_s)
end

#user_group_select_field(form, name) ⇒ Object

Renders a user_group select field in a form. form - FormBuilder object name - attribute user_group_id

Returns nothing.



102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/decidim/proposals/proposal_wizard_helper.rb', line 102

def user_group_select_field(form, name)
  selected = @form.user_group_id.presence
  user_groups = Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
  form.select(
    name,
    user_groups.map { |g| [g.name, g.id] },
    selected: selected,
    include_blank: current_user.name
  )
end