Fix structure position
This commit is contained in:
parent
fe1869199e
commit
5328a26440
|
@ -44,7 +44,13 @@ $(function(){
|
||||||
startCollapsed: true,
|
startCollapsed: true,
|
||||||
disableNesting: 'no-nest',
|
disableNesting: 'no-nest',
|
||||||
update: function(event, ui) {
|
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){
|
$(".sortable").delegate(".brand, .delete", clickEvent, function(e){
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Admin::ItemsController < OrbitBackendController
|
||||||
|
|
||||||
def update_position
|
def update_position
|
||||||
item = Item.find(params[:id])
|
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
|
render :nothing => true, status: 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -274,8 +274,6 @@ class Admin::UsersNewInterfaceController < OrbitMemberController
|
||||||
else
|
else
|
||||||
user.move_below(user_at_position)
|
user.move_below(user_at_position)
|
||||||
end
|
end
|
||||||
elsif to_go > User.count
|
|
||||||
user.move_to_bottom
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
render nothing: true, status: 200
|
render nothing: true, status: 200
|
||||||
|
|
|
@ -46,15 +46,17 @@ class Item
|
||||||
|
|
||||||
def shift_to(new_parent, position)
|
def shift_to(new_parent, position)
|
||||||
position = position.to_i
|
position = position.to_i
|
||||||
unless self.parent_id.to_s.eql?(new_parent) && self.position == position
|
new_parent = Item.find(new_parent)
|
||||||
new_parent = Item.find(new_parent)
|
current_position_sibling = find_by_parent_and_position(new_parent, position)
|
||||||
current_position_sibling = find_by_parent_and_position(new_parent, position)
|
if current_position_sibling
|
||||||
if current_position_sibling
|
if self.position > current_position_sibling.position
|
||||||
move_above(current_position_sibling)
|
self.move_above(current_position_sibling)
|
||||||
elsif self.parent != new_parent
|
else
|
||||||
self.parent = new_parent
|
self.move_below(current_position_sibling)
|
||||||
save
|
|
||||||
end
|
end
|
||||||
|
elsif self.parent != new_parent
|
||||||
|
self.parent = new_parent
|
||||||
|
save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Reference in New Issue