class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController

  def initialize
    super
    @app_title = 'announcement'
  end
  
  # GET /bulletins
  # GET /bulletins.xml
  
  def index
	
	# deadline
	# @bulletin_categorys = BulletinCategory.first;
    # @bulletins = Bulletin.widget_datas(@bulletin_categorys.id).limit(9)
    if !params[:category_id].blank?
      @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).widget_datas.limit(9)
    elsif !params[:tag_id].blank?
      @bulletins = AnnouncementTag.find(params[:tag_id]).bulletins.can_display.widget_datas.limit(9) rescue nil
    else
      @bulletins = Bulletin.can_display.widget_datas.limit(9)
    end
	
	get_categorys
	
  end
  
  def bulletins_and_web_links
    @tags = AnnouncementTag.all
    @selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0]
    @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil
    @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil
    render :layout => 'module_widget'
  end
  
  def reload_bulletins
    @selected_tag = AnnouncementTag.find(params[:tag_id])
    @bulletins = @selected_tag.get_visible_bulletins.can_display.page(params[:page]).per(5) rescue nil
  end
  
  def reload_web_links
    @selected_tag = AnnouncementTag.find(params[:tag_id])
    @web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(5) rescue nil
  end

  def bulletins_side_bar
    @tags = AnnouncementTag.all
    get_categorys
  end
  
  
  protected
  
  def get_categorys
    @bulletin_categorys = BulletinCategory.excludes('disabled' => true)
  end
  
end
