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.
**/
/*
* 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
footerButtons: {}, // action buttons at the bottom of page
sessionStorageName: 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 = jQuery.map(selected_ids, function(id) { return id });
}
// 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);
}
this.footerButtons = jQuery('#action_buttons button:not(.no-chkbxrange)');
var thisChkbxRange = this;
this.footerButtons.each(function() {
addListener(this, 'click', thisChkbxRange.submitFooterButton.bindAsEventListener(thisChkbxRange), false);
});
},
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);