class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendController
  include OrbitControllerLib::DivisionForDisable
  before_filter :force_order_for_visitor,:only=>[:index]
  before_filter :force_order_for_user,:except => [:index]
  before_filter :for_app_sub_manager,:except => [:index]


  def index
    @news_bulletin_categorys = get_categories_for_index("NewsBulletinCategory")
    #TODO 需要做 manager ,admin 才可以 all.  其他 available就好

    @news_bulletin_category = NewsBulletinCategory.new(:display => 'List')
	
	@url = panel_news_back_end_news_bulletin_categorys_path
	
    respond_to do |format|
      format.html # index.html.erb
      # format.xml  { render :xml => @news_bulletins }
      format.js
    end
  end

  # GET /news_bulletins/1
  # GET /news_bulletins/1.xml
  def show
    @news_bulletin_category = NewsBulletinCategory.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      # format.xml  { render :xml => @news_bulletin_category }
      format.js
    end
  end

  # GET /news_bulletins/new
  # GET /news_bulletins/new.xml
  def new
    @news_bulletin_category = NewsBulletinCategory.new(:display => 'List')

    respond_to do |format|
      format.html # new.html.erb
      # format.xml  { render :xml => @news_bulletin_category }
      format.js
    end
  end

  def quick_edit
	# debugger
	
    @news_bulletin_category = NewsBulletinCategory.find(params[:news_bulletin_category_id])
	
	@url = panel_news_back_end_news_bulletin_category_path(@news_bulletin_category)
	
    respond_to do |format|
      format.js
    end
	
  end
  
  # GET /news_bulletins/1/edit
  def edit
    @news_bulletin_category = NewsBulletinCategory.find(params[:id])
	
	@url = panel_news_back_end_news_bulletin_category_path(@news_bulletin_category)

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

  # POST /news_bulletins
  # POST /news_bulletins.xml
  def create
    @news_bulletin_category = NewsBulletinCategory.new(params[:news_bulletin_category])

    respond_to do |format|
      if @news_bulletin_category.save
        # format.html { redirect_to @news_bulletin_category, notice: 'Entry was successfully created.' }
        format.html { redirect_to(panel_news_back_end_news_bulletin_categorys_url, :notice => t('news_bulletin.create_news_bulletin_category_success')) }
        # format.xml  { render :xml => @news_bulletin_category, :status => :created, :location => @news_bulletin_category }
        format.js
      else
        format.html { render :action => "new" }
        # format.xml  { render :xml => @news_bulletin_category.errors, :status => :unprocessable_entity }
        format.js { render action: "new" }
      end
    end
  end

  # PUT /news_bulletins/1
  # PUT /news_bulletins/1.xml
  def update
    @news_bulletin_category = NewsBulletinCategory.find(params[:id])
	
	@url = panel_news_back_end_news_bulletin_category_path(@news_bulletin_category)

    respond_to do |format|
      if @news_bulletin_category.update_attributes(params[:news_bulletin_category])
        # format.html { redirect_to(panel_news_back_end_news_bulletin_category_url(@news_bulletin_category), :notice => t('news_bulletin_category.update_news_bulletin_category_success')) }
        # format.html { redirect_to(panel_news_back_end_news_bulletin_categorys_url, :notice => t('news_bulletin_category.update_news_bulletin_category_success')) }
        # format.xml  { head :ok }
        format.js
      else
        format.html { render :action => "edit" }
        format.js { render :action => "edit" }
        # format.xml  { render :xml => @news_bulletin_category.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /news_bulletins/1
  # DELETE /news_bulletins/1.xml
  def destroy
    @news_bulletin_category = NewsBulletinCategory.find(params[:id])
    @news_bulletin_category.disable = @news_bulletin_category.disable ? false : true

    if @news_bulletin_category.save! 
      expire_page(:controller=>'panel/news/widget/news_bulletins' , :action=>'home_banner')
      respond_to do |format|
        flash[:notice] = t("update.success_")
        # flash[:error] +=  @bulletin_category.disable ?  t(enable) : t(disable)
        format.html { redirect_to(panel_announcement_back_end_news_bulletin_categorys_url) }
        # format.xml  { head :ok }
        format.js 
      end
    else
      flash[:error] = t("update.fail")
      format.html { render :action => "index" }

    end
  end
end
