%h1=@home_slider.name

=link_to "Ajouter un slide", new_admin_home_slider_slide_path(:home_slider_id => @home_slider.id), :remote => true

.home_slider_slides
  =render @home_slider.home_slider_slides.order(:position)
  
:coffeescript

  adjustment = ""
  
  $('.home_slider_slides').sortable({
    itemSelector:".home_slider_slide",
    containerSelector :".home_slider_slides",
    nested:true,
    placeholder:"<div class='placeholder' style='height:10px;'></div>",
    onDragStart: ($item, container, _super) ->
      $("body").addClass("dragging")
    
      offset = $item.offset()
      pointer = container.rootGroup.pointer
      adjustment = {
        left: pointer.left - offset.left,
        top: pointer.top - offset.top
        }
    onDrag: ($item, position, _super) ->
      
      $item.css({
        
        left: position.left - adjustment.left,
        top: position.top - adjustment.top - $(window).scrollTop()
        
      })
      
    onDrop: ($item, container, _super) ->
    
      $item.removeClass("dragged").removeAttr("style")
      $("body").removeClass("dragging")
    
      result = []
      container.el.find(".home_slider_slide").each ->
        result.push $(this).data("id")
      
    
  

      $.ajax({
        url:"/admin/home_slider_slides/reorder.js", 
        type: "GET",
        data: { 
          order : result
          } 
  
      })
  });
%hr
%h2 Simulation
#home_slider_simulation

  -@date = Time.now
  
  -@home_slides_simu = @home_slider.home_slider_slides.where(:enabled => true)
  -@home_slides_simu = @home_slides_simu.where("start_at IS NULL or start_at <= ?",@date)
  -@home_slides_simu = @home_slides_simu.where("end_at IS NULL or end_at >= ?",@date)
  -@home_slides_simu = @home_slides_simu.order(:position)
  -@home_slides_simu.each do |home_slider_slide|
    -if home_slider_slide.image_file
      =image_tag home_slider_slide.image_file.file.url, :style => "height:200px;"