Fix structure position
This commit is contained in:
		
							parent
							
								
									fe1869199e
								
							
						
					
					
						commit
						5328a26440
					
				|  | @ -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){ | ||||
|  |  | |||
|  | @ -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 | ||||
|    | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -46,17 +46,19 @@ 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) | ||||
|       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 | ||||
|   end | ||||
| 
 | ||||
|   def show_in_sitemap_for(locale) | ||||
|     if !sitemap_enabled.blank? && !sitemap_enabled[locale].blank? | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue