Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
var LCL_SUGGESTS = [];
function createSuggest(oid) {
var sid = LCL_SUGGESTS.length;
LCL_SUGGESTS[sid] = new CSuggest(sid, oid);
return sid;
}
var CSuggest = function(id, objid) {
this.id = id;
this.cleanCache();
this.dom.input = document.getElementById(objid);
addListener(this.dom.input, 'keyup', this.keyPressed.bindAsEventListener(this));
addListener(this.dom.input, 'blur', this.suggestBlur.bindAsEventListener(this));
addListener(window, 'resize', this.positionSuggests.bindAsEventListener(this));
this.timeoutNeedle = null;
this.userNeedle = this.dom.input.value;
};
CSuggest.prototype = {
// public
'useLocal': true, // use cache to find suggests
'useServer': true, // use server to find suggests
'saveToCache': true, // save results to cache
'cacheTimeOut': 60, // cache timeout (seconds)
'suggestLimit': 15, // suggestion show limit
'searchDelay': 200, // milliseconds
// private
'id': null, // sugg obj identity
'rpcid': 0, // rpc request id
'needles': {}, // searched strings
'userNeedle': '', // userNeedle
'timeoutNeedle': null, // Timeout reference
'cache': {
'time': 0, // cache creation time
'list': {}, // cache by word
'needle': {} // cache by needle
},
'dom': {
'input': null, // DOM node input
'suggest': null, // DOM node suggest div
'sugtab': null // DOM node suggests table
},
'hlIndex': 0, // indicates what row should be highlighted
'suggestCount': 0, // suggests shown
'mouseOverSuggest': false, // indicates if mouse is over suggests
needleChange: function(e) {
this.hlIndex = 0;
this.suggestCount = 0;
clearTimeout(this.timeoutNeedle);
var target = e.target,
needle = target.value.toLowerCase();
if (empty(needle)) {
this.hideSuggests();
return true;
}
this.userNeedle = target.value;
this.needles[needle] = {'needle': needle, 'list': {}};
var found = false;
if (this.useLocal) {
found = this.searchClient(needle);
}
if (!found && this.useServer) {