Source
xxxxxxxxxx
/*
** 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/>.
**/
/*
* Automatic checkbox range selection
*/
var chkbxRange = {
startbox: null, // start checkbox obj
chkboxes: {}, // ckbx list
prefix: null, // prefix for session storage variable name
pageGoName: null, // which checkboxes should be counted by Go button and saved to session storage
sessionStorageName: null,
event_handlers: null,
init: function() {
var path = new Curl();
var filename = basename(path.getPath(), '.php');
this.sessionStorageName = 'cb_' + filename + (this.prefix ? '_' + this.prefix : '');
// Erase old checkboxes.
this.chkboxes = {};
this.startbox = null;
this.resetOtherPage();
// initialize checkboxes
var chkboxes = jQuery('.list-table tbody input[type=checkbox]:not(:disabled)');
if (chkboxes.length > 0) {
for (var i = 0; i < chkboxes.length; i++) {
this.implement(chkboxes[i]);
}
}
// load selected checkboxes from session storage or cache
if (this.pageGoName != null) {
const selected_ids = this.getSelectedIds();
// check if checkboxes should be selected from session storage
if (!jQuery.isEmptyObject(selected_ids)) {
var objectIds = Object.keys(selected_ids);
}
// no checkboxes selected, check browser cache if checkboxes are still checked and update state
else {
var checkedFromCache = jQuery('main .list-table tbody input[type=checkbox]:checked:not(:disabled)');
var objectIds = jQuery.map(checkedFromCache, jQuery.proxy(function(checkbox) {
return this.getObjectIdFromName(checkbox.name);
}, this));
}
this.checkObjects(this.pageGoName, objectIds, true);
this.update(this.pageGoName);
}
if (this.event_handlers === null) {
this.event_handlers = {
action_button_click: (e) => this.submitFooterButton(e)
};
}
for (const footer_button of document.querySelectorAll('#action_buttons button:not(.js-no-chkbxrange)')) {
footer_button.addEventListener('click', this.event_handlers.action_button_click);
}
},
implement: function(obj) {
// skip the "select all" checkbox
if (obj.name.indexOf('all_') > -1) {
return;
}
var objName = this.getObjectFromName(obj.name);
if (typeof(this.chkboxes[objName]) === 'undefined') {
this.chkboxes[objName] = [];
}
this.chkboxes[objName].push(obj);
addListener(obj, 'click', this.handleClick.bindAsEventListener(this), false);
if (objName == this.pageGoName) {