class ZamestnancisController < ApplicationController
  # GET /zamestnancis
  # GET /zamestnancis.json
  def index
    if @active_user.ID_Zam == 1
      @zamestnancis = Zamestnanci.all 
    else 
      @zamestnancis = [Zamestnanci.find_by_ID_Zam(@active_user.ID_Zam)]
    end
    
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @zamestnancis }
    end
  end

  # GET /zamestnancis/1
  # GET /zamestnancis/1.json
  def show
    @zamestnanci = Zamestnanci.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @zamestnanci }
    end
  end

  # GET /zamestnancis/new
  # GET /zamestnancis/new.json
  def new
    @zamestnanci = Zamestnanci.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @zamestnanci }
    end
  end

  # GET /zamestnancis/1/edit
  def edit
    @zamestnanci = Zamestnanci.find(params[:id])
  end

  # POST /zamestnancis
  # POST /zamestnancis.json
  def create
    @zamestnanci = Zamestnanci.new(params[:zamestnanci])

    respond_to do |format|
      if @zamestnanci.save
        format.html { redirect_to @zamestnanci, notice: 'Zamestnanci was successfully created.' }
        format.json { render json: @zamestnanci, status: :created, location: @zamestnanci }
      else
        format.html { render action: "new" }
        format.json { render json: @zamestnanci.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /zamestnancis/1
  # PUT /zamestnancis/1.json
  def update
    @zamestnanci = Zamestnanci.find(params[:id])

    respond_to do |format|
      if @zamestnanci.update_attributes(params[:zamestnanci])
        format.html { redirect_to @zamestnanci, notice: 'Zamestnanci was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @zamestnanci.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /zamestnancis/1
  # DELETE /zamestnancis/1.json
  def destroy
    @zamestnanci = Zamestnanci.find(params[:id])
    @zamestnanci.destroy

    respond_to do |format|
      format.html { redirect_to zamestnancis_url }
      format.json { head :no_content }
    end
  end
end
