Module: Decidim::Proposals::ProposalEndorsementsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/decidim/proposals/proposal_endorsements_helper.rb
Overview
Simple helper to handle markup variations for proposal endorsements partials
Instance Method Summary collapse
-
#current_user_can_endorse? ⇒ Boolean
Public: Checks if the current user is allowed to endorse in this step.
-
#endorsement_button(proposal, from_proposals_list, btn_label = nil, user_group = nil) ⇒ Object
Public: Renders a button to endorse the given proposal.
-
#endorsement_button_classes(from_proposals_list) ⇒ Object
Returns the css classes used for proposal endorsement button in both proposals list and show pages.
- #endorsement_identity(endorsement) ⇒ Object
-
#endorsements_blocked? ⇒ Boolean
Public: Checks if endorsements are blocked in this step.
-
#endorsements_count_classes(from_proposals_list) ⇒ Object
Returns the css classes used for proposal endorsements count in both proposals list and show pages.
-
#endorsements_enabled? ⇒ Boolean
Public: Checks if endorsement are enabled in this step.
-
#fully_endorsed?(proposal, user) ⇒ Boolean
Public: Checks if the given Proposal has been endorsed by all identities of the user.
-
#render_endorsement_identity(proposal, user, user_group = nil) ⇒ Object
Public: Renders an identity for endorsement.
-
#show_endorsements_card? ⇒ Boolean
Public: Checks if the card for endorsements should be rendered.
Instance Method Details
#current_user_can_endorse? ⇒ Boolean
Public: Checks if the current user is allowed to endorse in this step.
Returns true if the current user can endorse, false otherwise.
44 45 46 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 44 def current_user_can_endorse? current_user && endorsements_enabled? && !endorsements_blocked? end |
#endorsement_button(proposal, from_proposals_list, btn_label = nil, user_group = nil) ⇒ Object
Public: Renders a button to endorse the given proposal. To override the translation for both buttons: endorse and unendorse (use to be the name of the user/user_group).
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 64 def (proposal, from_proposals_list, btn_label = nil, user_group = nil) current_endorsement_url = proposal_proposal_endorsement_path( proposal_id: proposal, from_proposals_list: from_proposals_list, user_group_id: user_group&.id ) endorse_label = btn_label || t(".endorse") unendorse_label = btn_label || t("decidim.proposals.proposal_endorsements_helper.endorsement_button.already_endorsed") render partial: "decidim/proposals/proposals/endorsement_button", locals: { proposal: proposal, from_proposals_list: from_proposals_list, user_group: user_group, current_endorsement_url: current_endorsement_url, endorse_label: endorse_label, unendorse_label: unendorse_label } end |
#endorsement_button_classes(from_proposals_list) ⇒ Object
Returns the css classes used for proposal endorsement button in both proposals list and show pages
from_proposals_list - A boolean to indicate if the template is rendered from the proposals list page
Returns a string with the value of the css classes.
22 23 24 25 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 22 def (from_proposals_list) return "small" if from_proposals_list "small compact light button--sc expanded" end |
#endorsement_identity(endorsement) ⇒ Object
55 56 57 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 55 def endorsement_identity(endorsement) endorsement.user_group ? endorsement.user_group : endorsement. end |
#endorsements_blocked? ⇒ Boolean
Public: Checks if endorsements are blocked in this step.
Returns true if blocked, false otherwise.
37 38 39 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 37 def endorsements_blocked? current_settings.endorsements_blocked end |
#endorsements_count_classes(from_proposals_list) ⇒ Object
Returns the css classes used for proposal endorsements count in both proposals list and show pages
from_proposals_list - A boolean to indicate if the template is rendered from the proposals list page
Returns a hash with the css classes for the count number and label
12 13 14 15 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 12 def endorsements_count_classes(from_proposals_list) return { number: "card__support__number", label: "" } if from_proposals_list { number: "extra__suport-number", label: "extra__suport-text" } end |
#endorsements_enabled? ⇒ Boolean
Public: Checks if endorsement are enabled in this step.
Returns true if enabled, false otherwise.
30 31 32 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 30 def endorsements_enabled? current_settings.endorsements_enabled end |
#fully_endorsed?(proposal, user) ⇒ Boolean
Public: Checks if the given Proposal has been endorsed by all identities of the user.
85 86 87 88 89 90 91 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 85 def fully_endorsed?(proposal, user) return false unless user user_group_endorsements = user.user_groups.verified.all? { |user_group| proposal.endorsed_by?(user, user_group) } user_group_endorsements && proposal.endorsed_by?(user) end |
#render_endorsement_identity(proposal, user, user_group = nil) ⇒ Object
Public: Renders an identity for endorsement.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 98 def render_endorsement_identity(proposal, user, user_group = nil) current_endorsement_url = proposal_proposal_endorsement_path( proposal_id: proposal, from_proposals_list: false, user_group_id: user_group&.id, authenticity_token: form_authenticity_token ) presenter = if user_group Decidim::UserGroupPresenter.new(user_group) else Decidim::UserPresenter.new(user) end selected = proposal.endorsed_by?(user, user_group) http_method = selected ? :delete : :post render partial: "decidim/proposals/proposal_endorsements/identity", locals: { identity: presenter, selected: selected, current_endorsement_url: current_endorsement_url, http_method: http_method } end |
#show_endorsements_card? ⇒ Boolean
Public: Checks if the card for endorsements should be rendered.
Returns true if the endorsements card should be rendered, false otherwise.
51 52 53 |
# File 'app/helpers/decidim/proposals/proposal_endorsements_helper.rb', line 51 def show_endorsements_card? endorsements_enabled? end |