Updated Quantity to use Formula
and upgraded controller actions to match Measurement/Ingredient
This commit is contained in:
15
app/views/quantities/_edit_form.html.erb
Normal file
15
app/views/quantities/_edit_form.html.erb
Normal 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 %>
|
||||
@@ -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>
|
||||
|
||||
18
app/views/quantities/_new_form.html.erb
Normal file
18
app/views/quantities/_new_form.html.erb
Normal 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>
|
||||
3
app/views/quantities/create.js.erb
Normal file
3
app/views/quantities/create.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= render partial: 'body_trackers/flash' %>
|
||||
$('#new-quantity').empty();
|
||||
$('#quantities').html('<%= j render partial: 'quantities/index' %>');
|
||||
6
app/views/quantities/destroy.js.erb
Normal file
6
app/views/quantities/destroy.js.erb
Normal 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 %>
|
||||
8
app/views/quantities/edit.js.erb
Normal file
8
app/views/quantities/edit.js.erb
Normal 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>'
|
||||
);
|
||||
@@ -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>
|
||||
|
||||
2
app/views/quantities/new.js.erb
Normal file
2
app/views/quantities/new.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= render partial: 'body_trackers/flash' %>
|
||||
$('#new-quantity').html('<%= j render partial: 'quantities/new_form' %>');
|
||||
Reference in New Issue
Block a user