From d14700c51d692335f001a93c2f6b13b135783206 Mon Sep 17 00:00:00 2001 From: IN COMMON Collective Date: Thu, 8 Apr 2021 16:34:15 +0200 Subject: [FIX] Use form model to create/edit resources (fixes #4, fixes #5, refs #3) Since we must associate other models (e.g., classifications) to a Resource, we use a composite model to save all changes inside a database transaction. This approach makes it simpler to handle resources and their associations. Work remains to fix the geolocation and reverse geolocation to ensure these are in sync. --- app/views/resources/_form.html.erb | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'app/views/resources/_form.html.erb') diff --git a/app/views/resources/_form.html.erb b/app/views/resources/_form.html.erb index 89745bd..648834d 100644 --- a/app/views/resources/_form.html.erb +++ b/app/views/resources/_form.html.erb @@ -1,12 +1,24 @@ -
+<% if resource.errors.any? %> +
+

<%= pluralize(resource.errors.count, "error") %> prohibited this resource from being saved:

+ +
    + <% resource.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+<% end %> + +
<%= tag.legend "Propriétés de la ressource" %> -
+
<%= f.label :name %>
-
<%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux', value: resource.name %>
+
<%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux' %>
<%= f.label :summary %>
-
<%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale', value: resource.name %>
+
<%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale' %>
<%= f.label :description %>
<%= f.text_area :description, cols: 72, rows: 10, placeholder: '## Un choix pertinent @@ -29,33 +41,34 @@ La description _peut_ comporter du [Markdown].
<%= tag.legend "Classification" %> <%# TODO Add a taxonomy selector %> - <%= section_select(current_agent.taxonomies&.first || Taxonomy.first) %> + <%= section_select(current_agent.taxonomies&.first || Taxonomy.first, resource.section_ids, name: 'resource_form[section_ids]') %>
<%= tag.legend "Coordonées géographiques" %> <%# TODO Add a graphical geo selector %> -
+
<%= f.label :address %>
-
<%= f.text_field :address, value: resource.address, placeholder: 'Rue aux herbes, 123' %>
+
<%= f.text_field :address, placeholder: 'Rue aux herbes, 123' %>
<%= f.label :postal_code %>
-
<%= f.text_field :postal_code, value: resource.postal_code, placeholder: '1000' %>
+
<%= f.text_field :postal_code, placeholder: '1000' %>
<%= f.label :city %>
-
<%= f.text_field :city, value: resource.city, placeholder: 'Bruxelles' %>
+
<%= f.text_field :city, placeholder: 'Bruxelles' %>
-
+
<%= f.label :longitude %>
-
<%= f.text_field :longitude, value: resource.longitude, placeholder: '0.56789012' %>
+
<%= f.text_field :longitude, placeholder: '0.56789012', pattern: '[\d]+.[\d]+' %>
<%= f.label :latitude %>
-
<%= f.text_field :latitude, value: resource.latitude, placeholder: '50.12345678' %>
+
<%= f.text_field :latitude, placeholder: '50.12345678', pattern: '[\d]+.[\d]+' %>
<%= f.hidden_field :agent_id, value: current_agent.id %> +<%= f.hidden_field :source, value: current_agent.name %>

<%= f.submit 'Save' %>

-- cgit v1.2.3