Module: Decidim::AmendmentsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/decidim/amendments_helper.rb
Overview
A Helper to render and link amendments to resources.
Instance Method Summary collapse
-
#accept_and_reject_buttons_for(emendation) ⇒ Object
Renders the buttons to ACCEPT/REJECT an emendation.
-
#action_button_card_for(emendation) ⇒ Object
Returns Html action button cards to ACCEPT/REJECT or to PROMOTE an emendation.
-
#allowed_to_accept_and_reject?(emendation) ⇒ Boolean
Checks if the user can accept and reject the emendation.
-
#allowed_to_promote?(emendation) ⇒ Boolean
Checks if the user can promote the emendation.
-
#amend_button_for(amendable) ⇒ Object
Returns Html action button card to AMEND an amendable resource.
-
#amenders_list_for(amendable) ⇒ Object
Renders the amenders list of an amendable resource.
- #amendments_enabled? ⇒ Boolean
-
#amendments_for(amendable) ⇒ Object
Renders the emendations of an amendable resource.
-
#amendments_form_fields_label(attribute) ⇒ Object
Return the translated attribute name to use as label in a form.
-
#amendments_form_fields_value(original_resource, attribute) ⇒ Object
Return the edited field value or presents the original attribute value in a form.
-
#can_participate_in_private_space? ⇒ Boolean
Checks if the user can participate in a participatory space based on its settings related with Decidim::HasPrivateUsers.
-
#can_react_to_emendation?(emendation) ⇒ Boolean
Checks if there’s a user that can react to an emendation.
-
#emendation_actions_for(emendation) ⇒ Object
Returns Html action button cards for an emendation.
-
#emendation_announcement_for(emendation) ⇒ Object
Renders the state of an emendation.
-
#promote_button_for(emendation) ⇒ Object
Renders the button to PROMOTE an emendation.
-
#user_group_select_field(form, name) ⇒ Object
Renders a UserGroup select field in a form.
Instance Method Details
#accept_and_reject_buttons_for(emendation) ⇒ Object
Renders the buttons to ACCEPT/REJECT an emendation
73 74 75 |
# File 'app/helpers/decidim/amendments_helper.rb', line 73 def (emendation) cell("decidim/amendable/emendation_actions", emendation) end |
#action_button_card_for(emendation) ⇒ Object
Returns Html action button cards to ACCEPT/REJECT or to PROMOTE an emendation
67 68 69 70 |
# File 'app/helpers/decidim/amendments_helper.rb', line 67 def (emendation) return (emendation) if allowed_to_accept_and_reject?(emendation) return (emendation) if allowed_to_promote?(emendation) end |
#allowed_to_accept_and_reject?(emendation) ⇒ Boolean
Checks if the user can accept and reject the emendation
94 95 96 97 98 |
# File 'app/helpers/decidim/amendments_helper.rb', line 94 def allowed_to_accept_and_reject?(emendation) return unless emendation.amendment.evaluating? emendation.amendable.created_by?(current_user) || current_user.admin? end |
#allowed_to_promote?(emendation) ⇒ Boolean
Checks if the user can promote the emendation
101 102 103 104 105 106 |
# File 'app/helpers/decidim/amendments_helper.rb', line 101 def allowed_to_promote?(emendation) return unless emendation.amendment.rejected? && emendation.created_by?(current_user) return if emendation.amendment.promoted? current_component.current_settings.amendment_promotion_enabled end |
#amend_button_for(amendable) ⇒ Object
Returns Html action button card to AMEND an amendable resource
43 44 45 46 47 48 49 |
# File 'app/helpers/decidim/amendments_helper.rb', line 43 def (amendable) return unless amendments_enabled? && amendable.amendable? return unless current_component.current_settings.amendment_creation_enabled return unless can_participate_in_private_space? cell("decidim/amendable/amend_button_card", amendable) end |
#amenders_list_for(amendable) ⇒ Object
Renders the amenders list of an amendable resource
27 28 29 30 31 |
# File 'app/helpers/decidim/amendments_helper.rb', line 27 def amenders_list_for(amendable) return unless amendable.amendable? cell("decidim/amendable/amenders_list", amendable) end |
#amendments_enabled? ⇒ Boolean
82 83 84 |
# File 'app/helpers/decidim/amendments_helper.rb', line 82 def amendments_enabled? current_component.settings.amendments_enabled end |
#amendments_for(amendable) ⇒ Object
Renders the emendations of an amendable resource
Returns Html grid of CardM.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/decidim/amendments_helper.rb', line 9 def amendments_for(amendable) return unless amendable.amendable? return unless (emendations = amendable.visible_emendations_for(current_user)).any? content = content_tag(:h2, class: "section-heading", id: "amendments") do t("section_heading", scope: "decidim.amendments.amendable", count: emendations.count) end content << cell("decidim/collapsible_list", emendations, cell_options: { context: { current_user: current_user } }, list_class: "row small-up-1 medium-up-2 card-grid amendment-list", size: 4).to_s content_tag :div, content.html_safe, class: "section" end |
#amendments_form_fields_label(attribute) ⇒ Object
Return the translated attribute name to use as label in a form. Returns a String.
119 120 121 122 |
# File 'app/helpers/decidim/amendments_helper.rb', line 119 def amendments_form_fields_label(attribute) model_name = amendable.model_name.singular_route_key I18n.t(attribute, scope: "activemodel.attributes.#{model_name}") end |
#amendments_form_fields_value(original_resource, attribute) ⇒ Object
Return the edited field value or presents the original attribute value in a form.
original_resource - name of the method to send to the controller (:amendable or :emendation) attribute - name of the attribute to send to the original_resource Presenter
Returns a String.
130 131 132 133 134 |
# File 'app/helpers/decidim/amendments_helper.rb', line 130 def amendments_form_fields_value(original_resource, attribute) return params[:amendment][:emendation_params][attribute] if params[:amendment].present? present(send(original_resource)).send(attribute) end |
#can_participate_in_private_space? ⇒ Boolean
Checks if the user can participate in a participatory space based on its settings related with Decidim::HasPrivateUsers.
53 54 55 56 57 |
# File 'app/helpers/decidim/amendments_helper.rb', line 53 def can_participate_in_private_space? return true unless current_participatory_space.class.included_modules.include?(HasPrivateUsers) current_participatory_space.can_participate?(current_user) end |
#can_react_to_emendation?(emendation) ⇒ Boolean
Checks if there’s a user that can react to an emendation
87 88 89 90 91 |
# File 'app/helpers/decidim/amendments_helper.rb', line 87 def can_react_to_emendation?(emendation) return unless current_user && emendation.emendation? current_component.current_settings.amendment_reaction_enabled end |
#emendation_actions_for(emendation) ⇒ Object
Returns Html action button cards for an emendation
60 61 62 63 64 |
# File 'app/helpers/decidim/amendments_helper.rb', line 60 def emendation_actions_for(emendation) return unless amendments_enabled? && can_react_to_emendation?(emendation) (emendation) end |
#emendation_announcement_for(emendation) ⇒ Object
Renders the state of an emendation
Returns Html callout.
36 37 38 39 40 |
# File 'app/helpers/decidim/amendments_helper.rb', line 36 def emendation_announcement_for(emendation) return unless emendation.emendation? cell("decidim/amendable/announcement", emendation) end |
#promote_button_for(emendation) ⇒ Object
Renders the button to PROMOTE an emendation
78 79 80 |
# File 'app/helpers/decidim/amendments_helper.rb', line 78 def (emendation) cell("decidim/amendable/promote_button_card", emendation) end |
#user_group_select_field(form, name) ⇒ Object
Renders a UserGroup select field in a form.
109 110 111 112 113 114 115 |
# File 'app/helpers/decidim/amendments_helper.rb', line 109 def user_group_select_field(form, name) form.select(name, current_user.user_groups.verified.map { |g| [g.name, g.id] }, selected: form.object.user_group_id.presence, include_blank: current_user.name, label: t("new.amendment_author", scope: "decidim.amendments")) end |