class Panel::PersonalSeminar::BackEnd::WritingSeminarCategorysController < OrbitBackendController

  include OrbitControllerLib::DivisionForDisable
	
  before_filter :force_order_for_visitor,:only=>[:index,:show]
  before_filter :force_order_for_user,:except => [:index,:show]
  before_filter :for_app_manager,:except => [:index]

  def index
  
	get_types
	
    @writing_seminar_categorys =  @types.all
    @writing_seminar_category = @types.new(:display => 'List')
	
	# @url = panel_personal_seminar_back_end_writing_seminar_categorys_path
	@url = eval("panel_personal_seminar_back_end_#{@app_type}s_path")
	
    respond_to do |format|
      format.html # index.html.erb
      format.js
    end
  end

  # GET /writing_seminars/1
  # GET /writing_seminars/1.xml
  def show
  
	get_types
	
    @writing_seminar_category = @types.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.js
    end
  end

  # GET /writing_seminars/new
  # GET /writing_seminars/new.xml
  def new
  
	get_types
	
    @writing_seminar_category = @types.new(:display => 'List')
	
	@verb = :post

    respond_to do |format|
      format.html # new.html.erb
      format.js
    end
  end
  
  # GET /writing_seminars/1/edit
  def edit
  
	get_types
	
    @writing_seminar_category = @types.find(params[:id])
	
	# @url = panel_personal_seminar_back_end_writing_seminar_category_path(@writing_seminar_category)
	# @url = eval("panel_personal_seminar_back_end_#{@app_type}_path(@writing_seminar_category)")
	@url = polymorphic_path([:panel, :personal_seminar, :back_end, @writing_seminar_category])
	
	@verb = :put

    respond_to do |format|
      format.html
      format.js
    end
  end

  # POST /writing_seminars
  # POST /writing_seminars.xml
  def create
  
	get_types
	
    @writing_seminar_category = @types.new(params[:writing_seminar_category])

    respond_to do |format|
      if @writing_seminar_category.save
        format.html { redirect_to(panel_personal_seminar_back_end_writing_seminar_categorys_url, :notice => t('writing_seminar_category.create_writing_seminar_category_success')) }
        format.js
      else
        format.html { render :action => "new" }
        format.js { render action: "new" }
      end
    end
  end

  # PUT /writing_seminars/1
  # PUT /writing_seminars/1.xml
  def update
  
	get_types
	
    @writing_seminar_category = @types.find(params[:id])
	# debugger
	# @url = panel_personal_seminar_back_end_writing_seminar_category_path(@writing_seminar_category)
	# @url = eval("panel_personal_seminar_back_end_#{@app_type}_path(#{@writing_seminar_category})")
	@url = polymorphic_path([:panel, :personal_seminar, :back_end, @writing_seminar_category])

    respond_to do |format|
      if @writing_seminar_category.update_attributes(params[:writing_seminar_category])
        format.html { redirect_to(panel_personal_seminar_back_end_writing_seminar_categorys_url, :notice => t('writing_seminar_category.update_writing_seminar_category_success')) }
        # format.xml  { head :ok }
        format.js
      else
        format.html { render :action => "edit" }
        format.js { render :action => "edit" }
      end
    end
  end

  # DELETE /writing_seminars/1
  # DELETE /writing_seminars/1.xml
  def destroy
  
	get_types
	
    @writing_seminar_category = @types.find(params[:id])
    @writing_seminar_category.disable = @writing_seminar_category.disable ? false : true

    if @writing_seminar_category.save!
      respond_to do |format|
        format.html { redirect_to(panel_personal_seminar_back_end_writing_seminar_categorys_url) }
        # format.xml  { head :ok }
        format.js
      end      
    else
      flash[:error] = t("writing_seminar_category.update_failed")
      format.html { render :action => "index" }
    end

  end
  
  protected
  
  def get_types
    @types = @app_type.classify.constantize
  end
  
end
