Module: Decidim::Initiatives::InitiativeHelper

Includes:
ResourceVersionsHelper, SanitizeHelper
Included in:
CreateInitiativeController, InitiativeMetadataGCell
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

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, #resource_locator, #resource_title

Methods included from SanitizeHelper

#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_url_escape, included

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 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 101

def authorized_create_modal_button(type, html_options, &)
  tag = "button"
  html_options ||= {}

  if current_user
    if action_authorized_to("create", permissions_holder: type).ok?
      html_options["data-dialog-open"] = "not-authorized-modal"
    else
      html_options["data-dialog-open"] = "authorizationModal"
      html_options["data-dialog-remote-url"] = authorization_create_modal_initiative_path(type)
    end
  else
    html_options["data-dialog-open"] = "loginModal"
  end

  html_options["onclick"] = "event.preventDefault();"

  send("#{tag}_to", "", html_options, &)
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 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 121

def authorized_vote_modal_button(initiative, html_options, &)
  return if current_user && action_authorized_to("vote", resource: initiative, permissions_holder: initiative.type).ok?

  tag = "button"
  html_options ||= {}

  if current_user
    html_options["data-dialog-open"] = "authorizationModal"
    html_options["data-dialog-remote-url"] = authorization_sign_modal_initiative_path(initiative)
  else
    html_options["data-dialog-open"] = "loginModal"
  end

  html_options["onclick"] = "event.preventDefault();"

  send("#{tag}_to", "", html_options, &)
end

#can_edit_area?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
148
149
# File 'decidim-initiatives/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

Returns:

  • (Boolean)


139
140
141
142
143
# File 'decidim-initiatives/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 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 157

def hero_background_path(initiative)
  initiative.attachments.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 'decidim-initiatives/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 'decidim-initiatives/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 'decidim-initiatives/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 'decidim-initiatives/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

Returns:

  • (Boolean)


81
82
83
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 81

def popularity_level1?(initiative)
  initiative.percentage.positive? && initiative.percentage < 40
end

#popularity_level2?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 85

def popularity_level2?(initiative)
  initiative.percentage >= 40 && initiative.percentage < 60
end

#popularity_level3?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 89

def popularity_level3?(initiative)
  initiative.percentage >= 60 && initiative.percentage < 80
end

#popularity_level4?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 93

def popularity_level4?(initiative)
  initiative.percentage >= 80 && initiative.percentage < 100
end

#popularity_level5?(initiative) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'decidim-initiatives/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 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 56

def popularity_tag(initiative)
  (:div, class: "extra__popularity popularity #{popularity_class(initiative)}".strip) do
    5.times do
      concat((:span, class: "popularity__item") do
        # empty block
      end)
    end

    concat((: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_tooltipObject



151
152
153
154
155
# File 'decidim-initiatives/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 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 16

def state_badge_css_class(initiative)
  return "success" if initiative.accepted?

  "warning"
end