class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController

  def initialize
    super
    @app_title = 'news'
  end
  
  # GET /news_bulletins
  # GET /news_bulletins.xml
  
  def index
	
	# deadline
	# @news_bulletin_categorys = NewsBulletinCategory.first;
    # @news_bulletins = NewsBulletin.widget_datas(@news_bulletin_categorys.id).limit(9)
    if !params[:category_id].blank?
      @news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
    elsif !params[:tag_id].blank?
      @news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.can_display.widget_datas.limit(9) rescue nil
    else
      @news_bulletins = NewsBulletin.can_display.widget_datas.limit(9)
    end
	
	get_categorys
	
  end
  
  def news_bulletins_and_web_links
    @tags = NewsTag.all
    @selected_tag = NewsTag.find(params[:id]) rescue @tags[0]
    @news_bulletins = @selected_tag.get_visible_news_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_news_bulletins
    @selected_tag = NewsTag.find(params[:tag_id])
    @news_bulletins = @selected_tag.get_visible_news_bulletins.can_display.page(params[:page]).per(5) rescue nil
  end
  
  def reload_web_links
    @selected_tag = NewsTag.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 news_bulletins_side_bar
    @tags = NewsTag.all
    get_categorys
  end
  
  
  protected
  
  def get_categorys
    @news_bulletin_categorys = NewsBulletinCategory.excludes('disabled' => true)
  end
  
end
