Module: Decidim::Proposals::ApplicationHelper

Overview

Custom helpers, scoped to the proposals engine.

Instance Method Summary collapse

Methods included from CheckBoxesTreeHelper

#check_boxes_tree_options, #filter_categories_values, #filter_scopes_values, #filter_scopes_values_from, #filter_scopes_values_from_parent, #filter_tree_from, #resource_filter_scope_values, #scope_children_to_tree

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ControlVersionHelper

#item_name

Methods included from CollaborativeDraftHelper

#accept_request_button_label, #filter_collaborative_drafts_state_values, #reject_request_button_label

Methods included from MapHelper

#has_position?, #proposal_data_for_map, #proposal_preview_data_for_map, #proposals_data_for_map

Methods included from ApplicationHelper

#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #resolve_presenter_class, #step_cta_url

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amenders_list_for, #amendments_enabled?, #amendments_for, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods included from MapHelper

#dynamic_map_for, #static_map_link

Methods included from FollowableHelper

#follow_button_for

Methods included from EndorsableHelper

#current_user_can_endorse?, #endorsement_buttons_cell, #endorsements_blocked?, #endorsements_enabled?, #endorsers_list_cell, #fully_endorsed?, #path_to_create_endorsement, #path_to_destroy_endorsement, #render_endorsement_identity, #show_endorsements_card?

Methods included from ProposalVotesHelper

#can_accumulate_supports_beyond_threshold?, #current_user_can_vote?, #remaining_votes_count_for, #threshold_per_proposal, #threshold_per_proposal_enabled?, #vote_button_classes, #vote_limit, #vote_limit_enabled?, #votes_blocked?, #votes_count_classes, #votes_enabled?

Methods included from Decidim::PaginateHelper

#decidim_paginate

Methods included from Comments::CommentsHelper

#comments_for, #inline_comments_for

Instance Method Details

#activity_filter_valuesObject

Options to filter Proposals by activity.


168
169
170
171
172
173
174
175
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 168

def activity_filter_values
  base = [
    ["all", t(".all")],
    ["my_proposals", t(".my_proposals")]
  ]
  base += [["voted", t(".voted")]] if current_settings.votes_enabled?
  base
end

#collaborative_draft_state_badge_css_class(state) ⇒ Object

Public: The css class applied based on the collaborative draft state.

state - The String state of the collaborative draft.

Returns a String.


68
69
70
71
72
73
74
75
76
77
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 68

def collaborative_draft_state_badge_css_class(state)
  case state
  when "open"
    "success"
  when "withdrawn"
    "alert"
  when "published"
    "secondary"
  end
end

#filter_origin_valuesObject


177
178
179
180
181
182
183
184
185
186
187
188
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 177

def filter_origin_values
  origin_values = []
  origin_values << TreePoint.new("official", t("decidim.proposals.application_helper.filter_origin_values.official")) if component_settings.official_proposals_enabled
  origin_values << TreePoint.new("citizens", t("decidim.proposals.application_helper.filter_origin_values.citizens"))
  origin_values << TreePoint.new("user_group", t("decidim.proposals.application_helper.filter_origin_values.user_groups")) if current_organization.user_groups_enabled?
  origin_values << TreePoint.new("meeting", t("decidim.proposals.application_helper.filter_origin_values.meetings"))

  TreeNode.new(
    TreePoint.new("", t("decidim.proposals.application_helper.filter_origin_values.all")),
    origin_values
  )
end

#filter_type_valuesObject


159
160
161
162
163
164
165
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 159

def filter_type_values
  [
    ["all", t("decidim.proposals.application_helper.filter_type_values.all")],
    ["proposals", t("decidim.proposals.application_helper.filter_type_values.proposals")],
    ["amendments", t("decidim.proposals.application_helper.filter_type_values.amendments")]
  ]
end

#form_has_address?Boolean

Returns:

  • (Boolean)

145
146
147
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 145

def form_has_address?
  @form.address.present? || @form.has_address
end

#humanize_collaborative_draft_state(state) ⇒ Object

Public: The state of a proposal in a way a human can understand.

state - The String state of the proposal.

Returns a String.


59
60
61
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 59

def humanize_collaborative_draft_state(state)
  I18n.t("decidim.proposals.collaborative_drafts.states.#{state}", default: :open)
