add search for backend index

This commit is contained in:
manson 2014-08-07 18:46:24 +08:00
parent a0391f0c1e
commit a69769c5b7
4 changed files with 48 additions and 58 deletions

View File

@ -1,29 +1,25 @@
class Admin::ArchiveFilesController < OrbitAdminController class Admin::ArchiveFilesController < OrbitAdminController
def index def index
@table_fields = [:status, :category, :title] @table_fields = [:status, :category, :title, :update_at,:last_modified]
@categories = @module_app.categories @categories = @module_app.categories
@tags = @module_app.tags @tags = @module_app.tags
@filter_fields = { @filter_fields = filter_fields(@categories, @tags)
: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}}
}
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 []
@archives = ArchiveFile.order_by(sort).with_categories(categories).with_tags(tags).with_status(status).page(params[:page]).per(10) @archives = ArchiveFile.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
.with_status(filters("status"))
if request.xhr? @archives = search_data(@archives,[:title]).page(params[:page]).per(10)
render :partial => "index"
end render :partial => "index" if request.xhr?
end end
def new def new
@archive_file = ArchiveFile.new @archive_file = ArchiveFile.new
@tags = @module_app.tags @tags = @module_app.tags
@categories = @module_app.categories @categories = @module_app.categories
end end
def edit def edit
@ -36,7 +32,7 @@ class Admin::ArchiveFilesController < OrbitAdminController
end end
end end
def create def create
@archive_file = ArchiveFile.new(archive_vars) @archive_file = ArchiveFile.new(archive_vars)
@archive_file.create_user_id = current_user.id @archive_file.create_user_id = current_user.id
@archive_file.update_user_id = current_user.id @archive_file.update_user_id = current_user.id
@ -80,12 +76,12 @@ class Admin::ArchiveFilesController < OrbitAdminController
private private
def archive_vars def archive_vars
params[:archive_file][:tags] ||=[] params[:archive_file][:tags] ||=[]
params.require(:archive_file).permit! params.require(:archive_file).permit!
end end
def setup_vars def setup_vars
@module_app = ModuleApp.where(:key => "archive").first @module_app = ModuleApp.where(:key => "archive").first
end end
def sort def sort
unless params[:sort].blank? unless params[:sort].blank?
@ -100,7 +96,7 @@ class Admin::ArchiveFilesController < OrbitAdminController
@sort = {:title=>params[:order]} @sort = {:title=>params[:order]}
when "last_modified" when "last_modified"
@sort = {:update_user_id=>params[:order]} @sort = {:update_user_id=>params[:order]}
end end
else else
@sort = {:created_at=>'desc'} @sort = {:created_at=>'desc'}
end end

View File

@ -42,7 +42,6 @@ class ArchivesController < ApplicationController
"url_to_edit" => url_to_edit "url_to_edit" => url_to_edit
} }
end end
{ {
"categories" => cats "categories" => cats
} }

View File

@ -3,36 +3,34 @@
</script> </script>
<table class="table main-list"> <table class="table main-list">
<thead> <thead>
<tr class="sort-header"> <tr class="sort-header">
<% @table_fields.each do |f| %> <% @table_fields.each do |f| %>
<%= thead(f) %> <%= thead(f) %>
<% end %> <% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @archives.each do |archive| %> <% @archives.each do |archive| %>
<tr> <tr>
<td> <td><%= archive.status_for_table %></td>
<%= archive.status_for_table %> <td><%= archive.category.title %></td>
</td> <td>
<td> <a href="#" target="_blank"><%= archive.title %></a>
<%= archive.category.title %> <div class="quick-edit">
</td> <ul class="nav nav-pills">
<td> <% if can_edit_or_delete?(archive) %>
<a href="#" target="_blank"><%= archive.title %></a> <li><a href="/<%= I18n.locale.to_s %>/admin/archive_files/<%= archive.id.to_s %>/edit"><%= t(:edit) %></a></li>
<div class="quick-edit"> <li><a href="/admin/archive_files/<%= archive.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
<ul class="nav nav-pills"> <% end %>
<% if can_edit_or_delete?(archive) %> </ul>
<li><a href="/<%= I18n.locale.to_s %>/admin/archive_files/<%= archive.id.to_s %>/edit"><%= t(:edit) %></a></li> </div>
<li><a href="/admin/archive_files/<%= archive.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li> </td>
<% end %> <td><%= format_value archive.updated_at rescue nil %></td>
</ul> <td><%= User.find(archive.update_user_id).user_name rescue nil %></td>
</div> </tr>
</td> <% end %>
</tr> </tbody>
<% end %>
</tbody>
</table> </table>
<%= <%=

View File

@ -1,7 +1,4 @@
<%= render_filter @filter_fields %> <%= render_filter @filter_fields, "index_table" %>
<div id="archivelist"> <div id="index_table">
<%= render 'index'%> <%= render 'index'%>
</div> </div>
<script type="text/javascript">
var filter = new Filter("#archivelist");
</script>