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

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_newsletter, #decidim_url_escape, included

Instance Method Details

#authorized_vote_modal_button(initiative, html_options, &block) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 86

def authorized_vote_modal_button(initiative, html_options, &block)
  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-open"] = "loginModal"
  else
    html_options["data-open"] = "authorizationModal"
    html_options["data-open-url"] = authorization_sign_modal_initiative_path(initiative)
  end

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

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

#can_edit_area?(initiative) ⇒ Boolean

Returns:

  • (Boolean)

110
111
112
113
114
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 110

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)

104
105
106
107
108
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 104

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


56
57
58
59
60
61
62
63
64
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 56

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)

66
67
68
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 66

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

#popularity_level2?(initiative) ⇒ Boolean

Returns:

  • (Boolean)

70
71
72
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 70

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

#popularity_level3?(initiative) ⇒ Boolean

Returns:

  • (Boolean)

74
75
76
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 74

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

#popularity_level4?(initiative) ⇒ Boolean

Returns:

  • (Boolean)

78
79
80
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 78

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

#popularity_level5?(initiative) ⇒ Boolean

Returns:

  • (Boolean)

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

def popularity_level5?(initiative)
  initiative.percentage >= 100
end

#popularity_tag(initiative) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
# File 'decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb', line 43

def popularity_tag(initiative)
  (:div, class: "extra__popularity popularity #{popularity_class(initiative)}".strip) do
    5.times do
      concat((:span, class: "popularity__item") {})
    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

#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