forked from fixin.me/fixin.me
Enable creation of subunits
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<%= fields_for @unit do |form| %>
|
||||
<tr id="<%= dom_id(@unit) %>" onkeydown="processKey(event)">
|
||||
<td>
|
||||
<td class="<%= class_names({subunit: @unit.base}) %>">
|
||||
<%= form.text_field :symbol, form: :unit_form, required: true, autofocus: true, size: 12,
|
||||
maxlength: @unit.class.columns_hash['symbol'].limit, autocomplete: "off" %>
|
||||
</td>
|
||||
@@ -10,8 +10,9 @@
|
||||
</td>
|
||||
<td>
|
||||
<% unless @unit.base.nil? %>
|
||||
<%= form.number_field :multiplier, form: :unit_form, step: "any", size: 10,
|
||||
autocomplete: "off" %>
|
||||
<%= form.hidden_field :base_id, form: :unit_form %>
|
||||
<%= form.number_field :multiplier, form: :unit_form, required: true, step: "any",
|
||||
size: 10, autocomplete: "off" %>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
@@ -23,4 +24,3 @@
|
||||
</tr>
|
||||
<!-- TODO: display error_messages_for unit -->
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
<tr>
|
||||
<td class="link">
|
||||
<%= link_to unit.symbol, edit_unit_path(unit), class: unit.base.nil? ? '' : 'subunit' %>
|
||||
<tr id="<%= dom_id(unit) %>">
|
||||
<td class="<%= class_names('link', {subunit: unit.base}) %>">
|
||||
<%= link_to unit.symbol, edit_unit_path(unit) %>
|
||||
</td>
|
||||
<td><%= unit.name %></td>
|
||||
<td class="number"><%= scientifize(unit.multiplier) if unit.multiplier %></td>
|
||||
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="actions">
|
||||
<% if unit.base.nil? %>
|
||||
<%= image_link_to t(".add_subunit"), "plus-outline", new_unit_path(unit),
|
||||
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||
<% end %>
|
||||
|
||||
<%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
|
||||
method: :delete %>
|
||||
</td>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<%= turbo_stream.prepend :units do %>
|
||||
<%= render partial: 'form' %>
|
||||
<%= turbo_stream.disable :add_unit %>
|
||||
<%= turbo_stream.disable_all 'td.actions .button' %>
|
||||
|
||||
<% case %>
|
||||
<% when @unit.errors.present? %>
|
||||
<%= turbo_stream.replace @unit, partial: 'form' %>
|
||||
<% when @unit.base.nil? %>
|
||||
<%= turbo_stream.prepend :units, partial: 'form' %>
|
||||
<% else %>
|
||||
<%= turbo_stream.after @unit.base, partial: 'form' %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.update :unit_form_frame do %>
|
||||
|
||||
Reference in New Issue
Block a user