# -*- coding: utf-8 -*-
class RegularWorkShiftsController < ApplicationController
 
 before_filter :isAuthorization
  around_filter :isAccessRead
  
  before_filter :set_var
  
  def index
    @shifts = RegularWorkShift.for_department(@department)
    @empls_not_working = (eval "Division."+@department).employees.working.masters.map{|i| [i.login, i.id]}.uniq.sort - @shifts.map{|i| [i.nic, i.employee_id]}
  end
  
  def edit
    @employee = Employee.find params[:id]
    @shifts = @employee.regular_shifts
  end

  def update
    @employee = Employee.find(params[:id])
    if @employee.update_attributes(params[:employee])
      redirect_to :action => :index
    end
  end

  private
  
  def set_var
    Employee.current_user = Employee.find(session[:user_id]) unless session[:user_id].nil?
    @department = params[:department]
    @department = cookies[:sys_dep] if @department.nil?
    if ['soft', 'mod', 'corp', 'mod2', 'corp2'].include? @department 
      self.class.layout @department
      @department = @department.gsub('2', '') ## Для обработки новых разделов сделки
    else
      @errors = "В доступе отказано!"
      render(:partial => "/shared/errors")
    end
    cookies[:sys_dep] = { :value => $department }
    @current_user = Employee.find(session[:user_id]) unless session[:user_id].nil?
    @boss = (@current_user.accesses.for_department(@department).size > 0 && @current_user.position == 'диспетчер')
  end

end
