Source
/*
** Zabbix
** 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 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.
**/
/**
* JQuery class that creates an override UI control - button that shows menu with available override options and pill
* buttons on which user can change selected option. Used in graph widget configuration window.
*/
jQuery(function ($) {
"use strict";
function createOverrideElement($override, option, value) {
var close = $('<button>', {'type': 'button'})
.on('click', function(e) {
$override.overrides('removeOverride', $override, option);
e.stopPropagation();
e.preventDefault();
})
.addClass('subfilter-disable-btn'),
opt = $override.data('options'),
field_name = opt.makeName(option, opt.getId($override));
if (option === 'color') {
const id = field_name.replace(/\]/g, '_').replace(/\[/g, '_');
const input = $('<input>', {'name': field_name, 'type': 'hidden', 'id': id}).val(value);
return $('<div>')
.addClass('color-picker')
.append(input)
.append(close);
}
else if (option === 'timeshift') {
return $('<div>')
.append($('<input>', {
'name': field_name,
'maxlength': 10,
'type': 'text',
'placeholder': t('S_TIME_SHIFT')
})
.val(value)
)
.append(close);
}
else {
var visible_name = option,
visible_value = value;
if (typeof opt.captions[option] !== 'undefined') {
visible_name = opt.captions[option];
}
if (typeof opt.captions[option + value] !== 'undefined') {
visible_value = opt.captions[option + value];
}
var content = [
$('<span>', {'data-option': option}).text(visible_name + ': ' + visible_value),
$('<input>').attr({'name': field_name, 'type': 'hidden'}).val(value)
];
return $('<div>')
.append(content)
.append(close);
}
}
function getMenu($obj, options, option_to_edit, trigger_elmnt) {
var sections = [],
menu = [],
option_to_edit = option_to_edit || null;
var appendMenuItem = function(menu, name, items, opt) {
if (items.length > 0) {
var item = items.shift();
if (typeof menu[item] === 'undefined') {