class Panel::Announcement::BackEnd::FactChecksController  < OrbitBackendController
  before_filter :authenticate_user!
  include AdminHelper
  # layout 'admin'
  layout 'new_admin'
  
  def setting
    @bulletin_categorys = BulletinCategory.all
    if params.has_key?(:category_id)
      first_category = BulletinCategory.find params[:category_id]
      if params[:commit] == 'Update'
        privilege_users = params[:users].collect{|key,value| User.find key }  rescue []
        preload_object_auth_ary = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check')
        preload_object_auth = preload_object_auth_ary.first
        preload_object_auth.privilege_users = privilege_users
        preload_object_auth.save!
      end
    else
      first_category =  @bulletin_categorys.first
    end  
    preload_object_auth = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check')
    @users_array =  preload_object_auth.first.privilege_users rescue []
    respond_to do |format|
      format.html
      format.js
    end
  end
  
  def update_setting
    
  end
  # def index
  #   get_categorys(params[:bulletin_category_id])
  #   
  #   @bulletins = params[:sort] ? get_sorted_bulletins : Bulletin.all
  #   @bulletin_categories = BulletinCategory.all
  #   
  #   module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
  #   @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc)
  # 
  #   respond_to do |format|
  #     format.html # index.html.erb
  #     format.js
  #     format.xml  { render :xml => @bulletins }
  #   end
  # end
  # 
  # def new
  #   
  # end
  # 
  # def create
  #   
  # end
  # 
  # def update
  #   
  # end
  # 
  # def edit
  #   
  # end
  # 
  # def destroy
  #   
  # end
  protected
  def get_categorys(id = nil)
    @bulletin_categorys = []
    if(is_manager? || is_admin?)
      @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
    elsif is_sub_manager?
      @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
    end
  end
end
