Source
* @param {boolean} trigger_change (optional) Either to trigger element on-change event once data added. True by default.
/*
** 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/>.
**/
(function($) {
var ZBX_STYLE_CLASS = 'multiselect-control';
const MS_ACTION_POPUP = 0;
const MS_ACTION_AUTOSUGGEST = 1;
const FILTER_PRESELECT_ACCEPT_ID = 'id';
/**
* Multi select helper.
*
* @param string options['object_name'] backend data source
* @param object options['objectOptions'] parameters to be added the request URL (optional)
*
* @see jQuery.multiSelect()
*/
$.fn.multiSelectHelper = function(options) {
options = $.extend({objectOptions: {}}, options);
var curl = new Curl('jsrpc.php');
curl.setArgument('type', PAGE_TYPE_TEXT_RETURN_JSON);
curl.setArgument('method', 'multiselect.get');
curl.setArgument('object_name', options.object_name);
for (var key in options.objectOptions) {
curl.setArgument(key, options.objectOptions[key]);
}
options.url = curl.getUrl();
return this.each(function() {
$(this).empty();
this.dataset.params = JSON.stringify(options);
$(this).multiSelect();
});
};
/*
* Multiselect methods
*/
var methods = {
/**
* Get multi select selected data.
*
* @return array array of multiselect value objects
*/
getData: function() {
var $obj = $(this).first(),
ms = $obj.data('multiSelect');
var data = [];
for (var id in ms.values.selected) {
var item = ms.values.selected[id];
data.push({
id: id,
name: item.name,
prefix: (typeof item.prefix === 'undefined') ? '' : item.prefix
});
}
// Sort entries by name field.
data.sort(function(a, b) {
if (a.name === b.name) {
return 0;
}
else {
return (a.name < b.name) ? -1 : 1;
}
});
return data;
},
/**
* Insert outside data
*