From 3b70420d87d832ad5ffbb4d70f794a1d0e777242 Mon Sep 17 00:00:00 2001 From: Thomas Burkhalter Date: Fri, 6 May 2022 12:18:05 +0200 Subject: [PATCH] Fix initiative_signature_type --- .../admin/initiative_form_override.rb | 12 ++ .../initiatives/initiative_form_override.rb | 12 ++ .../admin/initiatives/_form.html.erb | 122 ++++++++++++++++++ .../initiatives/initiatives/_form.html.erb | 112 ++++++++++++++++ 4 files changed, 258 insertions(+) create mode 100644 app/overrides/forms/decidim/initiatives/admin/initiative_form_override.rb create mode 100644 app/overrides/forms/decidim/initiatives/initiative_form_override.rb create mode 100644 app/views/decidim/initiatives/admin/initiatives/_form.html.erb create mode 100644 app/views/decidim/initiatives/initiatives/_form.html.erb diff --git a/app/overrides/forms/decidim/initiatives/admin/initiative_form_override.rb b/app/overrides/forms/decidim/initiatives/admin/initiative_form_override.rb new file mode 100644 index 0000000..3d71832 --- /dev/null +++ b/app/overrides/forms/decidim/initiatives/admin/initiative_form_override.rb @@ -0,0 +1,12 @@ +Decidim::Initiatives::Admin::InitiativeForm.class_eval do + def signature_type_options + Decidim::Initiative.signature_types.keys.map do |type| + [ + I18n.t( + type, + scope: %w(activemodel attributes initiative signature_type_values) + ), type + ] + end + end +end \ No newline at end of file diff --git a/app/overrides/forms/decidim/initiatives/initiative_form_override.rb b/app/overrides/forms/decidim/initiatives/initiative_form_override.rb new file mode 100644 index 0000000..ed578c0 --- /dev/null +++ b/app/overrides/forms/decidim/initiatives/initiative_form_override.rb @@ -0,0 +1,12 @@ +Decidim::Initiatives::InitiativeForm.class_eval do + def signature_type_options + Decidim::Initiative.signature_types.keys.map do |type| + [ + I18n.t( + type, + scope: %w(activemodel attributes initiative signature_type_values) + ), type + ] + end + end +end \ No newline at end of file diff --git a/app/views/decidim/initiatives/admin/initiatives/_form.html.erb b/app/views/decidim/initiatives/admin/initiatives/_form.html.erb new file mode 100644 index 0000000..41c3649 --- /dev/null +++ b/app/views/decidim/initiatives/admin/initiatives/_form.html.erb @@ -0,0 +1,122 @@ +
+
+

<%= t ".title" %>

+
+ +
+
+ <%= form.translated :text_field, :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ +
+ <%= form.translated :editor, :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ +
+
+ <%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+
+
+
+ +
+
+

<%= t ".settings" %>

+
+ +
+
+
+ <%= form.select :state, + Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] }, + {}, + { disabled: !@form.state_updatable? } %> +
+
+ +
+ <% unless single_initiative_type? %> +
+ <%= form.select :type_id, + initiative_type_options, + {}, + { + disabled: !@form.signature_type_updatable?, + "data-scope-selector": "initiative_decidim_scope_id", + "data-scope-id": form.object.decidim_scope_id.to_s, + "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, + "data-signature-types-selector": "initiative_signature_type", + "data-signature-type": current_initiative.signature_type, + "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url + } %> +
+ <% end %> +
+ <%= form.select :decidim_scope_id, [], {}, { disabled: !@form.signature_type_updatable? } %> +
+
+ + <% if current_initiative.published? && current_user.admin? %> +
+
+ <%= form.date_field :signature_start_date %> +
+ +
+ <%= form.date_field :signature_end_date %> +
+
+ <% end %> + + <% if can_edit_custom_signature_end_date?(current_initiative) %> +
+ <%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ <% end %> + + <% if current_initiative.area_enabled? %> +
+ <%= form.areas_select :area_id, + areas_for_select(current_organization), + { + selected: current_initiative.decidim_area_id, + include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created? + }, + disabled: !@form.area_updatable? %> +
+ <% end %> + +
+
+ <%= form.select :signature_type, form.object.signature_type_options, {}, { disabled: !@form.signature_type_updatable? } %> +
+
+ + <% if current_initiative.accepts_offline_votes? && current_user.admin? %> +
+
+ <% @form.offline_votes.each do |scope_id, (votes, scope_name)| %> + <%= label_tag "initiative_offline_votes_#{scope_id}", t("activemodel.attributes.initiative.offline_votes_for_scope", scope_name: translated_attribute(scope_name)) %> + <%= number_field_tag "initiative[offline_votes][#{scope_id}]", votes, min: 0, id: "initiative_offline_votes_#{scope_id}" %> + <% end %> +
+
+ <% end %> +
+
+
+
+

