Running Quantity#toggle/up/down/left/right through AJAX
This commit is contained in:
parent
26f653819d
commit
daf0bd421e
@ -28,27 +28,31 @@ class QuantitiesController < ApplicationController
|
||||
|
||||
def toggle
|
||||
@quantity.update(primary: !@quantity.primary)
|
||||
redirect_to project_quantities_url(@project)
|
||||
@quantities = @project.quantities
|
||||
end
|
||||
|
||||
def up
|
||||
@quantity.move_left if @quantity.left_sibling.present?
|
||||
redirect_to project_quantities_url(@project)
|
||||
@quantities = @project.quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def down
|
||||
@quantity.move_right if @quantity.right_sibling.present?
|
||||
redirect_to project_quantities_url(@project)
|
||||
@quantities = @project.quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def left
|
||||
@quantity.move_to_right_of(@quantity.parent) if @quantity.parent.present?
|
||||
redirect_to project_quantities_url(@project)
|
||||
@quantities = @project.quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def right
|
||||
@quantity.move_to_child_of(@quantity.left_sibling) if @quantity.left_sibling.present?
|
||||
redirect_to project_quantities_url(@project)
|
||||
@quantities = @project.quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
private
|
||||
|
86
app/views/quantities/_list.html.erb
Normal file
86
app/views/quantities/_list.html.erb
Normal file
@ -0,0 +1,86 @@
|
||||
<% if @quantities.many? %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_order) %></th>
|
||||
<th><%= l(:field_domain) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
||||
<%
|
||||
next if q.new_record?
|
||||
quantity_class = "quantity"
|
||||
quantity_class += " project idnt idnt-#{level+1}"
|
||||
quantity_class += " primary" if q.primary
|
||||
quantity_class += " anchor" if @anchor == q.id
|
||||
%>
|
||||
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
||||
<td class="name">
|
||||
<%= link_to '', toggle_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
|
||||
}
|
||||
%>
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<td class="order">
|
||||
<%=
|
||||
if q.left_sibling.present?
|
||||
link_to '', up_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-up"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.right_sibling.present?
|
||||
link_to '', down_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-down"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.parent.present?
|
||||
link_to '', left_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-left"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.left_sibling.present?
|
||||
link_to '', right_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-right"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
</td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="action"><%= delete_link quantity_path(q), data: {} %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
@ -23,71 +23,6 @@
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @quantities.many? %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_order) %></th>
|
||||
<th><%= l(:field_domain) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
||||
<%
|
||||
next if q.new_record?
|
||||
quantity_class = "quantity"
|
||||
quantity_class += " project idnt idnt-#{level+1}"
|
||||
quantity_class += " primary" if q.primary
|
||||
%>
|
||||
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
||||
<td class="name">
|
||||
<%= link_to '', toggle_quantity_path(q),
|
||||
{method: :post, class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"} %>
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<td class="order">
|
||||
<%=
|
||||
if q.left_sibling.present?
|
||||
link_to '', up_quantity_path(q), {method: :post, class: "icon icon-move-up"}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.right_sibling.present?
|
||||
link_to '', down_quantity_path(q),
|
||||
{method: :post, class: "icon icon-move-down"}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.parent.present?
|
||||
link_to '', left_quantity_path(q),
|
||||
{method: :post, class: "icon icon-move-left"}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<%=
|
||||
if q.left_sibling.present?
|
||||
link_to '', right_quantity_path(q),
|
||||
{method: :post, class: "icon icon-move-right"}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
</td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="action"><%= delete_link quantity_path(q), data: {} %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
<div id='quantities'>
|
||||
<%= render :partial => 'quantities/list' %>
|
||||
</div>
|
||||
|
1
app/views/quantities/toggle.js.erb
Normal file
1
app/views/quantities/toggle.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/list') %>');
|
Reference in New Issue
Block a user