diff --git a/app/assets/javascripts/lib/items/items.js.erb b/app/assets/javascripts/lib/items/items.js.erb index 873ebc20..b0af6813 100644 --- a/app/assets/javascripts/lib/items/items.js.erb +++ b/app/assets/javascripts/lib/items/items.js.erb @@ -44,7 +44,13 @@ $(function(){ startCollapsed: true, disableNesting: 'no-nest', update: function(event, ui) { - $.post("<%= Rails.application.routes.url_helpers.admin_update_position_path %>", { id: ui.item.attr('id'), parent_id: (ui.item.parent().closest('li').attr('id') || ui.item.parent().closest('ol').attr('id')), position: ui.item.index() } ); + var position = null; + if($(ui.item).closest('ol').hasClass('item-groups')) { + position = $(ui.item).index() - 1; + } else { + position = $(ui.item).index(); + }; + $.post("<%= Rails.application.routes.url_helpers.admin_update_position_path %>", { id: ui.item.attr('id'), parent_id: (ui.item.parent().closest('li').attr('id') || ui.item.parent().closest('ol').attr('id')), position: position } ); } }); $(".sortable").delegate(".brand, .delete", clickEvent, function(e){ diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index 7ac1cb1e..e364acb1 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -27,7 +27,7 @@ class Admin::ItemsController < OrbitBackendController def update_position item = Item.find(params[:id]) - item.shift_to(params[:parent_id], params[:position].to_i - 1) + item.shift_to(params[:parent_id], params[:position].to_i) render :nothing => true, status: 200 end diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 9ddb0755..8190f5df 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -274,8 +274,6 @@ class Admin::UsersNewInterfaceController < OrbitMemberController else user.move_below(user_at_position) end - elsif to_go > User.count - user.move_to_bottom end end render nothing: true, status: 200 diff --git a/app/models/item.rb b/app/models/item.rb index f06109a5..65e30bbc 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -46,15 +46,17 @@ class Item def shift_to(new_parent, position) position = position.to_i - unless self.parent_id.to_s.eql?(new_parent) && self.position == position - new_parent = Item.find(new_parent) - current_position_sibling = find_by_parent_and_position(new_parent, position) - if current_position_sibling - move_above(current_position_sibling) - elsif self.parent != new_parent - self.parent = new_parent - save + new_parent = Item.find(new_parent) + current_position_sibling = find_by_parent_and_position(new_parent, position) + if current_position_sibling + if self.position > current_position_sibling.position + self.move_above(current_position_sibling) + else + self.move_below(current_position_sibling) end + elsif self.parent != new_parent + self.parent = new_parent + save end end