Fix structure position

This commit is contained in:
chris 2013-10-08 12:33:24 +08:00
parent fe1869199e
commit 5328a26440
4 changed files with 18 additions and 12 deletions

View File

@ -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){

View File

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

View File

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

View File

@ -46,17 +46,19 @@ 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
move_above(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 elsif self.parent != new_parent
self.parent = new_parent self.parent = new_parent
save save
end end
end end
end
def show_in_sitemap_for(locale) def show_in_sitemap_for(locale)
if !sitemap_enabled.blank? && !sitemap_enabled[locale].blank? if !sitemap_enabled.blank? && !sitemap_enabled[locale].blank?