Refactor Procedure#switch_list_order

This commit is contained in:
gregoirenovel 2017-05-26 21:43:44 +02:00
parent d54fe12a9c
commit 9268da8236

View file

@ -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?