Add Units

This commit is contained in:
2023-07-06 18:34:16 +02:00
parent 6f415dfb62
commit a4745c9cb8
21 changed files with 285 additions and 15 deletions

View File

@@ -0,0 +1,26 @@
<div id="add-unit" <%= 'style=display:none;' if @unit.errors.empty? %>>
<h2><%= t ".heading_new_unit" %></h2>
<%= labelled_form_for @unit,
url: project_units_path(@project),
html: {id: 'unit-add-form', name: 'unit-add-form'} do |f| %>
<%= render partial: 'units/form', locals: {f: f} %>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#", onclick: '$("#add-unit").hide(); return false;' %>
<% end %>
<hr>
</div>
<%= error_messages_for @unit %>
<div class="box tabular">
<div class="splitcontent">
<div class="splitcontentleft">
<p><%= f.text_field :shortname, required: true, size: 20 %></p>
</div>
<div class="splitcontentright">
<p><%= f.text_field :name, size: 60 %></p>
</div>
</div>
</div>

View File

@@ -0,0 +1 @@
/var/www/app/views/units/new.html.erb

View File

@@ -0,0 +1,35 @@
<div class="contextual">
<% if current_user.at_least(:active) %>
<%= image_link_to t(".add_unit"), "plus-outline", new_unit_path %>
<% end %>
</div>
<table class="items" id="units">
<thead>
<tr>
<th><%= User.human_attribute_name(:symbol).capitalize %></th>
<th><%= User.human_attribute_name(:name).capitalize %></th>
<th><%= User.human_attribute_name(:multiplier).capitalize %></th>
<% if current_user.at_least(:active) %>
<th><%= t :actions %></th>
<% end %>
</tr>
</thead>
<tbody>
<% Unit.each_with_level(@units) do |unit, level| %>
<tr>
<td <%= "style=padding-left:0.5rem;" if level > 0 %>>
<%= link_to unit.symbol, edit_unit_path(unit) %>
</td>
<td><%= unit.name %></td>
<td class="number"><%= unit.multiplier unless unit.multiplier == 1 %></td>
<% if current_user.at_least(:active) %>
<td class="actions">
<%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
method: :delete %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,22 @@
<% content_for :navigation, flush: true do %>
<div class="left">
<%= image_link_to t(:back), "arrow-left-bold-outline",
request.referer.present? ? :back : units_url %>
</div>
<% end %>
<%= tabular_form_for @unit do |f| %>
<%= f.text_field :symbol, required: true, size: 10, autofocus: true, autocomplete: "off" %>
<%= f.text_field :name, size: 25, autocomplete: "off" %>
<% if current_user.units.roots.count %>
<%= f.select :base_id,
current_user.units.roots.collect { |u| ["#{u.symbol}#{' - ' + u.name if u.name}", u.id] },
{include_blank: t(".none")},
onchange: 'this.form.unit_multiplier.disabled = (this.value == "");' %>
<%= f.number_field :multiplier, step: "any", disabled: @unit.base.nil?, size: 10,
autocomplete: "off" %>
<% end %>
<%= f.submit @unit.persisted? ? t(:update) : t(:add) %>
<% end %>