Module: Decidim::Initiatives::InitiativeHelper
- Includes:
- ResourceVersionsHelper, SanitizeHelper
- Included in:
- CreateInitiativeController
- Defined in:
- decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb
Overview
Helper method related to initiative object and its internal state.
Instance Method Summary collapse
- #authorized_vote_modal_button(initiative, html_options, &block) ⇒ Object
- #can_edit_area?(initiative) ⇒ Boolean
- #can_edit_custom_signature_end_date?(initiative) ⇒ Boolean
-
#humanize_admin_state(state) ⇒ Object
Public: The state of an initiative from an administration perspective in a way that a human can understand.
-
#humanize_state(initiative) ⇒ Object
Public: The state of an initiative in a way a human can understand.
- #popularity_class(initiative) ⇒ Object
- #popularity_level1?(initiative) ⇒ Boolean
- #popularity_level2?(initiative) ⇒ Boolean
- #popularity_level3?(initiative) ⇒ Boolean
- #popularity_level4?(initiative) ⇒ Boolean
- #popularity_level5?(initiative) ⇒ Boolean
- #popularity_tag(initiative) ⇒ Object
-
#state_badge_css_class(initiative) ⇒ Object
Public: The css class applied based on the initiative state to the initiative badge.
Methods included from ResourceVersionsHelper
#link_to_other_resource_versions, #resource_version, #resource_version_number, #resource_version_of
Methods included from ResourceHelper
#linked_classes_filter_values_for, #linked_classes_for, #linked_resources_for, #resource_locator, #resource_title
Methods included from SanitizeHelper
#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_editor, #decidim_sanitize_newsletter, #decidim_url_escape, included
Instance Method Details
#authorized_vote_modal_button(initiative, html_options, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 88 def (initiative, , &block) return if current_user && ("vote", resource: initiative, permissions_holder: initiative.type).ok? tag = "button" ||= {} if current_user ["data-open"] = "authorizationModal" ["data-open-url"] = (initiative) else ["data-open"] = "loginModal" end ["onclick"] = "event.preventDefault();" send("#{tag}_to", "", , &block) end |
#can_edit_area?(initiative) ⇒ Boolean
112 113 114 115 116 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 112 def can_edit_area?(initiative) return false unless initiative.area_enabled? initiative.created? || initiative.validating? end |
#can_edit_custom_signature_end_date?(initiative) ⇒ Boolean
106 107 108 109 110 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 106 def can_edit_custom_signature_end_date?(initiative) return false unless initiative.custom_signature_end_date_enabled? initiative.created? || initiative.validating? end |
#humanize_admin_state(state) ⇒ Object
Public: The state of an initiative from an administration perspective in a way that a human can understand.
state - String
Returns a String
39 40 41 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 39 def humanize_admin_state(state) I18n.t(state, scope: "decidim.initiatives.admin_states", default: :created) end |
#humanize_state(initiative) ⇒ Object
Public: The state of an initiative in a way a human can understand.
initiative - Decidim::Initiative.
Returns a String.
27 28 29 30 31 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 27 def humanize_state(initiative) I18n.t(initiative.accepted? ? "accepted" : "expired", scope: "decidim.initiatives.states", default: :expired) end |
#popularity_class(initiative) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 58 def popularity_class(initiative) return "popularity--level1" if popularity_level1?(initiative) return "popularity--level2" if popularity_level2?(initiative) return "popularity--level3" if popularity_level3?(initiative) return "popularity--level4" if popularity_level4?(initiative) return "popularity--level5" if popularity_level5?(initiative) "" end |
#popularity_level1?(initiative) ⇒ Boolean
68 69 70 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 68 def popularity_level1?(initiative) initiative.percentage.positive? && initiative.percentage < 40 end |
#popularity_level2?(initiative) ⇒ Boolean
72 73 74 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 72 def popularity_level2?(initiative) initiative.percentage >= 40 && initiative.percentage < 60 end |
#popularity_level3?(initiative) ⇒ Boolean
76 77 78 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 76 def popularity_level3?(initiative) initiative.percentage >= 60 && initiative.percentage < 80 end |
#popularity_level4?(initiative) ⇒ Boolean
80 81 82 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 80 def popularity_level4?(initiative) initiative.percentage >= 80 && initiative.percentage < 100 end |
#popularity_level5?(initiative) ⇒ Boolean
84 85 86 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 84 def popularity_level5?(initiative) initiative.percentage >= 100 end |
#popularity_tag(initiative) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 43 def popularity_tag(initiative) content_tag(:div, class: "extra__popularity popularity #{popularity_class(initiative)}".strip) do 5.times do concat(content_tag(:span, class: "popularity__item") do # empty block end) end concat(content_tag(:span, class: "popularity__desc") do I18n.t("decidim.initiatives.initiatives.vote_cabin.supports_required", total_supports: initiative.scoped_type.supports_required) end) end end |
#state_badge_css_class(initiative) ⇒ Object
Public: The css class applied based on the initiative state to
the initiative badge.
initiative - Decidim::Initiative
Returns a String.
16 17 18 19 20 |
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 16 def state_badge_css_class(initiative) return "success" if initiative.accepted? "warning" end |