1
0

Added Meal edit/update

This commit is contained in:
cryptogopher
2020-04-20 22:56:05 +02:00
parent 6b5cb85b11
commit dfeb9af6db
8 changed files with 37 additions and 3 deletions

View File

@@ -0,0 +1,15 @@
<%= labelled_form_for @meal,
url: meal_path(@meal),
method: :patch, remote: true,
html: {id: 'edit-meal-form', name: 'edit-meal-form'} do |f| %>
<%= render partial: 'meals/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

@@ -3,7 +3,7 @@
remote: true,
html: {id: 'edit-meal-notes-form', name: 'edit-meal-notes-form'} do |f| %>
<%= f.text_field :notes, size: 50, required: false, label: '' %>
<%= f.text_field :notes, size: 40, required: false, label: '' %>
<%= link_to l(:button_save), '', class: 'icon icon-save',
onclick: "$(event.target).closest('form').submit(); return false;" %>
<%= link_to l(:button_cancel), '', class: 'icon icon-cancel',

View File

@@ -8,6 +8,7 @@
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
</td>
</tr>
<% eaten, not_eaten = meals.partition { |m| m.eaten_at }
eaten.sort_by! { |m| m.eaten_at }
not_eaten.sort_by! { |m| m.created_at }

View File

@@ -0,0 +1,7 @@
$('tr[id=meal-<%= @meal.id %>]').nextUntil('tr.primary, tr.date', ':not(.ingredient)').remove();
var columns = $('table > tbody > tr.ingredient > td').length;
$('tr[id=meal-<%= @meal.id %>]').nextUntil('tr.primary, tr.date').addBack().last().after(
'<tr><td class="form" colspan="'+columns+'"><div id="edit-meal">' +
'<%= j render partial: 'meals/edit_form' %>' +
'</div></td></tr>'
);

View File

@@ -0,0 +1 @@
$('#meals').html('<%= j render partial: 'meals/index' %>');