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
|
||||
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)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js {
|
||||
render inline: "location.replace('#{dmsf_workflow_path(@dmsf_workflow)}');"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class DmsfWorkflow < ActiveRecord::Base
|
||||
|
||||
has_many :dmsf_workflow_steps, -> { order 'step ASC, operator DESC' }, :dependent => :destroy
|
||||
belongs_to :author, :class_name => 'User'
|
||||
|
||||
@ -89,51 +88,19 @@ class DmsfWorkflow < ActiveRecord::Base
|
||||
|
||||
def reorder_steps(step, move_to)
|
||||
DmsfWorkflow.transaction do
|
||||
case move_to
|
||||
when 'highest'
|
||||
unless step == 1
|
||||
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', 1)
|
||||
end
|
||||
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
|
||||
dmsf_workflow_steps.each do |ws|
|
||||
if ws.step == step
|
||||
return false unless ws.update_attribute('step', move_to)
|
||||
elsif ws.step >= move_to && ws.step < step
|
||||
# Move up
|
||||
return false unless ws.update_attribute('step', ws.step + 1)
|
||||
elsif ws.step <= move_to && ws.step > step
|
||||
# Move down
|
||||
return false unless ws.update_attribute('step', ws.step - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return reload
|
||||
return true
|
||||
end
|
||||
|
||||
def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id)
|
||||
|
||||
@ -42,11 +42,11 @@
|
||||
</p>
|
||||
<% steps = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq %>
|
||||
<% if steps.any? %>
|
||||
<table class="list">
|
||||
<table class="list steps">
|
||||
<thead><tr>
|
||||
<th><%= l(:label_dmsf_workflow_step) %></th>
|
||||
<th><%= l(:label_dmsf_workflow_approval_plural) %></th>
|
||||
<th><%= l(:button_sort) %></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
@ -62,10 +62,8 @@
|
||||
<%= link_to_user step.user %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="reorder">
|
||||
<%= reorder_links('workflow_step', {:action => 'edit', :id => @dmsf_workflow, :step => i}, :put) %>
|
||||
</td>
|
||||
<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) %>
|
||||
</td>
|
||||
</tr>
|
||||
@ -75,4 +73,8 @@
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
$(function() { $("table.steps tbody").positionedItems(); });
|
||||
<% end %>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user