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

class Admin::PressReleasesController < ApplicationController

	before_filter :auth_admin
	
	layout "admin"
	

	def index 
    @press_releases = PressRelease.order("published_at DESC").all
    
    @press_releases = @press_releases.page(params[:page]).per(15)
	end


	def cible
		
		render :layout => false
		
	end
	
	
	def new
	
		@press_release = PressRelease.new(:published_at => Time.now)
    
  

	end


	def edit
	
    params[:lang] = params[:lang] || "fr"
    
  
		@press_release = PressRelease.find(params[:id])
    
		
	end


	def show
	
    params[:lang] = params[:lang] || "fr"
    
    @lang = LangSite.find_by_slug(params[:lang])
    
  
		@press_release = PressRelease.find(params[:id])
    
    
    
		
	end


	def create
		
		@press_release = PressRelease.new(params.require(:press_release).permit!)

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

		end

	end


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


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