<%= t ".attachments" %>

+
+ +
+
+ <% if allowed_to?(:read, :attachment, initiative: current_participatory_space) %> + <%= render partial: "initiative_attachments", locals: { current_initiative: current_initiative, current_participatory_space: current_participatory_space } %> + <% end %> +
+
+
+ +<%= javascript_include_tag "decidim/initiatives/scoped_type" %> diff --git a/app/views/decidim/initiatives/initiatives/_form.html.erb b/app/views/decidim/initiatives/initiatives/_form.html.erb new file mode 100644 index 0000000..7f47e0b --- /dev/null +++ b/app/views/decidim/initiatives/initiatives/_form.html.erb @@ -0,0 +1,112 @@ +<%= form_required_explanation %> + +
+ <%= form.text_field :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.title) %> +
+ +
+ <%= form.editor :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description) %> +
+ +
+ <%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+ +
+ <%= form.select :state, + Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] }, + {}, + { disabled: !@form.state_updatable? } %> +
+ +<% unless single_initiative_type? %> +
+ <%= form.select :type_id, + initiative_type_options, + {}, + { + disabled: !@form.signature_type_updatable?, + "data-scope-selector": "initiative_decidim_scope_id", + "data-scope-id": form.object.scope_id.to_s, + "data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url, + "data-signature-types-selector": "initiative_signature_type", + "data-signature-type": current_initiative.signature_type, + "data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url + } %> +
+<% end %> + +
+ <%= form.select :scope_id, + @form.available_scopes.map { |scope| [translated_attribute(scope.scope_name), scope&.scope&.id] }, + { disabled: !@form.state_updatable? } %> +
+ +<% if can_edit_custom_signature_end_date?(current_initiative) %> +
+ <%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %> +
+<% end %> + +<% if current_initiative.area_enabled? %> +
+ <%= form.areas_select :area_id, + areas_for_select(current_organization), + { + selected: current_initiative.decidim_area_id, + include_blank: current_initiative.decidim_area_id.blank? || current_initiative.created? + }, + disabled: !@form.area_updatable? %> +
+<% end %> + +
+ <%= form.select :signature_type, form.object.signature_type_options, {}, { disabled: !@form.signature_type_updatable? } %> +
+<% if current_initiative.type.attachments_enabled? %> +
+ <%= t("attachment_legend", scope: "decidim.initiatives.form") %> + + <% if @form.photos.any? %> + <% @form.photos.each do |photo| %> + + <% end %> + <% end %> + + <% if @form.documents.any? %> + <% @form.documents.each do |document| %> +
+ <%= link_to translated_attribute(document.title), document.url %> + <%= document.file_type %> <%= number_to_human_size(document.file_size) %> + <%= form.hidden_field :documents, multiple: true, value: document.id, id: "document-#{document.id}" %> + +
+ <% end %> + <% end %> + +
+ <%= form.file_field :add_documents, multiple: true, label: t("add_attachments", scope: "decidim.initiatives.form") %> +
+
+<% end %> + +<% if current_initiative.type.promoting_committee_enabled? %> + <%= render partial: "committee_members" %> +<% end %> + +<%= javascript_include_tag "decidim/initiatives/scoped_type" %>