end

#humanize_proposal_state(state) ⇒ Object

Public: The state of a proposal in a way a human can understand.

state - The String state of the proposal.

Returns a String.


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

def humanize_proposal_state(state)
  I18n.t(state, scope: "decidim.proposals.answers", default: :not_answered)
end

#minimum_votes_per_user_enabled?Boolean

Returns:

  • (Boolean)

83
84
85
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 83

def minimum_votes_per_user_enabled?
  minimum_votes_per_user.positive?
end

#not_from_collaborative_draft(proposal) ⇒ Object


87
88
89
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 87

def not_from_collaborative_draft(proposal)
  proposal.linked_resources(:proposals, "created_from_collaborative_draft").empty?
end

#not_from_participatory_text(proposal) ⇒ Object


91
92
93
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 91

def not_from_participatory_text(proposal)
  proposal.participatory_text_level.nil?
end

#proposal_limitObject


124
125
126
127
128
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 124

def proposal_limit
  return if component_settings.proposal_limit.zero?

  component_settings.proposal_limit
end

#proposal_limit_enabled?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 79

def proposal_limit_enabled?
  proposal_limit.present?
end

#proposal_state_css_class(proposal) ⇒ Object

Public: The css class applied based on the proposal state.

proposal - The proposal to evaluate.

Returns a String.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 36

def proposal_state_css_class(proposal)
  state = proposal.state
  state = proposal.internal_state if proposal.answered? && !proposal.published_state?

  case state
  when "accepted"
    "text-success"
  when "rejected"
    "text-alert"
  when "evaluating"
    "text-warning"
  when "withdrawn"
    "text-alert"
  else
    "text-info"
  end
end

#render_proposal_body(proposal) ⇒ Object

If the content is safe, HTML tags are sanitized, otherwise, they are stripped.


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

def render_proposal_body(proposal)
  body = present(proposal).body(links: true, strip_tags: !safe_content?)
  body = simple_format(body, {}, sanitize: false)

  return body unless safe_content?

  decidim_sanitize(body)
end

#safe_content?Boolean

If the proposal is official or the rich text editor is enabled on the frontend, the proposal body is considered as safe content; that's unless the proposal comes from a collaborative_draft or a participatory_text.

Returns:

  • (Boolean)

98
99
100
101
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 98

def safe_content?
  rich_text_editor_in_public_views? && not_from_collaborative_draft(@proposal) ||
    (@proposal.official? || @proposal.official_meeting?) && not_from_participatory_text(@proposal)
end

#show_voting_rules?Boolean

Returns:

  • (Boolean)

149
150
151
152
153
154
155
156
157
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 149

def show_voting_rules?
  return false unless votes_enabled?

  return true if vote_limit_enabled?
  return true if threshold_per_proposal_enabled?
  return true if proposal_limit_enabled?
  return true if can_accumulate_supports_beyond_threshold?
  return true if minimum_votes_per_user_enabled?
end

#text_editor_for_proposal_body(form) ⇒ Object

Returns :text_area or :editor based on the organization' settings.


114
115
116
117
118
119
120
121
122
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 114

def text_editor_for_proposal_body(form)
  options = {
    class: "js-hashtags",
    hashtaggable: true,
    value: form_presenter.body(extras: false).strip
  }

  text_editor_for(form, :body, options)
end

#vote_button_for(model, from_proposals_list) ⇒ Object


141
142
143
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 141

def vote_button_for(model, from_proposals_list)
  render partial: "decidim/proposals/proposals/participatory_texts/proposal_vote_button.html", locals: { proposal: model, from_proposals_list: from_proposals_list }
end

#votes_count_for(model, from_proposals_list) ⇒ Object


137
138
139
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 137

def votes_count_for(model, from_proposals_list)
  render partial: "decidim/proposals/proposals/participatory_texts/proposal_votes_count.html", locals: { proposal: model, from_proposals_list: from_proposals_list }
end

#votes_givenObject


130
131
132
133
134
135
# File 'decidim-proposals/app/helpers/decidim/proposals/application_helper.rb', line 130

def votes_given
  @votes_given ||= ProposalVote.where(
    proposal: Proposal.where(component: current_component),
    author: current_user
  ).count
end