1
0

Added ingredient index and form

This commit is contained in:
cryptogopher
2019-09-13 14:48:43 +02:00
parent c916e7fd3c
commit c82f903360
9 changed files with 77 additions and 22 deletions

View File

@@ -0,0 +1,10 @@
<%= error_messages_for @ingredient %>
<div class="box tabular">
<p><%= f.text_field :name, size: 40, required: true %></p>
<p>
<%= f.number_field :ref_amount, size: 8, required: true, min: 0 %>
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
</p>
<p><%= f.select :group, group_options, required: true %></p>
</div>

View File

@@ -4,40 +4,45 @@
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".heading_new_unit"), '#', :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-unit", "unit_shortname"); return false;' %>
<%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-ingredient", "ingredient_name"); return false;' %>
<% end %>
</div>
<div id="add-unit" <%= 'style=display:none;' if @unit.errors.empty? %>>
<h2><%= t ".heading_new_unit" %></h2>
<div id="add-ingredient" <%= 'style=display:none;' if @ingredient.errors.empty? %>>
<h2><%= t ".heading_new_ingredient" %></h2>
<%= labelled_form_for @unit,
:url => project_units_path(@project),
:html => {:id => 'unit-form'} do |f| %>
<%= render :partial => 'units/form', :locals => { :f => f } %>
<%= labelled_form_for @ingredient,
:url => project_ingredients_path(@project),
:html => {:id => 'ingredient-form'} do |f| %>
<%= render :partial => 'ingredients/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-unit").hide()' %>
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-ingredient").hide()' %>
<% end %>
<hr>
</div>
<h2><%= t ".heading" %></h2>
<% if @units.any? %>
<% if @ingredients.any? %>
<table class="list">
<thead>
<tr>
<th><%= l(:field_shortname) %></th>
<th><%= l(:field_name) %></th>
<th><%= l(:field_ref_amount) %></th>
<th><%= l(:field_ref_unit) %></th>
<th><%= l(:field_group) %></th>
<th><%= l(:field_source) %></th>
<th style="width:15%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% @units.each do |u| %>
<tr id="unit-<%= u.id %>" class="unit">
<td class="shortname"><%= u.shortname %></td>
<td class="unitname"><%= u.name %></td>
<td><%= delete_link unit_path(u), data: {} %></td>
<% @ingredients.each do |i| %>
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
<td class="ingredientname"><%= i.name %></td>
<td class="ref_amount"><%= i.ref_amount %> [<%= i.ref_unit %>]</td>
<td class="group"><%= i.group %></td>
<td class="source"><%= i.source %></td>
<td><%= delete_link ingredient_path(i), data: {} %></td>
</tr>
<% end %>
</tbody>