forked from fixin.me/fixin.me
Alternative new Measurement form, WIP
This commit is contained in:
@@ -1,25 +1,29 @@
|
||||
<% @readouts.each do |readout| %>
|
||||
<%= tabular_fields_for 'readouts[]', readout do |form| %>
|
||||
<%- 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.number_field :value, required: true, autofocus: true, size: 10 %>
|
||||
</td>
|
||||
<td>
|
||||
<%= form.select :unit_id, options_from_collection_for_select(
|
||||
@units, :id, ->(u){ sanitize(' '*(u.base_id ? 1 : 0) + u.symbol) }
|
||||
) %>
|
||||
</td>
|
||||
|
||||
<td class="actions">
|
||||
<%= image_button_tag '', '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 %>
|
||||
<%= 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') %>
|
||||
</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} %>
|
||||
</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>
|
||||
<% end %>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<%= turbo_stream.update :new_readouts_form %>
|
||||
<%= turbo_stream.update :measurement_form %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<%= tabular_fields_for Readout.new do |form| %>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<%= tag.span id: :new_readouts_form_legend %>
|
||||
<%= image_link_to '', "close-outline", measurements_path, name: :cancel,
|
||||
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
||||
</legend>
|
||||
<table class="items centered">
|
||||
<tbody id="readouts">
|
||||
<tr id="new_readouts_actions">
|
||||
<td colspan="4"><div class="actions centered"><%= form.button %></div></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
@@ -1,7 +0,0 @@
|
||||
<%= 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 %>
|
||||
@@ -1,2 +0,0 @@
|
||||
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
|
||||
<%= render partial: 'form_repath' %>
|
||||
@@ -1,20 +1,10 @@
|
||||
<div class="topside vflex">
|
||||
<%# TODO: show hint when no quantities/units defined %>
|
||||
<div class="rightside buttongrid">
|
||||
<% if current_user.at_least(:active) %>
|
||||
<%# TODO: show hint when no quantities/units defined %>
|
||||
<%= tabular_form_with url: new_measurement_path,
|
||||
html: {id: :new_readouts_form} do |f| %>
|
||||
<% end %>
|
||||
<div class="hflex">
|
||||
<%= 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, formmethod: :get,
|
||||
formnovalidate: true, data: {turbo_stream: true}} %>
|
||||
<%= image_button_tag t('.new_quantity'), 'plus-outline', **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>
|
||||
<%= image_link_to t('.new_measurement'), 'plus-outline', new_measurement_path,
|
||||
id: :new_measurement_link, onclick: 'this.blur();',
|
||||
data: {turbo_stream: true} %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= tag.div class: 'main', id: :measurement_form %>
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
<%= turbo_stream.update :new_readouts_form do %>
|
||||
<%= render partial: 'form_frame' %>
|
||||
<% end if @prev_quantities.empty? %>
|
||||
|
||||
<%= render partial: 'form_repath' %>
|
||||
|
||||
<%= turbo_stream.before :new_readouts_actions do %>
|
||||
<%= turbo_stream.disable :new_measurement_link -%>
|
||||
<%= turbo_stream.update :measurement_form do %>
|
||||
<%= render partial: 'form' %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user