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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "tournees"
  end
  
  def index
    @file_tunel_sends = FileTunelSend.all
    
    @file_tunel_sends = sort_by_sorting(@file_tunel_sends, "created_at DESC")
    
    
    params[:search][:per_page] = params[:search][:per_page] || 50
		per_page = params[:search][:per_page]
		page = (params[:page] and params[:page] != "") ? params[:page] : 1 
		@file_tunel_sends = @file_tunel_sends.page(page).per(per_page)
    

  end

  def send_mail
    @file_tunel_send = FileTunelSend.find(params[:id])
    @file_tunel_send.send_mail_type("envoi_lien")
    redirect_to [:admin,@file_tunel_send.file_tunel ]
  end

  def show
    @file_tunel_send = FileTunelSend.find(params[:id])

  end

  def new
    @file_tunel_send = FileTunelSend.new
  
  end

  def edit
    @file_tunel_send = FileTunelSend.find(params[:id])
    
  end

  def create
    @file_tunel_send = FileTunelSend.new(params.require(:file_tunel_send).permit!)

    if @file_tunel_send.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @file_tunel_send = FileTunelSend.find(params[:id])


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


  def destroy
    @file_tunel_send = FileTunelSend.find(params[:id])
    @file_tunel_send.destroy
    
  end
end
