forked from fixin.me/fixin.me
Update Measurements#new form pathnames on actions
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
<% @readouts.each do |readout| %>
|
||||
<%= tabular_fields_for 'readouts[]', readout do |form| %>
|
||||
<% row = dom_id(form.object.quantity, :new, :readout) %>
|
||||
<%- tag.tr id: row, onkeydown: 'processKey(event)' do %>
|
||||
<%- tag.tr id: dom_id(readout.quantity, :new, :readout),
|
||||
onkeydown: 'processKey(event)' do %>
|
||||
<%= tag.td id: dom_id(readout.quantity, nil, :pathname) do %>
|
||||
<%= readout.quantity.relative_pathname(@common_ancestor) %>
|
||||
<%end%>
|
||||
<td>
|
||||
<%= form.object.quantity.pathname.delete_prefix(@closest_ancestor.pathname) %>
|
||||
<%= form.hidden_field :quantity_id %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.number_field :value, required: true, autofocus: true,
|
||||
size: 10 %>
|
||||
<%= form.number_field :value, required: true, autofocus: true, size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.select :unit_id, options_from_collection_for_select(
|
||||
@@ -17,9 +15,10 @@
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<%= image_link_to t(:delete), 'delete-outline', quantities_path,
|
||||
class: 'dangerous',
|
||||
onclick: render_turbo_stream('form_destroy_row', {row: row}) %>
|
||||
<%= image_button_tag t(:delete), 'delete-outline', class: 'dangerous',
|
||||
formaction: discard_new_measurement_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
<%= form.hidden_field :quantity_id %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<%= turbo_stream.remove row %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= tabular_form_with url: new_measurement_path, html: {id: :new_readouts_form} do %>
|
||||
<% if @readouts&.present? %>
|
||||
<fieldset>
|
||||
<%= tag.legend @closest_ancestor.pathname if @closest_ancestor&.pathname %>
|
||||
<%= tag.legend id: :new_readouts_form_legend %>
|
||||
<table class="items centered">
|
||||
<tbody id="readouts">
|
||||
<tr id="new_readouts_actions">
|
||||
|
||||
7
app/views/measurements/_form_repath.html.erb
Normal file
7
app/views/measurements/_form_repath.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<%= turbo_stream.update(:new_readouts_form_legend) { @common_ancestor&.pathname } %>
|
||||
|
||||
<% @prev_quantities.each do |pq| %>
|
||||
<%= turbo_stream.update dom_id(pq, nil, :pathname) do %>
|
||||
<%= pq.relative_pathname(@common_ancestor) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
2
app/views/measurements/discard.turbo_stream.erb
Normal file
2
app/views/measurements/discard.turbo_stream.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
@@ -6,15 +6,14 @@
|
||||
<%= select_tag :id, options_from_collection_for_select(
|
||||
@quantities, :id, ->(q){ sanitize(' ' * q.depth + q.name) }
|
||||
), form: :new_readouts_form %>
|
||||
<% common_options = {form: :new_readouts_form, formaction: new_measurement_path,
|
||||
formmethod: :get, formnovalidate: true,
|
||||
data: {turbo_stream: true}} %>
|
||||
<%= image_button_tag t('.new_quantity'), 'plus-outline', name: :scope,
|
||||
**common_options -%>
|
||||
<%= image_button_tag t('.new_children'), 'plus-multiple-outline', name: :scope,
|
||||
value: :children, **common_options -%>
|
||||
<%= image_button_tag t('.new_subtree'), 'plus-multiple-outline', name: :scope,
|
||||
value: :subtree, **common_options -%>
|
||||
<% common_options = {form: :new_readouts_form, formmethod: :get,
|
||||
formnovalidate: true, data: {turbo_stream: true}} %>
|
||||
<%= image_button_tag t('.new_quantity'), 'plus-outline',
|
||||
formaction: new_measurement_path, **common_options -%>
|
||||
<%= image_button_tag t('.new_children'), 'plus-multiple-outline',
|
||||
formaction: new_measurement_path(:children), **common_options -%>
|
||||
<%= image_button_tag t('.new_subtree'), 'plus-multiple-outline',
|
||||
formaction: new_measurement_path(:subtree), **common_options -%>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<%= render partial: 'form_frame' %>
|
||||
<% end if @prev_quantities.empty? %>
|
||||
|
||||
<%= render partial: 'form_repath' %>
|
||||
|
||||
<%= turbo_stream.before :new_readouts_actions do %>
|
||||
<%= render partial: 'form' %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user