search delay and hide empty popup

This commit is contained in:
Fabio Comuni 2011-10-25 15:50:34 +02:00
parent 155a09cfdf
commit bed0043b30

View File

@ -18,13 +18,14 @@ function ACPopup(elm,backend_url){
w = $(elm).width(); w = $(elm).width();
h = $(elm).height(); h = $(elm).height();
style.top=style.top+h; style.top=style.top+h;
style.height = '150px'; style['max-height'] = '150px';
style.width = w; style.width = w;
style.border = '1px solid red'; style.border = '1px solid red';
style.background = '#cccccc'; style.background = '#cccccc';
style.position = 'absolute'; style.position = 'absolute';
style.overflow = 'auto'; style.overflow = 'auto';
style['z-index'] = '100000'; style['z-index'] = '100000';
style.display = 'none';
this.cont = $("<div class='acpopup'></div>"); this.cont = $("<div class='acpopup'></div>");
this.cont.css(style); this.cont.css(style);
@ -36,18 +37,19 @@ ACPopup.prototype.close = function(){
this.ready=false; this.ready=false;
} }
ACPopup.prototype.search = function(text){ ACPopup.prototype.search = function(text){
var that = this;
this.searchText=text; this.searchText=text;
/*if (this.kp_timer) clearTimeout(this.kp_timer); if (this.kp_timer) clearTimeout(this.kp_timer);
this.kp_timer = setTimeout( this._search, 1000);*/ this.kp_timer = setTimeout( function(){that._search();}, 1000);
this._search();
} }
ACPopup.prototype._search = function(){ ACPopup.prototype._search = function(){
console.log("_search");
var that = this; var that = this;
var postdata = { var postdata = {
start:0, start:0,
count:100, count:100,
search:this.searchText, search:this.searchText,
type:'c',
} }
$.ajax({ $.ajax({
@ -57,12 +59,15 @@ ACPopup.prototype._search = function(){
dataType: 'json', dataType: 'json',
success:function(data){ success:function(data){
that.cont.html(""); that.cont.html("");
if (data.tot>0){
that.cont.show();
$(data.items).each(function(){ $(data.items).each(function(){
if (this.type=="c"){
html = "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(this.photo, this.name, this.nick) html = "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(this.photo, this.name, this.nick)
that.add(html, this.nick); that.add(html, this.nick);
}
}); });
} else {
that.cont.hide();
}
} }
}); });