forked from fixin.me/fixin.me
Back to single-select form w/ multiple select actions
This commit is contained in:
@@ -1,29 +1,40 @@
|
||||
<%= tabular_form_with model: Measurement.new do |form| %>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= tag.span id: :measurement_form_legend %>
|
||||
<%= image_link_to '', "close-outline", measurements_path, name: :cancel,
|
||||
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
||||
<%= tag.span t('.no_items'), id: :measurement_form_legend %>
|
||||
<%= image_link_to '', "pencil-outline", measurements_path,
|
||||
data: {turbo_stream: true} %>
|
||||
</legend>
|
||||
<table class="items">
|
||||
<tbody id="readouts">
|
||||
<tr id="readouts_form">
|
||||
<td>
|
||||
<%= select_tag :id, quantity_options(@quantities), onchange:
|
||||
"this.form.requestSubmit(document.getElementById('readout_submit'));",
|
||||
class: 'quantity' %>
|
||||
<%= form.submit id: :readout_submit, name: nil, value: nil,
|
||||
formaction: new_readout_path, formmethod: :get, formnovalidate: true,
|
||||
hidden: true, data: {turbo_stream: true} %>
|
||||
<%= select_tag :id,
|
||||
options_from_collection_for_select(
|
||||
@quantities, :id, ->(q){ quantity_option_text(q, false) }
|
||||
), class: 'quantity' %>
|
||||
</td>
|
||||
<td colspan="3">
|
||||
<div class="actions">
|
||||
<% opts = {formaction: new_readout_path, formmethod: :get,
|
||||
formnovalidate: true, data: {turbo_stream: true}} %>
|
||||
<%= image_button_tag t('.new_readout'), 'plus-outline', id: :new_readout,
|
||||
value: nil, **opts -%>
|
||||
<%= image_button_tag t('.new_children'), 'plus-multiple-outline',
|
||||
value: :children, **opts -%>
|
||||
<%#= image_button_tag t('.new_subtree'), 'plus-multiple-outline',
|
||||
value: :subtree, **opts -%>
|
||||
<%= image_button_tag t('.new_leaves'), 'plus-multiple-outline',
|
||||
value: :leaves, **opts -%>
|
||||
</div>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr id="measurement_form_actions">
|
||||
<td colspan="4"><div class="actions centered"><%= form.button %></div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<div class="hflex centered">
|
||||
<%= form.button -%>
|
||||
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
||||
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -7,4 +7,10 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= tag.div class: 'main', id: :measurement_form %>
|
||||
<%= tag.div class: 'topside', id: :measurement_form %>
|
||||
|
||||
<table class="main">
|
||||
<tbody id="measurements">
|
||||
<%= render(@measurements) || render_no_items %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
<%# TODO: add readout reordering by dragging %>
|
||||
<%= 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'} %>
|
||||
<%= readout.quantity.relative_pathname(@superquantity) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.number_field :value, required: true, autofocus: true, size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.hidden_field :quantity_id %>
|
||||
<%= 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',
|
||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: :discard,
|
||||
formaction: discard_readouts_path(readout.quantity),
|
||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= turbo_stream.update(:measurement_form_legend) { @common_ancestor&.pathname } %>
|
||||
<%= turbo_stream.update(:measurement_form_legend) { @superquantity&.pathname } %>
|
||||
|
||||
<% @prev_quantities.each do |pq| %>
|
||||
<%= turbo_stream.update dom_id(pq, nil, :pathname) do %>
|
||||
<%= pq.relative_pathname(@common_ancestor) %>
|
||||
<%= pq.relative_pathname(@superquantity) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
5
app/views/readouts/discard.turbo_stream.erb
Normal file
5
app/views/readouts/discard.turbo_stream.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= turbo_stream.disable_all 'button[name="discard"]' if @prev_quantities.one? %>
|
||||
<%= turbo_stream.update_all "#id option[value=\"#{@quantity.id}\"]",
|
||||
quantity_option_text(@quantity, false) %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
@@ -1,7 +1,10 @@
|
||||
<%#= render partial: 'form_repath' %>
|
||||
|
||||
<%= render partial: 'form_repath' %>
|
||||
<%= turbo_stream.enable_all 'button[name="discard"]' if @prev_quantities.one? %>
|
||||
<%# TODO: disable Add actions accordingly (e.g. disable Children if childless or all
|
||||
children already added), then disable option once all actions unavailable %>
|
||||
<% @readouts.each do |r| %>
|
||||
<%= turbo_stream.disable_all "select.quantity option[value='#{r.quantity_id}']" %>
|
||||
<%= turbo_stream.update_all "#id option[value=\"#{r.quantity_id}\"]",
|
||||
quantity_option_text(r.quantity, true) %>
|
||||
<% end %>
|
||||
<%= turbo_stream.before :readouts_form do %>
|
||||
<%= render partial: 'form', collection: @readouts, as: :readout %>
|
||||
|
||||
Reference in New Issue
Block a user