# -*- encoding : utf-8 -*-
	class Admin::VideoFilesController < ApplicationController
		before_filter :auth_admin

	
	layout "admin"

	def index
		params[:video_folder_id] = params[:video_folder_id] || 1

		@video_folder = VideoFolder.find(params[:video_folder_id])
		@video_folders = VideoFolder.order(:name).all
		@video_files = VideoFile.where(:video_folder_id => @video_folder.id).order("created_at DESC").all
		@video_file = VideoFile.new(:video_folder_id => @video_folder.id)
		if request.xhr?
		render :layout => false
		end
	end

	def new
    
    @video_file = VideoFile.new(:video_folder_id => params[:video_folder_id])
    
    LangSite.all.each do |ls|
      @video_file.video_file_langs << VideoFileLang.new(:lang_site_id => ls.id)
    end
    
    
	end

	def edit
    @video_file = VideoFile.find(params[:id])
	end
  
	def create
		@video_file_create = true
		@video_file = VideoFile.new(params.require(:video_file).permit!)
		
		if @video_file.save

		else
      render :action => :new
		end


	end

	def update
		@video_file = VideoFile.find(params[:id])
		if @video_file.video_folder_id != params[:video_file][:video_folder_id].to_i
      @folder_changed = true
    end
    
		if @video_file.update_attributes(params.require(:video_file).permit!)
  		
		else
	    render :action => :edit
		end
	end

	def destroy
		@video_file = VideoFile.find(params[:id])
		@video_file.destroy

		flash[:notice] = "Le fichier à bien été supprimée."
	end

	def show
		@video_file = VideoFile.find(params[:id])

	end

end
