/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.widget.ComboBox");
dojo.require("dojo.widget.*");
dojo.require("dojo.event.*");
dojo.widget.incrementalComboBoxDataProvider = function(url, limit, timeout){
this.searchUrl = url;
this.inFlight = false;
this.activeRequest = null;
this.allowCache = false;
this.cache = {};
this.init = function(cbox){
this.searchUrl = cbox.dataUrl;
}
this.addToCache = function(keyword, data){
if(this.allowCache){
this.cache[keyword] = data;
}
}
this.startSearch = function(searchStr, type, ignoreLimit){
if(this.inFlight){
// FIXME: implement backoff!
}
var tss = encodeURIComponent(searchStr);
var realUrl = dojo.string.paramString(this.searchUrl, {"searchString": tss});
var _this = this;
var request = dojo.io.bind({
url: realUrl,
method: "get",
mimetype: "text/json",
load: function(type, data, evt){
_this.inFlight = false;
if(!dojo.lang.isArray(data)){
var arrData = [];
for(var key in data){
arrData.push([data[key], key]);
}
data = arrData;
}
_this.addToCache(searchStr, data);
_this.provideSearchResults(data);
}
});
this.inFlight = true;
}
}
dojo.widget.ComboBoxDataProvider = function(dataPairs, limit, timeout){
// NOTE: this data provider is designed as a naive reference
// implementation, and as such it is written more for readability than
// speed. A deployable data provider would implement lookups, search
// caching (and invalidation), and a significantly less naive data
// structure for storage of items.
this.data = [];
this.searchTimeout = 500;
this.searchLimit = 30;
this.searchType = "STARTSTRING"; // may also be "STARTWORD" or "SUBSTRING"
this.caseSensitive = false;
// for caching optimizations
this._lastSearch = "";
this._lastSearchResults = null;
this.init = function(cbox, node){
if(!dojo.string.isBlank(cbox.dataUrl)){
this.getData(cbox.dataUrl);
}else{
// check to see if we can populate the list from