Refactor Procedure#switch_list_order
This commit is contained in:
parent
d54fe12a9c
commit
9268da8236
1 changed files with 11 additions and 6 deletions
|
@ -82,13 +82,18 @@ class Procedure < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def switch_list_order(list, index_of_first_element)
|
def switch_list_order(list, index_of_first_element)
|
||||||
return false if index_of_first_element < 0
|
if index_of_first_element < 0 ||
|
||||||
return false if index_of_first_element == list.count - 1
|
index_of_first_element == list.count - 1 ||
|
||||||
return false if list.count < 1
|
list.count < 1
|
||||||
|
|
||||||
|
false
|
||||||
|
else
|
||||||
list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1)
|
list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1)
|
||||||
list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element)
|
list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element)
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def locked?
|
def locked?
|
||||||
published?
|
published?
|
||||||
|
|
Loading…
Reference in a new issue