add search for backend index

This commit is contained in:
manson 2014-08-07 18:47:37 +08:00
parent f45ea12490
commit 5d7505fe21
3 changed files with 52 additions and 78 deletions

View File

@ -3,45 +3,20 @@ class Admin::FaqsController < OrbitAdminController
before_filter :setup_vars before_filter :setup_vars
def index def index
@table_fields = ["status","category","title","tags"] @table_fields = [:status,:category,:title,:tags]
@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 []
@qas = Qa.order_by(sort).with_categories(categories).with_tags(tags).with_status(status).page(params[:page]).per(10) @qas = Qa.order_by(sort)
.with_categories(filters("category"))
.with_tags(filters("tag"))
.with_status(filters("status"))
if request.xhr? @qas = search_data(@qas,[:title]).page(params[:page]).per(10)
render :partial => "index"
end
end
def sort render :partial => "index" if request.xhr?
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 "last_modified"
@sort = {:update_user_id=>params[:order]}
end end
else
@sort = {:created_at=>'desc'}
end
@sort
end
def new def new
@qa = Qa.new @qa = Qa.new

View File

@ -9,12 +9,8 @@
<tbody> <tbody>
<% @qas.each do |qa| %> <% @qas.each do |qa| %>
<tr> <tr>
<td> <td><%= qa.status_for_table %></td>
<%= qa.status_for_table %> <td><%= qa.category.title %></td>
</td>
<td>
<%= qa.category.title %>
</td>
<td> <td>
<a href="#" target="_blank"><%= qa.title %></a> <a href="#" target="_blank"><%= qa.title %></a>
<div class="quick-edit"> <div class="quick-edit">
@ -35,3 +31,9 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@qas), class: "pagination pagination-centered"
end
%>

View File

@ -1,8 +1,5 @@
<%= render_filter @filter_fields %> <%= render_filter @filter_fields, "index_table" %>
<div id="faqslist"> <div id="index_table">
<%= render 'index'%> <%= render 'index'%>
</div> </div>
<script type="text/javascript">
filter.init("#faqslist")
</script>