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,48 +3,23 @@ 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 render :partial => "index" if request.xhr?
end 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 "last_modified"
@sort = {:update_user_id=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
end
@sort
end
def new def new
@qa = Qa.new @qa = Qa.new
@tags = @module_app.tags @tags = @module_app.tags
@categories = @module_app.categories @categories = @module_app.categories
respond_to do |format| respond_to do |format|
@ -87,7 +62,7 @@ class Admin::FaqsController < OrbitAdminController
private private
def setup_vars def setup_vars
@module_app = ModuleApp.where(:key => "faq").first @module_app = ModuleApp.where(:key => "faq").first
end end
def create_params def create_params

View File

@ -1,37 +1,39 @@
<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>
<% @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>
<td> <a href="#" target="_blank"><%= qa.title %></a>
<%= qa.category.title %> <div class="quick-edit">
</td> <ul class="nav nav-pills">
<td> <% if can_edit_or_delete?(qa) %>
<a href="#" target="_blank"><%= qa.title %></a> <li><a href="/<%= I18n.locale.to_s %>/admin/faqs/<%= qa.id.to_s %>/edit"><%= t(:edit) %></a></li>
<div class="quick-edit"> <li><a href="/admin/faqs/<%= qa.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?(qa) %> </ul>
<li><a href="/<%= I18n.locale.to_s %>/admin/faqs/<%= qa.id.to_s %>/edit"><%= t(:edit) %></a></li> </div>
<li><a href="/admin/faqs/<%= qa.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li> </td>
<% end %> <td>
</ul> <% qa.tags.each do |tag| %>
</div> <span class="label label-warning"><%= tag.name %></span>
</td> <% end %>
<td> </td>
<% qa.tags.each do |tag| %> </tr>
<span class="label label-warning"><%= tag.name %></span> <% end %>
<% end %> </tbody>
</td>
</tr>
<% end %>
</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>