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


 
class SheetYearsController < ApplicationController
  
  before_filter :authenticate_admin!, except: [:show]
  # GET /sheet_years
  # GET /sheet_years.xml
  def index
    @sheet_years = SheetYear.all

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

  # GET /sheet_years/1
  # GET /sheet_years/1.xml
  def show
    @sheet_year = SheetYear.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @sheet_year }
      format.js { render(:update){|page| page.replace 'sheet_year_'+@sheet_year.id.to_s, :partial => "sheet_year", :object => @sheet_year} }
    end
  end

  # GET /sheet_years/new
  # GET /sheet_years/new.xml
  def new
    @sheet_year = SheetYear.new
    @sheet_year.sheet_id = params[:sheet_id]
    @sheet_year.payment_type = 1
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @sheet_year }
    end
  end

  # GET /sheet_years/1/edit
  def edit
    @sheet_year = SheetYear.find(params[:id])
    respond_to do |format|
      format.js { render(:update){|page| page.replace_html 'sheet_year_'+@sheet_year.id.to_s, :partial => "form", :object => @sheet_year} }
    end
  end

  # POST /sheet_years
  # POST /sheet_years.xml
  def create
    @sheet_year = SheetYear.new(params[:sheet_year])
    
    
    respond_to do |format|
      if @sheet_year.save
        @sheet = @sheet_year.sheet
        format.html { redirect_to(@sheet_year, :notice => 'SheetYear was successfully created.') }
        format.xml  { render :xml => @sheet_year, :status => :created, :location => @sheet_year }
        format.js 
      else
        @sheet = @sheet_year.sheet
        format.html { render :action => "new" }
        format.xml  { render :xml => @sheet_year.errors, :status => :unprocessable_entity }
        format.js { render(:update){|page| page.replace_html 'new_sheet_year', :partial => "form", :object => @sheet_year} }
      end
    end
  end

  # PUT /sheet_years/1
  # PUT /sheet_years/1.xml
  def update
    @sheet_year = SheetYear.find(params[:id])



    respond_to do |format|
      if @sheet_year.update_attributes(params[:sheet_year])
        format.html { redirect_to(@sheet_year, :notice => 'SheetYear was successfully updated.') }
        format.xml  { head :ok }
         format.js { render(:update){|page| page.replace 'sheet_year_'+@sheet_year.id.to_s, :partial => "sheet_year", :object => @sheet_year} }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @sheet_year.errors, :status => :unprocessable_entity }
        format.js { render(:update){|page| page.replace_html 'sheet_year_'+@sheet_year.id.to_s, :partial => "form", :object => @sheet_year} }
      end
    end
  end

  # DELETE /sheet_years/1
  # DELETE /sheet_years/1.xml
  def destroy
    @sheet_year = SheetYear.find(params[:id])
    @sheet_year.destroy

    respond_to do |format|
      format.html { redirect_to(sheet_years_url) }
      format.xml  { head :ok }
      format.js { render(:update){|page| page.remove 'sheet_year_'+@sheet_year.id.to_s} }
    end
  end
end
