1
0

Moved notes form from div to td

This commit is contained in:
cryptogopher 2020-04-19 21:34:24 +02:00
parent 3706206191
commit 03d0a56474
6 changed files with 15 additions and 16 deletions

View File

@ -41,7 +41,7 @@ class MealsController < ApplicationController
def update_notes def update_notes
if @meal.update(params.require(:meal).permit(:notes)) if @meal.update(params.require(:meal).permit(:notes))
flash[:notice] = 'Updated meal notes' flash[:notice] = 'Updated meal notes' unless @meal.previous_changes.empty?
end end
end end

View File

@ -17,8 +17,8 @@ module MealsHelper
end end
def display_notes(m) def display_notes(m)
content_tag :div, link_to(l(:button_notes), edit_notes_meal_path(m), link_to(l(:button_notes), edit_notes_meal_path(m),
{remote: true, class: "icon icon-wiki-page"}) + {remote: true, class: "icon icon-wiki-page"}) +
(m.notes.blank? ? "" : ": #{m.notes}") content_tag(:span, m.notes.blank? ? "" : ": #{m.notes}")
end end
end end

View File

@ -3,11 +3,11 @@
remote: true, remote: true,
html: {id: 'edit-meal-notes-form', name: 'edit-meal-notes-form'} do |f| %> html: {id: 'edit-meal-notes-form', name: 'edit-meal-notes-form'} do |f| %>
<%= f.text_field :notes, size: 50, required: false, label: '' %>
<%= link_to l(:button_save), '', class: 'icon icon-save', <%= link_to l(:button_save), '', class: 'icon icon-save',
onclick: "$(event.target).closest('form').submit(); return false;" %> onclick: "$(event.target).closest('form').submit(); return false;" %>
<%= f.text_field :notes, rows: 1, required: false, label: '' %> <%= link_to l(:button_cancel), '', class: 'icon icon-cancel',
<%= link_to l(:button_cancel), '',
onclick: "$(event.target).closest('form').remove(); onclick: "$(event.target).closest('form').remove();
$('div[id=notes-#{@meal.id}]').contents().show(); $('td[id=notes-#{@meal.id}]').contents().show();
return false;" %> return false;" %>
<% end %> <% end %>

View File

@ -1,19 +1,18 @@
<tr id="meal-<%= m.id %>" class="primary meal project idnt idnt-1"> <tr id="meal-<%= m.id %>" class="primary meal project idnt idnt-1">
<td class="name" colspan="2"> <td class="name unwrappable" style="width: 5%;">
<b><%= "#{t '.label_meal'} ##{index+1}" %></b> <b><%= "#{t '.label_meal'} ##{index+1}" %></b>
<% if m.eaten_at %> <% if m.eaten_at %>
<%= " at #{m.eaten_at.strftime('%R')}" %> <%= " at #{m.eaten_at.strftime('%R')}" %>
<%= link_to '', toggle_eaten_meal_path(m), <%= link_to '', toggle_eaten_meal_path(m),
{remote: true, method: :post, class: "icon icon-close", {remote: true, method: :post, class: "icon icon-close"} %>
style: "margin-left: -0.2em;"} %>
<% else %> <% else %>
<%= link_to l(:button_eat), toggle_eaten_meal_path(m), <%= link_to l(:button_eat), toggle_eaten_meal_path(m),
{remote: true, method: :post, class: "icon icon-ok"} %> {remote: true, method: :post, class: "icon icon-ok"} %>
<% end %> <% end %>
<div id="notes-<%= m.id %>" style="display: inline-flex;">&emsp; <td id="notes-<%= m.id %>" class="notes" style="text-align: left;">
<%= display_notes(m) %> <%= display_notes(m) %>
</div> </td>
<div style="float: right; position: relative;"><%= meal_links(m) %></div> <td class="action" style="width: 5%;"><%= meal_links(m) %></td>
</td> </td>
</tr> </tr>
@ -22,7 +21,7 @@
<td class="name unwrappable" style="width: 5%;"> <td class="name unwrappable" style="width: 5%;">
<%= i.food.name %> <%= i.food.name %>
</td> </td>
<td style="text-align: left;" class="unwrappable"> <td style="text-align: left;" class="unwrappable" colspan="2">
<%= adjust_ingredient_links(i) { raw "&emsp;#{i.amount}&emsp;" } %> <%= adjust_ingredient_links(i) { raw "&emsp;#{i.amount}&emsp;" } %>
</td> </td>
</tr> </tr>

View File

@ -1,4 +1,4 @@
var box = $('div[id=notes-<%= @meal.id %>]'); var box = $('td[id=notes-<%= @meal.id %>]');
box.contents().hide(); box.contents().hide();
box.append('<%= j render partial: 'meals/edit_notes_form' %>'); box.append('<%= j render partial: 'meals/edit_notes_form' %>');
box.find('input[type=text]').focus(); box.find('input[type=text]').focus();

View File

@ -1,2 +1,2 @@
var box = $('div[id=notes-<%= @meal.id %>]'); var box = $('td[id=notes-<%= @meal.id %>]');
box.html('<%= j display_notes(@meal) %>'); box.html('<%= j display_notes(@meal) %>');