add search for backend index
This commit is contained in:
parent
f45ea12490
commit
5d7505fe21
|
@ -3,48 +3,23 @@ class Admin::FaqsController < OrbitAdminController
|
|||
before_filter :setup_vars
|
||||
|
||||
def index
|
||||
@table_fields = ["status","category","title","tags"]
|
||||
@table_fields = [:status,:category,:title,:tags]
|
||||
@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)
|
||||
|
||||
@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?
|
||||
render :partial => "index"
|
||||
end
|
||||
@qas = search_data(@qas,[:title]).page(params[:page]).per(10)
|
||||
|
||||
render :partial => "index" if request.xhr?
|
||||
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
|
||||
@qa = Qa.new
|
||||
@qa = Qa.new
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
respond_to do |format|
|
||||
|
@ -87,7 +62,7 @@ class Admin::FaqsController < OrbitAdminController
|
|||
|
||||
private
|
||||
def setup_vars
|
||||
@module_app = ModuleApp.where(:key => "faq").first
|
||||
@module_app = ModuleApp.where(:key => "faq").first
|
||||
end
|
||||
|
||||
def create_params
|
||||
|
|
|
@ -1,37 +1,39 @@
|
|||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @qas.each do |qa| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= qa.status_for_table %>
|
||||
</td>
|
||||
<td>
|
||||
<%= qa.category.title %>
|
||||
</td>
|
||||
<td>
|
||||
<a href="#" target="_blank"><%= qa.title %></a>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<% if can_edit_or_delete?(qa) %>
|
||||
<li><a href="/<%= I18n.locale.to_s %>/admin/faqs/<%= qa.id.to_s %>/edit"><%= t(:edit) %></a></li>
|
||||
<li><a href="/admin/faqs/<%= qa.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<% qa.tags.each do |tag| %>
|
||||
<span class="label label-warning"><%= tag.name %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @qas.each do |qa| %>
|
||||
<tr>
|
||||
<td><%= qa.status_for_table %></td>
|
||||
<td><%= qa.category.title %></td>
|
||||
<td>
|
||||
<a href="#" target="_blank"><%= qa.title %></a>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<% if can_edit_or_delete?(qa) %>
|
||||
<li><a href="/<%= I18n.locale.to_s %>/admin/faqs/<%= qa.id.to_s %>/edit"><%= t(:edit) %></a></li>
|
||||
<li><a href="/admin/faqs/<%= qa.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<% qa.tags.each do |tag| %>
|
||||
<span class="label label-warning"><%= tag.name %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%=
|
||||
content_tag :div, class: "bottomnav clearfix" do
|
||||
content_tag :div, paginate(@qas), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
|
@ -1,8 +1,5 @@
|
|||
<%= render_filter @filter_fields %>
|
||||
<div id="faqslist">
|
||||
<%= render 'index'%>
|
||||
<%= render_filter @filter_fields, "index_table" %>
|
||||
<div id="index_table">
|
||||
<%= render 'index'%>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
filter.init("#faqslist")
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue