Commit 28a26632 authored by Klaus Stein's avatar Klaus Stein
Browse files

Add dates editing to map edit

This is completely unfinished work but it works
parent 20cd83c1
......@@ -76,6 +76,6 @@ class MapsController < ApplicationController
puts params.require(:map).inspect
params.require(:map).permit(:title, :place_id, :repository_id,
:description, :district, :basemap, :scale, :orientation, :papersize, :techniques, :platenumber, :creator, :legend, :damage_categories, :doi, :repository, :repo_location, :repo_doc_ref, :repo_url, :copyright, :copyright_holder, category_ids: [])
:description, :district, :basemap, :scale, :orientation, :papersize, :techniques, :platenumber, :creator, :legend, :damage_categories, :doi, :repository, :repo_location, :repo_doc_ref, :repo_url, :copyright, :copyright_holder, category_ids: [], itemdates_attributes: [:id, :edtfdate, :description])
end
end
......@@ -40,6 +40,7 @@ class Map < ApplicationRecord
has_one :wda_map, dependent: :destroy
has_one :dfg_map, dependent: :destroy
has_many :itemdates, as: :dated
accepts_nested_attributes_for :itemdates, reject_if: :all_blank, allow_destroy: true
has_many :image_maps, dependent: :destroy
has_and_belongs_to_many :categories
......
<%= form_with(model: map, class: 'map') do |form| %>
<%= form_with(model: map, class: 'map', data: { controller: 'nested-form' }) do |form| %>
<% if map.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(map.errors.count, "error") %> prohibited this map from being saved:</h2>
<ul>
<% map.errors.each do |error| %>
<li><%= error.full_message %></li>
......@@ -10,12 +9,27 @@
</ul>
</div>
<% end %>
<template data-nested-form-target="template">
<%= form.fields_for :itemdates, Itemdate.new, child_index: 'NEW_RECORD' do |itemdate_fields| %>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
</template>
<table>
<tr class="field"><th><%= form.label :title %></th><td><%= form.text_field :title %></td></tr>
<tr class="field"><th><%= form.label :place_id %></th><td><%= form.collection_select(:place_id, Place.with_name, :id, :name, {include_blank: true}) %></td></tr>
<tr class="field"><th><%= form.label :categories %></th><td><%= form.collection_select(:category_ids, Category.all, :id, :name, {label: 'Category(s)'}, {multiple: true}) %></td></tr>
<tr class="field"><th><%= form.label :description %></th><td><%= form.text_area :description %></td></tr>
<tr class="field"><th><%= form.label :district %></th><td><%= form.text_field :district %></td></tr>
<tr class="field"><th><%= form.label :description %></th><td><%= form.text_area :description %></td></tr>
<tr class="field"><th>Dates:</th>
<td><%= form.fields_for :itemdates do |itemdate_fields| %>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
<div data-nested-form-target="target"></div>
<button type="button" data-action="nested-form#add">
Add date
</button>
</td></tr>
<tr class="field"><th><%= form.label :district %></th><td><%= form.text_field :district %></td></tr>
<tr class="field"><th><%= form.label :basemap %></th><td><%= form.text_field :basemap %></td></tr>
<tr class="field"><th><%= form.label :scale %></th><td><%= form.text_field :scale %></td></tr>
<tr class="field"><th><%= form.label :orientation %></th><td><%= form.text_field :orientation %></td></tr>
......
<table class="nested-form-wrapper" data-new-record="<%= form.object.new_record? %>">
<tr>
<th><%= form.label :edtfdate %></th>
<td><%= form.text_field :edtfdate, value: form.object.edtfdate&.edtf %></td>
<td><button type="button" data-action="nested-form#remove">
Remove date
</button></td>
</tr>
<tr>
<th><%= form.label :description %></th>
<td><%= form.text_area :description %></td>
</tr>
<%= form.hidden_field :_destroy %>
</table>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment