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

class 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

  # GET /newsgroups/1
  # GET /newsgroups/1.xml
  def show
    @newsgroup = Newsgroup.find(params[:id])

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

  # GET /newsgroups/new
  # GET /newsgroups/new.xml
  def new
    @newsgroup = Newsgroup.new

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

  # GET /newsgroups/1/edit
  def edit
    @newsgroup = Newsgroup.find(params[:id])
  end

  # POST /newsgroups
  # POST /newsgroups.xml
  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

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

  # DELETE /newsgroups/1
  # DELETE /newsgroups/1.xml
  def destroy
    @newsgroup = Newsgroup.find(params[:id])
    @newsgroup.destroy
    flash[:notice] = 'Le groupe à bien été supprimé.'
    respond_to do |format|
      format.html { redirect_to(newsgroups_url) }
      format.xml  { head :ok }
    end
  end
end
