(function($) {
'use strict';
const ZBX_MACRO_TYPE_TEXT = 0;
const ZBX_MACRO_TYPE_SECRET = 1;
const ZBX_MACRO_TYPE_VAULT = 2;
const ZBX_STYLE_MACRO_VALUE_TEXT = 'macro-value-text';
const ZBX_STYLE_MACRO_VALUE_SECRET = 'macro-value-secret';
const ZBX_STYLE_MACRO_VALUE_VAULT = 'macro-value-vault';
const ZBX_STYLE_ICON_SECRET = 'icon-secret';
function btnUndoFocusEventHandle() {
$(this)
.closest('.macro-input-group')
.find('.btn-undo')
.toggleClass('is-focused');
}
function btnUndoClickEventHandle() {
var $this = $(this),
$container = $this.closest('.macro-input-group'),
$input_container = $('.input-secret, .textarea-flexible', $container),
$input = $('.input-secret input[type=password], .textarea-flexible', $container),
$dropdown_value = $('.dropdown-value', $container);
$input_container.replaceWith(
$('<div>')
.addClass('input-secret')
.append(
$('<input>')
.attr({
id: $input.attr('id'),
name: $input.attr('name'),
type: 'password',
value: '******',
placeholder: $input.attr('placeholder'),
maxlength: $input.attr('maxlength'),
disabled: true
})
.on('focus blur', btnUndoFocusEventHandle)
)
.append($('<button>').attr({
type: 'button',
id: $input.attr('name').replace(/\[/g, '_').replace(/\]/g, '') + '_btn',
class: 'btn-change'
}).text(t('Set new value')))
.inputSecret()
);
$dropdown_value
.val(ZBX_MACRO_TYPE_SECRET)
.trigger('change');
$('.btn-dropdown-container button', $container)
.removeClass([ZBX_ICON_TEXT, ZBX_ICON_LOCK])
.addClass(['btn-alt', 'btn-dropdown-toggle', ZBX_ICON_EYE_OFF]);
$this.hide();
}
function getCurrentValueType($container) {
if ($container.hasClass(ZBX_STYLE_MACRO_VALUE_VAULT)) {
return ZBX_MACRO_TYPE_VAULT;
}
else if ($container.hasClass(ZBX_STYLE_MACRO_VALUE_SECRET)) {
return ZBX_MACRO_TYPE_SECRET;
}