diff --git a/app/controllers/admin/web_resources_controller.rb b/app/controllers/admin/web_resources_controller.rb index 526e89b..43615bb 100644 --- a/app/controllers/admin/web_resources_controller.rb +++ b/app/controllers/admin/web_resources_controller.rb @@ -4,55 +4,22 @@ class Admin::WebResourcesController < OrbitAdminController def index @tags = @module_app.tags - @categories = @module_app.categories - - @filter_fields = { - :status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}], - :category=>@categories.map{|c| {:title=>c.title, :id=>c.id}}, - :tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}} - } - end - - def index_table - status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue [] - categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue [] - tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue [] + @categories = @module_app.categories.enabled + @filter_fields = filter_fields(@categories, @tags) + @table_fields = [:status, :category, :title] @links = Kaminari.paginate_array( - WebLink.order_by(sort).with_categories(categories).with_tags(tags).with_status(status) + WebLink.order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")) ).page(params[:page]).per(10) - @table_fields = [:status, :category, :title] - render :layout => false - end - - def sort - unless params[:sort].blank? - case params[:sort] - when "status" - @sort = [[:is_top, params[:order]], - [:is_hot, params[:order]], - [:is_hidden,params[:order]]] - when "category" - @sort = {:category_id=>params[:order]} - when "title" - @sort = {:title=>params[:order]} - when "start_date" - @sort = {:postdate=>params[:order]} - when "end_date" - @sort = {:deadline=>params[:order]} - when "last_modified" - @sort = {:update_user_id=>params[:order]} - end - else - @sort = {:created_at=>'desc'} + if request.xhr? + render :partial => "index" end - @sort end def new @tags =@module_app.tags - @categories = @module_app.categories + @categories = @module_app.categories.enabled @statuses = [] @link = WebLink.new end @@ -67,7 +34,7 @@ class Admin::WebResourcesController < OrbitAdminController def edit @tags =@module_app.tags - @categories = @module_app.categories + @categories = @module_app.categories.enabled @statuses = [] end diff --git a/app/views/admin/web_resources/index_table.html.erb b/app/views/admin/web_resources/_index.html.erb similarity index 91% rename from app/views/admin/web_resources/index_table.html.erb rename to app/views/admin/web_resources/_index.html.erb index 30518c7..27a35d9 100644 --- a/app/views/admin/web_resources/index_table.html.erb +++ b/app/views/admin/web_resources/_index.html.erb @@ -12,7 +12,7 @@