Drag&Drop in approval workflow steps ordering
This commit is contained in:
parent
94c93e8569
commit
7fc3e49a76
@ -338,12 +338,15 @@ class DmsfWorkflowsController < ApplicationController
|
|||||||
|
|
||||||
def reorder_steps
|
def reorder_steps
|
||||||
if request.put?
|
if request.put?
|
||||||
unless @dmsf_workflow.reorder_steps(params[:step].to_i, params[:workflow_step][:move_to])
|
unless @dmsf_workflow.reorder_steps(params[:step].to_i, params[:dmsf_workflow][:position].to_i)
|
||||||
flash[:error] = l(:notice_cannot_renumber_steps)
|
flash[:error] = l(:notice_cannot_renumber_steps)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
format.js {
|
||||||
|
render inline: "location.replace('#{dmsf_workflow_path(@dmsf_workflow)}');"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class DmsfWorkflow < ActiveRecord::Base
|
class DmsfWorkflow < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :dmsf_workflow_steps, -> { order 'step ASC, operator DESC' }, :dependent => :destroy
|
has_many :dmsf_workflow_steps, -> { order 'step ASC, operator DESC' }, :dependent => :destroy
|
||||||
belongs_to :author, :class_name => 'User'
|
belongs_to :author, :class_name => 'User'
|
||||||
|
|
||||||
@ -89,51 +88,19 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
|
|
||||||
def reorder_steps(step, move_to)
|
def reorder_steps(step, move_to)
|
||||||
DmsfWorkflow.transaction do
|
DmsfWorkflow.transaction do
|
||||||
case move_to
|
dmsf_workflow_steps.each do |ws|
|
||||||
when 'highest'
|
if ws.step == step
|
||||||
unless step == 1
|
return false unless ws.update_attribute('step', move_to)
|
||||||
dmsf_workflow_steps.each do |ws|
|
elsif ws.step >= move_to && ws.step < step
|
||||||
if ws.step < step
|
# Move up
|
||||||
return false unless ws.update_attribute('step', ws.step + 1)
|
return false unless ws.update_attribute('step', ws.step + 1)
|
||||||
elsif ws.step == step
|
elsif ws.step <= move_to && ws.step > step
|
||||||
return false unless ws.update_attribute('step', 1)
|
# Move down
|
||||||
end
|
return false unless ws.update_attribute('step', ws.step - 1)
|
||||||
end
|
|
||||||
end
|
|
||||||
when 'higher'
|
|
||||||
unless step == 1
|
|
||||||
dmsf_workflow_steps.each do |ws|
|
|
||||||
if ws.step == step - 1
|
|
||||||
return false unless ws.update_attribute('step', step)
|
|
||||||
elsif ws.step == step
|
|
||||||
return false unless ws.update_attribute('step', step - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when 'lower'
|
|
||||||
unless step == dmsf_workflow_steps.collect{|s| s.step}.uniq.count
|
|
||||||
dmsf_workflow_steps.each do |ws|
|
|
||||||
if ws.step == step + 1
|
|
||||||
return false unless ws.update_attribute('step', step)
|
|
||||||
elsif ws.step == step
|
|
||||||
return false unless ws.update_attribute('step', step + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when 'lowest'
|
|
||||||
size = dmsf_workflow_steps.collect{|s| s.step}.uniq.count
|
|
||||||
unless step == size
|
|
||||||
dmsf_workflow_steps.each do |ws|
|
|
||||||
if ws.step > step
|
|
||||||
return false unless ws.update_attribute('step', ws.step - 1)
|
|
||||||
elsif ws.step == step
|
|
||||||
return false unless ws.update_attribute('step', size)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
return true
|
||||||
return reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
||||||
|
|||||||
@ -42,11 +42,11 @@
|
|||||||
</p>
|
</p>
|
||||||
<% steps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq %>
|
<% steps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq %>
|
||||||
<% if steps.any? %>
|
<% if steps.any? %>
|
||||||
<table class="list">
|
<table class="list steps">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
<th><%= l(:label_dmsf_workflow_step) %></th>
|
<th><%= l(:label_dmsf_workflow_step) %></th>
|
||||||
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
|
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
|
||||||
<th><%= l(:button_sort) %></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -62,10 +62,8 @@
|
|||||||
<%= link_to_user step.user %>
|
<%= link_to_user step.user %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="reorder">
|
|
||||||
<%= reorder_links('workflow_step', {:action => 'edit', :id => @dmsf_workflow, :step => i}, :put) %>
|
|
||||||
</td>
|
|
||||||
<td class="buttons">
|
<td class="buttons">
|
||||||
|
<%= reorder_handle(@dmsf_workflow, :url => url_for(:action => 'edit', :id => @dmsf_workflow, :step => i) ) %>
|
||||||
<%= delete_link edit_dmsf_workflow_path(@dmsf_workflow, :step => i) %>
|
<%= delete_link edit_dmsf_workflow_path(@dmsf_workflow, :step => i) %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -75,4 +73,8 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= javascript_tag do %>
|
||||||
|
$(function() { $("table.steps tbody").positionedItems(); });
|
||||||
|
<% end %>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user