Source
<?php declare(strict_types = 1);
/*
** 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/>.
**/
?>
<script>
const view = new class {
init({groupid, name}) {
this.form = document.getElementById('templategroupForm');
this.groupid = groupid;
this.name = name;
this.form.addEventListener('submit', (e) => this._onSubmit(e));
this._initActionButtons();
}
_initActionButtons() {
document.addEventListener('click', (e) => {
if (e.target.classList.contains('js-update-templategroup')) {
this._submit(e.target);
}
else if (e.target.classList.contains('js-clone-templategroup')) {
this._clone();
}
else if (e.target.classList.contains('js-delete-templategroup')) {
this._delete(e.target);
}
});
}
_submit(button) {
this._setLoading(button);
const fields = getFormFields(this.form);
fields.name = fields.name.trim();
const curl = new Curl('zabbix.php');
curl.setArgument('action', this.groupid !== null ? 'templategroup.update' : 'templategroup.create');
this._post(curl.getUrl(), fields, (response) => {
postMessageOk(response.success.title);
if ('messages' in response.success) {
postMessageDetails('success', response.success.messages);
}
const url = new Curl('zabbix.php');
url.setArgument('action', 'templategroup.list');
location.href = url.getUrl();
});