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

class Admin::PopupsController < ApplicationController

	before_action :auth_admin
	
	layout "admin"
	

	def index 
    @popups = Popup.order("created_at DESC").all
    
    
	end


	def new
	
		@popup = Popup.new()
    
  

	end


	def edit
	

    
  
		@popup = Popup.find(params[:id])
    
		
	end


	def show
	

    
    @lang = LangSite.find_by_slug(params[:lang])
    
  
		@popup = Popup.find(params[:id])
    
    
    
		
	end


	def create
		
		@popup = Popup.new(params.require(:popup).permit!)

		
		if @popup.save
			flash[:notice] = "La popup à été ajouté avec succès."
      redirect_to :action => :index
		
		else
			render :action => "new" 

		end

	end


	def update
	
		@popup = Popup.find(params[:id])
	
  
    
  		if @popup.update_attributes(params.require(:popup).permit!)
  			flash[:notice] = "La popup à été modifié avec succès."
        redirect_to :action => :index
  		else
  			render :action => "edit"
  		end
      
   
  
  
		
	end


	def destroy
	
		@popup = Popup.find(params[:id])
		@popup.destroy
    redirect_to :action => :index
	end
	
	
end