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/>.
**/
/**
* 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([ZBX_STYLE_BTN_ICON, ZBX_ICON_REMOVE_SMALLER, 'js-remove']),
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];