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/>.
**/
const DASHBOARD_PAGE_STATE_INITIAL = 'initial';
const DASHBOARD_PAGE_STATE_ACTIVE = 'active';
const DASHBOARD_PAGE_STATE_INACTIVE = 'inactive';
const DASHBOARD_PAGE_STATE_DESTROYED = 'destroyed';
const DASHBOARD_PAGE_EVENT_EDIT = 'dashboard-page-edit';
const DASHBOARD_PAGE_EVENT_WIDGET_ADD = 'dashboard-page-widget-add';
const DASHBOARD_PAGE_EVENT_WIDGET_ADD_NEW = 'dashboard-page-widget-add-new';
const DASHBOARD_PAGE_EVENT_WIDGET_DELETE = 'dashboard-page-widget-delete';
const DASHBOARD_PAGE_EVENT_WIDGET_POSITION = 'dashboard-page-widget-position';
const DASHBOARD_PAGE_EVENT_WIDGET_EDIT = 'dashboard-page-widget-edit';
const DASHBOARD_PAGE_EVENT_WIDGET_ACTIONS = 'dashboard-page-widget-actions';
const DASHBOARD_PAGE_EVENT_WIDGET_COPY = 'dashboard-page-widget-copy';
const DASHBOARD_PAGE_EVENT_WIDGET_PASTE = 'dashboard-page-widget-paste';
const DASHBOARD_PAGE_EVENT_RESERVE_HEADER_LINES = 'dashboard-page-reserve-header-lines';
class CDashboardPage {
// Dashboard page ready event: informs the dashboard that the dashboard page has been fully loaded (fired once).
static EVENT_READY = 'dashboard-page-ready';
// Require data source event: informs the dashboard to load the referred data source.
static EVENT_REQUIRE_DATA_SOURCE = 'dashboard-page-require-data-source';
static PLACEHOLDER_DEFAULT_WIDTH = 6;
static PLACEHOLDER_DEFAULT_HEIGHT = 2;
// Minimum distance of mouse movement in pixels to assume that user is interacting intentionally.
static PLACEHOLDER_RESIZE_TRIGGER_DISTANCE = 25;
constructor(target, {
data,
dashboard,
cell_width,
cell_height,
max_columns,
max_rows,
widget_defaults,
is_editable,
is_edit_mode,
csrf_token = null,
unique_id
}) {
this._target = document.createElement('div');
this._dashboard_grid = target;
this._data = {