# -*- encoding : utf-8 -*-

class Admin::HomeSliderSlidesController < ApplicationController
  layout "admin"
  before_action :auth_admin

  def reorder
    i = 0
    params[:order].each do |gallery_image_id|
      i += 1
      gallery_image = HomeSliderSlide.find(gallery_image_id)
      gallery_image.position = i
      gallery_image.save
    end
    render :inline => "true"
  end

  def index
    per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 50
    page = (params[:page] and params[:page] != "") ? params[:page] : 1 
        
        
    
    
    @home_slider_slides = HomeSliderSlide.page(page).per(per_page)

   
  end

  def show
    @home_slider_slide = HomeSliderSlide.find(params[:id])

  end

  def new
    
    
		@home_slider_slide = HomeSliderSlide.new(:home_slider_id => params[:home_slider_id])
    

  end

 

  def edit
  
    
    @home_slider_slide = HomeSliderSlide.find(params[:id])
  end

  def create
    @home_slider_slide = HomeSliderSlide.new(params.require(:home_slider_slide).permit!)


    if @home_slider_slide.save
      @home_slider_slides = @home_slider_slide.home_slider.home_slider_slides.order(:position)
      
    else
      render action: "new"
 
    end

  end


  def update
    @home_slider_slide = HomeSliderSlide.find(params[:id])


    if @home_slider_slide.update_attributes(params.require(:home_slider_slide).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @home_slider_slide = HomeSliderSlide.find(params[:id])
    @home_slider_slide.destroy
    
    #redirect_to admin_home_slider_slides_url

  end
end
