1
0

Updated Quantity to use Formula

and upgraded controller actions to match Measurement/Ingredient
This commit is contained in:
cryptogopher
2020-02-19 17:57:29 +01:00
parent 544c0c5293
commit b7b7401833
12 changed files with 90 additions and 73 deletions

View File

@@ -0,0 +1,15 @@
<%= labelled_form_for @quantity,
url: quantity_path(@quantity),
method: :patch, remote: true,
html: {id: 'edit-quantity-form', name: 'edit-quantity-form'} do |f| %>
<%= render partial: 'quantities/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_save) %>
<%= link_to l(:button_cancel), "#",
onclick: '$(this).closest("tr").remove(); return false;' %>
</p>
</div>
<% end %>

View File

@@ -18,6 +18,7 @@
<%
next if q.new_record?
quantity_class = "quantity"
quantity_class += " primary" unless q.column_views.empty?
quantity_class += " project idnt idnt-#{level+1}"
%>
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
@@ -52,30 +53,6 @@
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
</td>
</tr>
<% next unless (q == @quantity) &&
((action_name == "edit") ||
(action_name == "update" && @quantity.errors.present?)) %>
<tr>
<td class="form" colspan="6">
<div id="edit-quantity">
<%= labelled_form_for @quantity,
url: quantity_path(@quantity),
method: :patch, remote: true,
html: {id: 'quantity-edit-form', name: 'quantity-edit-form'} do |f| %>
<%= render partial: 'quantities/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_save) %>
<%= link_to l(:button_cancel), "#",
onclick: '$(this).closest("tr").remove(); return false;' %>
</p>
</div>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,18 @@
<h2><%= t ".heading_new_quantity" %></h2>
<%= labelled_form_for @quantity,
url: project_quantities_path(@project),
remote: true,
html: {id: 'new-quantity-form', name: 'new-quantity-form'} do |f| %>
<%= render partial: 'quantities/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: '$("#new-quantity").empty(); return false;' %>
</p>
</div>
<% end %>
<hr>

View File

@@ -0,0 +1,3 @@
<%= render partial: 'body_trackers/flash' %>
$('#new-quantity').empty();
$('#quantities').html('<%= j render partial: 'quantities/index' %>');

View File

@@ -0,0 +1,6 @@
<%= render partial: 'body_trackers/flash' %>
<% if @quantity.destroyed? %>
<% @quantity_tree.each do |q| %>
$('tr[id=quantity-<%= q.id %>]').nextUntil('tr.quantity').addBack().remove();
<% end %>
<% end %>

View File

@@ -0,0 +1,8 @@
<%= render partial: 'body_trackers/flash' %>
$('tr[id=quantity-<%= @quantity.id %>]').nextUntil('tr.quantity').remove();
var columns = $('table > thead > tr > th').length;
$('tr[id=quantity-<%= @quantity.id %>]').nextAll('tr.quantity').first().before(
'<tr><td class="form" colspan="'+columns+'">' +
'<div id="edit-quantity"><%= j render partial: "quantities/edit_form" %></div>' +
'</td></tr>'
);

View File

@@ -1,28 +1,11 @@
<div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".link_new_quantity"), '#', class: 'icon icon-add',
onclick: '$("#add-quantity").toggle(); $("#quantity_name").focus(); return false;' %>
<%= link_to t(".link_new_quantity"), new_project_quantity_path(@project),
{remote: true, class: 'icon icon-add'} %>
<% end %>
</div>
<div id="add-quantity" <%= 'style=display:none;' if @quantity.errors.empty? %>>
<h2><%= t ".heading_new_quantity" %></h2>
<%= labelled_form_for @quantity,
url: project_quantities_path(@project),
html: {id: 'quantity-add-form', name: 'quantity-add-form'} do |f| %>
<%= render partial: 'quantities/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: '$("#add-quantity").hide(); return false;' %>
</p>
</div>
<% end %>
<hr>
<div id="new-quantity">
</div>
<h2><%= t ".heading" %></h2>

View File

@@ -0,0 +1,2 @@
<%= render partial: 'body_trackers/flash' %>
$('#new-quantity').html('<%= j render partial: 'quantities/new_form' %>');