class CssController < ApplicationController
  before_action :code_lost, :except=> ['code', 'libversions', 'libfiles']

  def code_lost
    @is_new = false
    @item = Code.find_by_id(params[:id])
    if !@item || @item.typcd != 'css'
      @item = Code.new({:typcd=> 'css'})
      @item.mem = current_mem
      @item.title = "新建代码"
      @is_author = !current_mem.nil?
      @is_new = true
    else
      @is_author = (current_mem and @item.mem_id == current_mem.id)
    end
    
  end

  def categorys
    render json: Menutyp.where({:group=> 'CSS'}) 
  end

  def save
    render json: {status: false} and return if @item.mem_id != current_mem.id
    @item.update_attributes({
      :css=> params[:css],
      :html=> params[:html],
      :title=> params[:title]
    })

    render json: {status: true, id: @item.id}
  end

  def code
    render json: Code.find_by_id(params[:id])
  end

  def updategroup
    _item = Code.find_by_id(params[:id])
    render json: false and return if _item.mem_id != current_mem.id 
    _item.group = params[:group]
    _item.save
    render json: true
  end

end
