class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController
  def initialize
    super
    @app_title = 'web_resource'
  end
  
  # GET /web_links
  # GET /web_links.xml
  

  def index
    if !params[:category_id].blank?
      @web_links = WebLink.where(:web_link_category => params[:category_id]).desc( :is_top, :postdate).page( params[:page]).per(10)
      @current_category = WebLinkCategory.from_id(params[:category_id]) rescue nil
    elsif !params[:tag_id].blank?
      @tag = WebResourceTag.find(params[:tag_id]) rescue nil
      @tag = WebResourceTag.where(key: params[:tag_id])[0] unless @tag
      @web_links = @tag.web_links.desc( :is_top, :postdate).page( params[:page]).per(10)
    else
      @web_links = WebLink.all.desc( :is_top, :postdate).page( params[:page]).per(10)
    end
  end



  def home_list
    @title = params[:part_title]
	
	# deadline
  
    # @web_link = WebLink.where( :is_hidden => false ).desc(:is_top, :name).first

    @web_links = WebLink.widget_datas.page(params[:page]).per(5)
	
	# get_categorys
  	
  	module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
  	@tags = Tag.all(:conditions => {:module_app_id => module_app.id})
	
  end

  def reload_web_links
    @web_links = WebLink.widget_datas.page(params[:page]).per(5)
  end
  
  
  protected
  
  def get_categorys
    @web_link_categorys = WebLinkCategory.excludes('disabled' => true)
  end
  
  def get_tags
  	module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
  	@tags = Tag.all(:conditions => {:module_app_id => module_app.id})
  end
  
end
