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

View File

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

View File

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

View File

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