Skip to content

Commit

Permalink
Mandatory categories for proposals (#29)
Browse files Browse the repository at this point in the history
* Mandatory categories for proposals

* Ignore missing
  • Loading branch information
fblupi authored Dec 18, 2024
1 parent 16ad1cc commit 70dd72a
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/forms/concerns/decidim/proposals/proposal_form_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
module Proposals
module ProposalFormOverride
extend ActiveSupport::Concern

included do
validates :category, presence: true
end
end
end
end
92 changes: 92 additions & 0 deletions app/views/decidim/proposals/proposals/_edit_form_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<%= form_required_explanation %>

<div class="field hashtags__container">
<%= form.text_field :title, class: "js-hashtags", value: form_presenter.title %>
</div>

<div class="field hashtags__container">
<%= text_editor_for_proposal_body(form) %>
</div>

<% if @form.component_automatic_hashtags.any? %>
<div class="field">
<%= form.label :automatic_hashtags %>
<div class="checkboxes hashtags">
<% @form.component_automatic_hashtags.each do |hashtag| %>
<label>
<%= check_box_tag "", "", { checked: true }, { disabled: true } %>#<%= hashtag %>
</label>
<% end %>
</div>
</div>
<% end %>

<% if @form.component_suggested_hashtags.any? %>
<div class="field">
<%= form.label :suggested_hashtags, nil, for: nil %>
<div class="checkboxes hashtags">
<%= form.collection_check_boxes :suggested_hashtags, @form.component_suggested_hashtags.map { |hashtag| [hashtag.downcase, "##{hashtag}"] }, :first, :last do |option|
option.label { option.check_box(checked: @form.suggested_hashtag_checked?(option.value)) + option.text }
end %>
</div>
</div>
<% end %>

<% if @form.geocoding_enabled? %>
<div class="field">
<%= form.check_box :has_address, checked: form_has_address? %>
</div>

<div class="field" id="address_input">
<%= form.geocoding_field :address, placeholder: t("decidim.proposals.proposals.placeholder.address") %>
<div class="map" id="address_map">
<%= render partial: "dynamic_map_instructions" %>
<%= dynamic_map_for proposal_preview_data_for_map(@proposal) %>
</div>
</div>
<% end %>

<% if @form.categories&.any? %>
<div class="field">
<%= form.categories_select :category_id, @form.categories, { include_blank: t("decidim.proposals.proposals.edit.select_a_category") }, { required: true } %>
</div>
<% end %>

<% if current_component.has_subscopes? %>
<div class="field">
<%= scopes_picker_field form, :scope_id, root: current_component.scope %>
</div>
<% end %>

<% if current_organization.user_groups_enabled? && Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.any? %>
<div class="field">
<%= user_group_select_field form, :user_group_id %>
</div>
<% end %>

<% if component_settings.attachments_allowed? && @proposal %>
<fieldset class="gallery__container photos_container">
<legend><%= t("gallery_legend", scope: "decidim.proposals.proposals.edit") %></legend>
<div class="row column">
<%= form.attachment :photos,
multiple: false,
label: t("decidim.proposals.proposals.edit.add_image"),
button_label: t("decidim.proposals.proposals.edit.add_image"),
button_edit_label: t("decidim.proposals.proposals.edit.edit_image"),
help_i18n_scope: "decidim.forms.file_help.image",
extension_allowlist: Decidim::OrganizationSettings.for(current_organization).upload_allowed_file_extensions_image %>
</div>
</fieldset>

<fieldset class="attachments_container gallery__container documents_container">
<legend><%= t("attachment_legend", scope: "decidim.proposals.proposals.edit") %></legend>
<div class="row column">
<%= form.attachment :documents,
multiple: true,
label: t("decidim.proposals.proposals.edit.add_documents"),
button_label: t("decidim.proposals.proposals.edit.add_documents"),
button_edit_label: t("decidim.proposals.proposals.edit.edit_documents"),
help_i18n_scope: "decidim.forms.file_help.file" %>
</div>
</fieldset>
<% end %>
8 changes: 8 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ ignore_missing:
- decidim.proposals.participatory_text_proposal.buttons.amend
- decidim.proposals.participatory_text_proposal.buttons.comment
- decidim.proposals.participatory_text_proposal.buttons.comments
- decidim.proposals.proposals.edit.add_documents
- decidim.proposals.proposals.edit.add_image
- decidim.proposals.proposals.edit.attachment_legend
- decidim.proposals.proposals.edit.edit_documents
- decidim.proposals.proposals.edit.edit_image
- decidim.proposals.proposals.edit.gallery_legend
- decidim.proposals.proposals.edit.select_a_category
- decidim.proposals.proposals.participatory_texts.index.document_index
- decidim.proposals.proposals.placeholder.address
- layouts.decidim.footer.cc_by_license
- layouts.decidim.footer.decidim_logo
- layouts.decidim.footer.made_with_open_source
Expand Down
1 change: 1 addition & 0 deletions config/initializers/decidim_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
Decidim::RegistrationForm.include(Decidim::AccountFormOverride)
Decidim::OmniauthRegistrationForm.include(Decidim::AccountFormOverride)
Decidim::AccountForm.include(Decidim::AccountFormOverride)
Decidim::Proposals::ProposalForm.include(Decidim::Proposals::ProposalFormOverride)
end
2 changes: 2 additions & 0 deletions spec/lib/overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb" => "0810f2a8eebf476b67632227a5c73ff2",
"/app/cells/decidim/proposals/participatory_text_proposal/show.erb" => "a6fd0029e01e712314f555a9397485f8",
"/app/forms/decidim/proposals/admin/participatory_text_proposal_form.rb" => "00d3e80982cc65d51c0fd9a85445526d",
"/app/forms/decidim/proposals/proposal_form.rb" => "5fbf98057d0e60a7beae161a37fdd31c",
"/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb" => "3cf530a07e4498195dab8d94b7df19d1",
"/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb" => "6d3666c3c116689bae657da537d9deef"
}
}
Expand Down

0 comments on commit 70dd72a

Please sign in to comment.