From f4eab719f88a730b19214da1c1021c9bd86b69c9 Mon Sep 17 00:00:00 2001 From: manson Date: Wed, 14 May 2014 10:58:06 +0800 Subject: [PATCH] Update index table --- .../admin/announcements_controller.rb | 43 +-------- .../{index_table.html.erb => _index.html.erb} | 0 app/views/admin/announcements/index.html.erb | 96 +++++++++---------- config/routes.rb | 1 - 4 files changed, 49 insertions(+), 91 deletions(-) rename app/views/admin/announcements/{index_table.html.erb => _index.html.erb} (100%) 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 @@
<% @filter_fields[field].each do |val| %> - <%= link_to t(val[:title]), "#", :onclick => "addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %> + <%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %> <% end %>
<% end %> @@ -25,65 +25,57 @@ <% end %> + <%= render 'index'%> <%= render 'layouts/delete_modal', delete_options: @delete_options %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a4d62b4..c06cd51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,6 @@ Rails.application.routes.draw do scope "(:locale)", locale: Regexp.new(locales.join("|")) do namespace :admin do - get 'announcements/index_table' => 'announcements#index_table' resources :announcements end