Source
* @param {boolean} trigger_change (optional) Either to trigger element on-change event once data added. True by default.
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
(function($) {
var ZBX_STYLE_CLASS = 'multiselect-control';
const MS_ACTION_POPUP = 0;
const MS_ACTION_AUTOSUGGEST = 1;
/**
* 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', 11); // 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;
},