Toggling quantity primariness from nutrients view
This commit is contained in:
78
app/views/ingredients/_list_nutrients.html.erb
Normal file
78
app/views/ingredients/_list_nutrients.html.erb
Normal file
@@ -0,0 +1,78 @@
|
||||
<% if @primary_nutrients.any? %>
|
||||
<%= render :partial => 'ingredients/options' %>
|
||||
|
||||
<table class="nutrients list odd-even">
|
||||
<thead>
|
||||
<tr>
|
||||
<% total_width = 3 + @primary_quantities.length %>
|
||||
<th style="width:<%= 3 * 100/total_width%>%"><%= l(:field_name) %></th>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<th style="width:<%= 100/total_width %>%"><%= q.name %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @primary_nutrients.each do |i, values| %>
|
||||
<% row_class = "ingredient#{' hidden' if i.hidden} #{cycle('odd', 'even')}" %>
|
||||
<tr id="ingredient-<%= i.id %>" class="primary <%= row_class %>">
|
||||
<td class="name" style="cursor: pointer;" onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', 'tr').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed"><%= i.name %></span>
|
||||
</td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary value">
|
||||
<%= values[q.id] || '-' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<td class="name" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed"><%= i.name %></span>
|
||||
</td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary quantity">
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary value">
|
||||
<%= values[q.id] || '-' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<% extras = @extra_nutrients[i].keys %>
|
||||
<% extras.each_slice(@primary_quantities.length).with_index do |names, index| %>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% names.each do |name| %>
|
||||
<td class="extra quantity">
|
||||
<%= name %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @primary_quantities.length > names.length %>
|
||||
<td class="space" colspan="<%= @primary_quantities.length-names.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% names.each do |name| %>
|
||||
<td class="extra value">
|
||||
<%= @extra_nutrients[i][name] %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @primary_quantities.length > names.length %>
|
||||
<td class="space" colspan="<%= @primary_quantities.length-names.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
31
app/views/ingredients/_options.html.erb
Normal file
31
app/views/ingredients/_options.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<fieldset id="options" class="collapsible">
|
||||
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
||||
<%= form_tag toggle_nutrient_column_project_ingredients_path(@project),
|
||||
id: 'add_nutrient_column', method: :post, remote: true do %>
|
||||
<table>
|
||||
<tr>
|
||||
<td width="100%"></td>
|
||||
<td>
|
||||
<%= select_tag 'id', nutrient_column_options %>
|
||||
</td>
|
||||
<td>
|
||||
<%= submit_tag l(:button_add) %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
|
||||
<table class="list" style="border: none; width: 100%">
|
||||
<tr>
|
||||
<% total_width = 3 + @primary_quantities.length %>
|
||||
<td style="visibility: hidden; border: none; width:<%= 3 * 100/total_width%>%"></td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="action" style="width:<%= 100/total_width %>%">
|
||||
<%= link_to l(:button_hide),
|
||||
toggle_nutrient_column_project_ingredients_path(@project, id: q.id),
|
||||
{class: "icon icon-close", method: :post, remote: true} %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -13,79 +13,6 @@
|
||||
<%= render :partial => 'ingredients/form' %>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @primary_nutrients.any? %>
|
||||
<table class="nutrients list odd-even">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:30%"><%= l(:field_name) %></th>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<th style="width:8%"><%= q.name %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @primary_nutrients.each do |i, values| %>
|
||||
|
||||
<% row_class = "ingredient#{' hidden' if i.hidden} #{cycle('odd', 'even')}" %>
|
||||
<tr id="ingredient-<%= i.id %>" class="primary <%= row_class %>">
|
||||
<td class="name" style="cursor: pointer;" onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', 'tr').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed"><%= i.name %></span>
|
||||
</td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary value">
|
||||
<%= values[q.id] || '-' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<td class="name" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed"><%= i.name %></span>
|
||||
</td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary quantity">
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% @primary_quantities.each do |q| %>
|
||||
<td class="primary value">
|
||||
<%= values[q.id] || '-' %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<% extras = @extra_nutrients[i].keys %>
|
||||
<% extras.each_slice(@primary_quantities.length).with_index do |names, index| %>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% names.each do |name| %>
|
||||
<td class="extra quantity">
|
||||
<%= name %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @primary_quantities.length > names.length %>
|
||||
<td class="space" colspan="<%= @primary_quantities.length-names.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<td class="space"></td>
|
||||
<% names.each do |name| %>
|
||||
<td class="extra value">
|
||||
<%= @extra_nutrients[i][name] %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @primary_quantities.length > names.length %>
|
||||
<td class="space" colspan="<%= @primary_quantities.length-names.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
<div id='nutrients'>
|
||||
<%= render :partial => 'ingredients/list_nutrients' %>
|
||||
</div>
|
||||
|
||||
3
app/views/ingredients/toggle_nutrient_column.js.erb
Normal file
3
app/views/ingredients/toggle_nutrient_column.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
$('div[id^=flash_]').remove();
|
||||
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
|
||||
$('#nutrients').html('<%= escape_javascript(render :partial => 'ingredients/list_nutrients') %>');
|
||||
Reference in New Issue
Block a user