diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index e5e3a96..6b60a85 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -11,49 +11,16 @@ class Admin::AnnouncementsController < OrbitAdminController def index @tags = @module_app.tags @categories = @module_app.categories.enabled - - @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 [] + @filter_fields = filter_fields(@categories, @tags) + @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] @bulletins = Kaminari.paginate_array( - Bulletin.order_by(sort).with_categories(categories).with_tags(tags).with_status(status) + Bulletin.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, :start_date, :end_date, :last_modified] - 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 diff --git a/app/views/admin/announcements/index_table.html.erb b/app/views/admin/announcements/_index.html.erb similarity index 100% rename from app/views/admin/announcements/index_table.html.erb rename to app/views/admin/announcements/_index.html.erb diff --git a/app/views/admin/announcements/index.html.erb b/app/views/admin/announcements/index.html.erb index f846c56..31d9a3b 100644 --- a/app/views/admin/announcements/index.html.erb +++ b/app/views/admin/announcements/index.html.erb @@ -13,11 +13,11 @@