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


	def index
		@video_folders = VideoFolder.all(:order => :name)
	end

	def new
		@video_folder = VideoFolder.new()
	end

	def create
		@video_folder = VideoFolder.new(params.require(:video_folder).permit!)
		@video_folder_create = true
		
		if @video_folder.save
			@video_folders = VideoFolder.order(:name).all
		else
			render :action => :new
		
		end
	end

	def edit
		@video_folder = VideoFolder.find(params[:id])	
	end

	def update
		@video_folder = VideoFolder.find(params[:id])
		@video_folder_update = true
		
		if @video_folder.update_attributes(params.require(:video_folder).permit!)
			@video_folders = VideoFolder.order(:name).all
		else
			render :action => :edit
		
		end
	end

	def destroy
		@video_folder = VideoFolder.find(params[:id])
		if @video_folder.id != 1
			@video_folder.delete
      @video_folders = VideoFolder.order(:name).all
		end
	end
  
  def change_video_folder
    @video_folder = VideoFolder.find(params[:id])
    
    @video_files = VideoFile.where(:id => params[:video_files_id])
    
    @video_files.update_all :video_folder_id => @video_folder.id
    render :inline => "ok"
    
  end
  
  
  

end
