forked from fixin.me/fixin.me
Prevent table columns' width change on form toggle
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
|
||||
<div class="flex reverse">
|
||||
<%= form.button id: :create_measurement_button, disabled: true -%>
|
||||
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
||||
<%= image_link_to t(:discard), "close-outline", measurements_path, name: :discard,
|
||||
class: 'auxiliary dangerous', onclick: render_turbo_stream('form_close') %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<%= tabular_fields_for @quantity, form: form_tag do |form| %>
|
||||
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
|
||||
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
|
||||
<%# locals: (record: Quantity.new, **attrs) %>
|
||||
<%= tabular_fields_for record, form: attrs.dig(:data, :form) do |form| %>
|
||||
<%- tag.tr class: "form", onkeydown: "formProcessKey(event)", **attrs do %>
|
||||
|
||||
<td style="--depth:<%= @quantity.depth %>">
|
||||
<td style="--depth:<%= form.object.depth %>">
|
||||
<%= form.text_field :name, autofocus: true, class: 'hstretch', required: true %>
|
||||
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
||||
|
||||
<td class="flex">
|
||||
<%= form.button %>
|
||||
<%= image_link_to t(:cancel), "close-outline", quantities_path,
|
||||
class: 'dangerous', name: :cancel,
|
||||
onclick: render_turbo_stream('form_close', {row: row}) %>
|
||||
<td><%= form.button %>
|
||||
<td>
|
||||
<%= image_link_to t(:discard), "close-outline", quantities_path,
|
||||
class: 'dangerous', name: :discard,
|
||||
onclick: render_turbo_stream('form_close', {id: attrs[:id]}) %>
|
||||
<td><!-- TODO: add aria-disabled drag handle with proper vertical alignment? -->
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<%= turbo_stream.close_form row %>
|
||||
<%= turbo_stream.close_form id %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
<td><%= quantity.description %>
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="flex">
|
||||
<td>
|
||||
<%= image_link_to t('.new_subquantity'), 'plus-outline',
|
||||
new_quantity_path(quantity), id: dom_target(:new, quantity, :link),
|
||||
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||
|
||||
<td>
|
||||
<%= image_button_to_if quantity.destroyable?, t('.destroy'), 'delete-outline',
|
||||
quantity_path(quantity), method: :delete %>
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<% ids = {row: dom_target(:edit, @quantity),
|
||||
hidden_row: dom_target(@quantity),
|
||||
link: nil,
|
||||
form_tag: dom_target(:edit, @quantity, :form)} %>
|
||||
<% attrs = {record: @quantity,
|
||||
id: dom_target(:edit, @quantity),
|
||||
data: {form: dom_target(:edit, @quantity, :form),
|
||||
hidden_row: dom_target(@quantity),
|
||||
link: nil}} %>
|
||||
|
||||
<%= turbo_stream.append_all 'body' do %>
|
||||
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do %>
|
||||
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.hide ids[:hidden_row] %>
|
||||
<%= turbo_stream.after @quantity, partial: 'form', locals: ids -%>
|
||||
<%= turbo_stream.hide attrs[:data][:hidden_row] %>
|
||||
<%= turbo_stream.after @quantity, partial: 'form', locals: attrs -%>
|
||||
|
||||
@@ -15,17 +15,22 @@
|
||||
<th class="hmintext"><%= Quantity.human_attribute_name(:name) %>
|
||||
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<th><%= t :actions %>
|
||||
<th>
|
||||
<th colspan="3"><%= t :actions %>
|
||||
|
||||
<tr id="quantity_" hidden
|
||||
ondragover="dragOver(event)" ondrop="drop(event)"
|
||||
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
||||
data-drop-id="quantity_"
|
||||
data-drop-id-param="<%= field_name(:quantity, :parent_id) %>">
|
||||
<th colspan="4"><%= t '.top_level_drop' %>
|
||||
<th colspan="5"><%= t '.top_level_drop' %>
|
||||
<% end %>
|
||||
|
||||
<%= render @quantities %>
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<tr id="endmark" hidden>
|
||||
|
||||
<tfoot>
|
||||
<%= render partial: 'form', locals: {hidden: true} %>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<% target_id = dom_target(:new, @quantity.parent || :quantity) %>
|
||||
<% ids = {row: target_id,
|
||||
hidden_row: nil,
|
||||
link: dom_target(target_id, :link),
|
||||
form_tag: dom_target(target_id, :form)} %>
|
||||
<% attrs = {record: @quantity,
|
||||
id: target_id,
|
||||
data: {form: dom_target(target_id, :form),
|
||||
hidden_row: nil,
|
||||
link: dom_target(target_id, :link)}} %>
|
||||
|
||||
<%= turbo_stream.disable ids[:link] -%>
|
||||
<%= turbo_stream.disable attrs[:data][:link] -%>
|
||||
|
||||
<%= turbo_stream.append_all 'body' do %>
|
||||
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do |form| %>
|
||||
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do |form| %>
|
||||
<%= form.hidden_field :parent_id if @quantity.parent_id? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: ids %>
|
||||
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: attrs %>
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<%= tabular_fields_for @unit, form: form_tag do |form| %>
|
||||
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
|
||||
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
|
||||
<%# locals: (record: Unit.new, **attrs) %>
|
||||
<%= tabular_fields_for record, form: attrs.dig(:data, :form) do |form| %>
|
||||
<%- tag.tr class: "form", onkeydown: "formProcessKey(event)", **attrs do %>
|
||||
|
||||
<td style="--depth:<%= @unit.base_id? ? 1 : 0 %>">
|
||||
<td style="--depth:<%= form.object.base_id? ? 1 : 0 %>">
|
||||
<%= form.text_field :symbol, autofocus: true, class: 'hstretch', required: true %>
|
||||
<td>
|
||||
<% if @unit.base_id? %>
|
||||
<% if form.object.base_id? %>
|
||||
<%= form.number_field :multiplier, class: 'hstretch', required: true %>
|
||||
<% end %>
|
||||
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
|
||||
|
||||
<td class="flex">
|
||||
<%= form.button %>
|
||||
<%= image_link_to t(:cancel), "close-outline", units_path, class: 'dangerous',
|
||||
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
||||
<td><%= form.button %>
|
||||
<td>
|
||||
<%= image_link_to t(:discard), "close-outline", units_path, class: 'dangerous',
|
||||
name: :discard, onclick: render_turbo_stream('form_close', {id: attrs[:id]}) %>
|
||||
<td><!-- TODO: add aria-disabled drag handle with proper vertical alignment? -->
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
<%= turbo_stream.close_form row %>
|
||||
<%= turbo_stream.close_form id %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
<td><%= unit.description %>
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="flex">
|
||||
<td>
|
||||
<% unless unit.base_id? %>
|
||||
<%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit),
|
||||
id: dom_target(:new, unit, :link), onclick: 'this.blur();',
|
||||
data: {turbo_stream: true} %>
|
||||
<% end %>
|
||||
|
||||
<td>
|
||||
<%= image_button_to_if unit.movable?, t('.destroy'), 'delete-outline',
|
||||
unit_path(unit), method: :delete %>
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<% ids = {row: dom_target(:edit, @unit),
|
||||
hidden_row: dom_target(@unit),
|
||||
link: nil,
|
||||
form_tag: dom_target(:edit, @unit, :form)} %>
|
||||
<% attrs = {record: @unit,
|
||||
id: dom_target(:edit, @unit),
|
||||
data: {form: dom_target(:edit, @unit, :form),
|
||||
hidden_row: dom_target(@unit),
|
||||
link: nil}} %>
|
||||
|
||||
<%= turbo_stream.append_all 'body' do %>
|
||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do %>
|
||||
<%- tabular_form_with model: @unit, html: {id: attrs[:data][:form]} do %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.hide ids[:hidden_row] %>
|
||||
<%= turbo_stream.after @unit, partial: 'form', locals: ids -%>
|
||||
<%= turbo_stream.hide attrs[:data][:hidden_row] %>
|
||||
<%= turbo_stream.after @unit, partial: 'form', locals: attrs -%>
|
||||
|
||||
@@ -16,18 +16,26 @@
|
||||
<th class="hminnumber"><%= Unit.human_attribute_name(:multiplier) %>
|
||||
<th class="hexpand"><%= Unit.human_attribute_name(:description) %>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<th><%= t :actions %>
|
||||
<th>
|
||||
<th colspan="3"><%= t :actions %>
|
||||
|
||||
<tr id="unit_" hidden
|
||||
ondragover="dragOver(event)" ondrop="drop(event)"
|
||||
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
|
||||
data-drop-id="unit_" data-drop-id-param="<%= field_name(:unit, :base_id) %>">
|
||||
<th colspan="5"><%= t '.top_level_drop' %>
|
||||
<th colspan="6"><%= t '.top_level_drop' %>
|
||||
<% end %>
|
||||
|
||||
<%= render @units %>
|
||||
<%# Hidden rows with IDs allow simplier row insertion by using only
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<%# Hidden header and `#endmark` rows allows simplier row insertion by using only
|
||||
turbo_stream #after/#before instead of #after + #prepend/#before + #append. %>
|
||||
<%# TODO: replace with custom turbo_stream action, e.g. #afterrow that #prepend-s
|
||||
if ID has `rows` property (`rows` in object) and #after otherwise? %>
|
||||
<tr id="endmark" hidden>
|
||||
|
||||
<tfoot>
|
||||
<%# Insert form to prevent actions column width change on form toggle. %>
|
||||
<%= render partial: 'form', locals: {hidden: true} %>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<% target_id = dom_target(:new, @unit.base || :unit) %>
|
||||
<% ids = {row: target_id,
|
||||
hidden_row: nil,
|
||||
link: dom_target(target_id, :link),
|
||||
form_tag: dom_target(target_id, :form)} %>
|
||||
<% attrs = {record: @unit,
|
||||
id: target_id,
|
||||
data: {form: dom_target(target_id, :form),
|
||||
hidden_row: nil,
|
||||
link: dom_target(target_id, :link)}} %>
|
||||
|
||||
<%= turbo_stream.disable ids[:link] -%>
|
||||
<%= turbo_stream.disable attrs[:data][:link] -%>
|
||||
<%# TODO: disable base unit delete button if subunit; same for quantities %>
|
||||
|
||||
<%= turbo_stream.append_all 'body' do %>
|
||||
<%- tabular_form_with model: @unit, html: {id: ids[:form_tag]} do |form| %>
|
||||
<%- tabular_form_with model: @unit, html: {id: attrs[:data][:form]} do |form| %>
|
||||
<%= form.hidden_field :base_id if @unit.base_id? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.after @unit.base || :unit_, partial: 'form', locals: ids %>
|
||||
<%= turbo_stream.after @unit.base || :unit_, partial: 'form', locals: attrs %>
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
<% end %>
|
||||
<%= turbo_stream.remove @unit %>
|
||||
<%= turbo_stream.before @before || :endmark, @unit %>
|
||||
<%# TODO: move new subunit form as well if open %>
|
||||
|
||||
Reference in New Issue
Block a user