forked from fixin.me/fixin.me
Alternative new Measurement form, WIP
This commit is contained in:
30
app/views/readouts/_form.html.erb
Normal file
30
app/views/readouts/_form.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<%= tabular_fields_for 'readouts[]', readout do |form| %>
|
||||
<%- tag.tr id: dom_id(readout.quantity, :new, :readout),
|
||||
onkeydown: 'processKey(event)' do %>
|
||||
<td>
|
||||
<%#= readout.quantity.relative_pathname(@common_ancestor) %>
|
||||
<%= form.collection_select :quantity_id, @user_quantities,
|
||||
:id, ->(q){ sanitize(' ' * q.depth + q.name) },
|
||||
{disabled: @quantities.map(&:id).delete!(form.object.quantity.id)},
|
||||
{class: 'quantity'} %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.number_field :value, required: true, autofocus: true, size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.collection_select :unit_id, @user_units, :id,
|
||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) } %>
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<%= image_button_tag t('.new_children'), 'plus-multiple-outline',
|
||||
formaction: new_measurement_path(readout.quantity, :children),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
<%#= image_button_tag t('.new_subtree'), 'plus-multiple-outline',
|
||||
formaction: new_measurement_path(:subtree), **common_options -%>
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous',
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
2
app/views/readouts/_form_discard.html.erb
Normal file
2
app/views/readouts/_form_discard.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
7
app/views/readouts/_form_repath.html.erb
Normal file
7
app/views/readouts/_form_repath.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<%= turbo_stream.update(:measurement_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 %>
|
||||
8
app/views/readouts/new.turbo_stream.erb
Normal file
8
app/views/readouts/new.turbo_stream.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
<%#= render partial: 'form_repath' %>
|
||||
|
||||
<% @readouts.each do |r| %>
|
||||
<%= turbo_stream.disable_all "select.quantity option[value='#{r.quantity_id}']" %>
|
||||
<% end %>
|
||||
<%= turbo_stream.before :readouts_form do %>
|
||||
<%= render partial: 'form', collection: @readouts, as: :readout %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user