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

class Admin::NewsgroupsController < ApplicationController
  layout 'admin'
  
  
#  require_permission 'adherent.show'
#  require_permission 'adherent.add', :only => [:new, :create]
#  require_permission 'adherent.edit', :only => [:edit, :update]
#  require_permission 'adherent.delete', :only => [:destroy]

  def index
    @newsgroups = Newsgroup.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @newsgroups }
    end
  end

  def show
    @newsgroup = Newsgroup.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @newsgroup }
    end
  end

  def new
    @newsgroup = Newsgroup.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @newsgroup }
    end
  end

  def edit
    @newsgroup = Newsgroup.find(params[:id])
  end


  def create
    @newsgroup = Newsgroup.new(params[:newsgroup])

    
      if @newsgroup.save
         flash[:notice] = 'Le nouveau groupe à bien été créé.'
       redirect_to :action => :index
      else
        render :action => "new" 
       
      end
 
  end

  def update
    @newsgroup = Newsgroup.find(params[:id])
      if @newsgroup.update_attributes(params[:newsgroup])
        flash[:notice] = 'Le groupe à bien été éditer.'
        redirect_to :action => :index
       
      else
        render :action => "edit" 
        
      end
    
  end


  def destroy
    @newsgroup = Newsgroup.find(params[:id])
    @newsgroup.destroy
    flash[:notice] = 'Le groupe à bien été supprimé.'
    redirect_to :action => :index
  end
end
