forked from saurabh/orbit4-5
search for module backend
This commit is contained in:
parent
a52239b135
commit
c656720132
|
@ -92,8 +92,8 @@ module OrbitBackendHelper
|
||||||
render :partial => '/admin/tags/tag_form', :locals => {:f=> f, :module_app=>module_app, :tags=>module_app.tags }
|
render :partial => '/admin/tags/tag_form', :locals => {:f=> f, :module_app=>module_app, :tags=>module_app.tags }
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_filter(fields)
|
def render_filter(fields, search_dom_id=nil)
|
||||||
render :partial => "shared/filter", :locals =>{:fields => fields}
|
render :partial => "shared/filter", :locals =>{:fields => fields, :search_dom_id=>search_dom_id}
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_visitors(options={})
|
def display_visitors(options={})
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
<% content_for :right_nav do %>
|
<% content_for :right_nav do %>
|
||||||
|
<% if !search_dom_id.nil?%>
|
||||||
|
<div class="searchClear pull-left" style="clear: left;">
|
||||||
|
<form id="module-search-form">
|
||||||
|
<input type="text" id="filter-input" class="search-query input-medium" placeholder="<%= t(:search_) %>" value="<%=params[:keywords]%>">
|
||||||
|
</form>
|
||||||
|
<img id="search-preloader" src="/assets/preloader.gif" style="height: 40px; position: absolute; left: 220px; top: -5px; display:none;">
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<ul class="nav nav-pills filter-nav pull-right">
|
<ul class="nav nav-pills filter-nav pull-right">
|
||||||
<% fields.keys.each do |field| %>
|
<% fields.keys.each do |field| %>
|
||||||
<li class="accordion-group">
|
<li class="accordion-group">
|
||||||
|
@ -24,15 +33,91 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
<% if !search_dom_id.nil?%>
|
||||||
|
var interval = 0;
|
||||||
|
var keyword;
|
||||||
|
var searchLock=false;
|
||||||
|
|
||||||
|
$("#filter-input").bind("input", function() {queueSearch();});
|
||||||
|
$("#module-search-form").submit(function(){queueSearch(); return false; });
|
||||||
|
|
||||||
|
var params = function(key){
|
||||||
|
var result = {};
|
||||||
|
var datas = window.location.search ? window.location.search.replace('?','').split('&') : []
|
||||||
|
datas.map(function(data){
|
||||||
|
tmp = data.split("=");
|
||||||
|
if(key){
|
||||||
|
if(tmp[0]==key){
|
||||||
|
if(tmp[0].indexOf('[]')>=0){
|
||||||
|
if(!Array.isArray(result)) result = [];
|
||||||
|
result.push(tmp[1]);
|
||||||
|
}else{
|
||||||
|
result = tmp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(tmp[0].indexOf('[]')>=0){
|
||||||
|
if(typeof(result[tmp[0]]) == "undefined") result[tmp[0]] = [];
|
||||||
|
result[tmp[0]].push(tmp[1]);
|
||||||
|
}else{
|
||||||
|
result[tmp[0]] = tmp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var queueSearch = function(){
|
||||||
|
if($("#filter-input").val()!=keyword){
|
||||||
|
keyword = $("#filter-input").val();
|
||||||
|
interval=500;
|
||||||
|
if(!searchLock) moduleSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var moduleSearch = function(){
|
||||||
|
$("#search-preloader").fadeIn();
|
||||||
|
searchLock = true;
|
||||||
|
if(interval==0){
|
||||||
|
url = document.URL;
|
||||||
|
if(url.indexOf("keywords=")>=0){
|
||||||
|
console.log("keywords="+params("keywords"));
|
||||||
|
url = url.replace("keywords="+params("keywords"),"keywords="+keyword)
|
||||||
|
}else{
|
||||||
|
url = (url.indexOf("?")>=0) ? url+'&'+"&keywords="+keyword : url+"?keywords="+keyword
|
||||||
|
}
|
||||||
|
|
||||||
|
history.replaceState(null, null, decodeURIComponent(url));
|
||||||
|
$.get(url,function(data){
|
||||||
|
searchLock = false;
|
||||||
|
$("#<%= search_dom_id %>").html(data);
|
||||||
|
bindPagination();
|
||||||
|
$("#search-preloader").fadeOut();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
interval -= 100;
|
||||||
|
setTimeout(moduleSearch,100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
var bindPagination = function(){
|
||||||
|
$(".pagination a").click(function(){
|
||||||
|
filter.updateTable($(this).attr('href'));
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var Filter = function(dom){
|
var Filter = function(dom){
|
||||||
|
var self = this;
|
||||||
var makeFilters = function(){
|
var makeFilters = function(){
|
||||||
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
||||||
}
|
}
|
||||||
var filters = makeFilters(),
|
var filters = makeFilters(),
|
||||||
dom = $(dom),
|
dom = $(dom),
|
||||||
mainUrl = window.location.pathname;
|
mainUrl = window.location.pathname;
|
||||||
var updateTable = function(url, goback){
|
this.updateTable = function(url, goback){
|
||||||
update = true;
|
update = true;
|
||||||
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : url);
|
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : url);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -46,13 +131,11 @@
|
||||||
|
|
||||||
filters = makeFilters();
|
filters = makeFilters();
|
||||||
dom.html(data);
|
dom.html(data);
|
||||||
$(".pagination a").click(function(){
|
bindPagination();
|
||||||
updateTable($(this).attr('href'));
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.addFilter = function(filter){
|
this.addFilter = function(filter){
|
||||||
|
filters = makeFilters();
|
||||||
$.each(filters,function(idx,data){
|
$.each(filters,function(idx,data){
|
||||||
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||||
});
|
});
|
||||||
|
@ -64,20 +147,20 @@
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTable();
|
self.updateTable();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.clearFilter = function(){
|
this.clearFilter = function(){
|
||||||
$(".filter-group a.active").removeClass("active");
|
$(".filter-group a.active").removeClass("active");
|
||||||
filters = [];
|
filters = [];
|
||||||
updateTable();
|
self.updateTable();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onpopstate = function(event){
|
window.onpopstate = function(event){
|
||||||
if(!update){
|
if(!update){
|
||||||
updateTable(document.location.href, true);
|
self.updateTable(document.location.href, true);
|
||||||
$(".filter-group .btn-small").removeClass('active');
|
$(".filter-group .btn-small").removeClass('active');
|
||||||
$.each(document.location.search.split('&'),function(key,filter){
|
$.each(document.location.search.split('&'),function(key,filter){
|
||||||
$('#filter_'+filter.split('=')[1]).addClass('active');
|
$('#filter_'+filter.split('=')[1]).addClass('active');
|
||||||
|
|
Loading…
Reference in New Issue