update backend search for modules

This commit is contained in:
manson 2014-08-07 18:44:23 +08:00
parent 68e0fbcd92
commit b4e5d36cc3
4 changed files with 22 additions and 4 deletions

View File

@ -15,15 +15,12 @@ class OrbitAdminController < ApplicationController
[:is_hidden,params[:order]]]
when "category"
@sort = {:category_id=>params[:order]}
when "title"
@sort = {:title=>params[:order]}
when "start_date"
@sort = {:postdate=>params[:order]}
when "end_date"
@sort = {:deadline=>params[:order]}
when "last_modified"
@sort = {:update_user_id=>params[:order]}
when "banner"
@sort = {'banner_id'=>params[:order]}
when "banner_name"
@ -38,6 +35,8 @@ class OrbitAdminController < ApplicationController
@sort = {:height=>params[:order]}
when "link"
@sort = {:out_link=>params[:order]}
else
@sort = {params[:sort].to_sym=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
@ -64,6 +63,18 @@ class OrbitAdminController < ApplicationController
end
end
def search_data(data, fields)
if params[:keywords].present?
key_string = params[:keywords]
key_string = key_string.strip.nil? ? key_string : key_string.strip
keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
data = data.any_of(fields.map{|f| {f.to_sym => regex} })
end
data
end
def load_authorized_categories
@user_authenticated_categories = current_user.is_admin? ? ["all"] : current_user.approved_categories.collect{|c| c.id}
end

View File

@ -11,7 +11,7 @@ module OrbitBackendHelper
arrow = (order.eql? "desc") ? "<b class='icons-arrow-up-3'></b>" : "<b class='icons-arrow-down-4'></b>"
klass = field.eql?(:title) ? "span5" : "span2"
th_data = (sort=="preview") ? t(field.to_sym) : "<a href='?sort=#{sort}&order=#{order}''>#{t(field.to_sym)} #{active ? arrow : ""}</a>"
th_data = (sort=="preview") ? t(field.to_sym) : "<a href='?sort=#{sort}&order=#{order}'>#{t(field.to_sym)} #{active ? arrow : ""}</a>"
"<th class='#{klass} #{active ? "active" : ""}'>#{th_data}</th>".html_safe
end

View File

@ -141,6 +141,7 @@
this.addFilter = function(filter){
filters = makeFilters();
$.each(filters,function(idx,data){
if(typeof(data)=="undefined") return true;
if(data.indexOf("page=")>-1) filters.splice(idx,1);
});
@ -177,4 +178,9 @@
}
var update = false;
var filter;
$(document).ready(function(){
filter = new Filter("#<%= search_dom_id %>");
bindPagination();
});
</script>

View File

@ -379,6 +379,7 @@ zh_tw:
or_lower:
organization: 組織
page: 頁面
page_id: ID
page_content:
page: 頁面
page_part_kinds: