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

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

  before_action :admin_space
  
  def admin_space
    @admin_space = "ventes"
  end
  
  def add_to_project
    @s_module = SModule.find(params[:id])
    @s_project = SProject.find(params[:s_project_id])
    
    @s_project.s_modules << @s_module
    
    redirect_to [:admin, @s_project]
  end
  
  def index
    @s_modules = SModule.order(:name).all

  end

  def show
    @s_module = SModule.find(params[:id])

  end

  def new
    @s_module = SModule.new
  
  end

  def edit
    @s_module = SModule.find(params[:id])
    
  end

  def create
    @s_module = SModule.new(params.require(:s_module).permit!)

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

  end


  def update
    @s_module = SModule.find(params[:id])


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


  def destroy
    @s_module = SModule.find(params[:id])
    @s_module.destroy
    
  end
end
