Module: Decidim::Initiatives::InitiativeHelper
- Includes:
- ResourceVersionsHelper, SanitizeHelper
- Included in:
- CreateInitiativeController, InitiativeMetadataGCell
- Defined in:
- app/helpers/decidim/initiatives/initiative_helper.rb
Overview
Helper method related to initiative object and its internal state.
Instance Method Summary collapse
- #authorized_create_modal_button(type, html_options) ⇒ Object
- #authorized_vote_modal_button(initiative, html_options) ⇒ Object
- #can_edit_area?(initiative) ⇒ Boolean
- #can_edit_custom_signature_end_date?(initiative) ⇒ Boolean
- #hero_background_path(initiative) ⇒ Object
-
#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.
- #metadata_badge_css_class(initiative) ⇒ Object
- #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
- #render_committee_tooltip ⇒ Object
-
#state_badge_css_class(initiative) ⇒ Object
Public: The css class applied based on the initiative state to the initiative badge.
Instance Method Details
#authorized_create_modal_button(type, html_options) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 101 def (type, , &) tag = "button" ||= {} if current_user if ("create", permissions_holder: type).ok? ["data-dialog-open"] = "not-authorized-modal" else ["data-dialog-open"] = "authorizationModal" ["data-dialog-remote-url"] = (type) end else ["data-dialog-open"] = "loginModal" end ["onclick"] = "event.preventDefault();" send("#{tag}_to", "/", , &) end |
#authorized_vote_modal_button(initiative, html_options) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 121 def (initiative, , &) return if current_user && ("vote", resource: initiative, permissions_holder: initiative.type).ok? tag = "button" ||= {} if current_user ["data-dialog-open"] = "authorizationModal" ["data-dialog-remote-url"] = (initiative) else ["data-dialog-open"] = "loginModal" end ["onclick"] = "event.preventDefault();" send("#{tag}_to", "/", , &) end |
#can_edit_area?(initiative) ⇒ Boolean
145 146 147 148 149 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 145 def can_edit_area?(initiative) return false unless initiative.area_enabled? initiative.created? || initiative.validating? end |
#can_edit_custom_signature_end_date?(initiative) ⇒ Boolean
139 140 141 142 143 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 139 def can_edit_custom_signature_end_date?(initiative) return false unless initiative.custom_signature_end_date_enabled? initiative.created? || initiative.validating? end |
#hero_background_path(initiative) ⇒ Object
157 158 159 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 157 def hero_background_path(initiative) initiative..find(&:image?)&.url 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
52 53 54 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 52 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.
40 41 42 43 44 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 40 def humanize_state(initiative) I18n.t(initiative.accepted? ? "accepted" : "expired", scope: "decidim.initiatives.states", default: :expired) end |
#metadata_badge_css_class(initiative) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 22 def (initiative) case initiative when "accepted", "published" "success" when "rejected", "discarded" "alert" when "validating" "warning" else "muted" end end |
#popularity_class(initiative) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 71 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
81 82 83 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 81 def popularity_level1?(initiative) initiative.percentage.positive? && initiative.percentage < 40 end |
#popularity_level2?(initiative) ⇒ Boolean
85 86 87 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 85 def popularity_level2?(initiative) initiative.percentage >= 40 && initiative.percentage < 60 end |
#popularity_level3?(initiative) ⇒ Boolean
89 90 91 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 89 def popularity_level3?(initiative) initiative.percentage >= 60 && initiative.percentage < 80 end |
#popularity_level4?(initiative) ⇒ Boolean
93 94 95 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 93 def popularity_level4?(initiative) initiative.percentage >= 80 && initiative.percentage < 100 end |
#popularity_level5?(initiative) ⇒ Boolean
97 98 99 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 97 def popularity_level5?(initiative) initiative.percentage >= 100 end |
#popularity_tag(initiative) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 56 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 |
#render_committee_tooltip ⇒ Object
151 152 153 154 155 |
# File 'app/helpers/decidim/initiatives/initiative_helper.rb', line 151 def render_committee_tooltip with_tooltip t("decidim.initiatives.create_initiative.share_committee_link.invite_to_committee_help"), class: "left" do icon "file-copy-line" 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 'app/helpers/decidim/initiatives/initiative_helper.rb', line 16 def state_badge_css_class(initiative) return "success" if initiative.accepted? "warning" end |