class Panel::Video::BackEnd::ChannelVideosController < OrbitBackendController
#  before_filter :force_order_for_visitor,:only => [:index, :new, :edit, :delete]
#  before_filter :force_order_for_user,:except => [:index]
 open_for_admin
 open_for_manager
 open_for_sub_manager
  
  def index
    @channel_videos = ChannelVideo.all         
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @videos }
    end
  end

  def show
    @channel_video = ChannelVideo.find(params[:id])
    client = YouTubeIt::Client.new(:dev_key => "AI39si5KGPg8rhKLBfmeukit2tCSP_B9lT8igiNICbrbgUXQoAdYGvsyCGCmO1wGnr1OW4bDRv-ESolwk-rdBNIAgVTL9VYaEA")
    @client_videos = client.videos_by(:user => @channel_video.channel_name, :per_page => 5)           

    respond_to do |format|
      format.html
      format.json { render json: @location }
    end
  end

  def new
  	@channel_video = ChannelVideo.new
  end

  def edit
    @channel_video = ChannelVideo.find(params[:id])
  end

  def create
    @channel_video = ChannelVideo.new(params[:channel_video])

    if @channel_video.save
      redirect_to panel_video_back_end_channel_videos_url
    else
      render 'new'
    end
  end

  def update
    @channel_video = ChannelVideo.find(params[:id])

      if @channel_video.update_attributes(params[:channel_video])
        redirect_to panel_video_back_end_channel_videos_url
      else
        render 'edit'
      end
  end

  def destroy
    @channel_video = ChannelVideo.find(params[:id])
    @channel_video.destroy
    redirect_to panel_video_back_end_channel_videos_url

  end
end
