/************************************* * SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. * SPDX-License-Identifier: AGPL-3.0-only ************************************/ // crmv@140887 crmv@166949 // crmv@194443 jQuery(document).ready(function() { VTE.PanelFactory = VTE.PanelFactory || { panelPrefix: 'VTpanel', panelId: 0, generate: function(type, params) { var me = this; var panel = null; if (type == 'fastPanel') { panel = me.generateFastPanel(); } else if (type == 'detailPanel') { panel = me.generateDetailPanel(); } else if (type == 'relatedPanel') { panel = me.generateRelatedPanel(); } else { console.error('Unknown type'); } if (panel) { var panelId = me.generateId(); panel.id = panelId; var element = jQuery('
', { 'id': panelId, 'class': 'fastPanel', }); jQuery('#mainContent').append(element); } return panel; }, generateFastPanel: function() { return jQuery.extend({}, {}, VTE.FastPanel); }, generateDetailPanel: function() { return jQuery.extend({}, {}, VTE.FastDetailPanel); }, generateRelatedPanel: function() { return jQuery.extend({}, {}, VTE.FastRelatedPanel); }, generateId: function() { var me = this, panelPrefix = me.panelPrefix; me.panelId++; return [panelPrefix, me.panelId].join('_'); }, }; VTE.PanelManager = VTE.PanelManager || { panels: [], historyUrl: [], historyMaxSize: 15, zIndex: 1000, currentGenId: 0, maskActivePanel: function() { var me = this; var panel = me.getActivePanel(); if (panel) panel.showBusy(); }, unmaskActivePanel: function() { var me = this; var panel = me.getActivePanel(); if (panel) panel.hideBusy(); }, isActivePanelBusy: function() { var me = this; var panel = me.getActivePanel(); if (panel) return panel.busy; }, canAddPanel: function() { var me = this; return !(me.panels.length >= me.historyMaxSize); }, canOpenNewPanel: function() { var me = this; if (!me.canAddPanel()) return false; if (me.isActivePanelBusy()) return false; return true; }, addPanel: function(panel, replaceHistory) { var me = this, replaceHistory = replaceHistory || false; if (!me.canOpenNewPanel()) return; me.removePanel(panel); me.panels.push(panel); if (replaceHistory) { var url = panel.currentUrl; me.addHistoryUrl(url); } }, removePanel: function(panel, replaceHistory) { var me = this, panels = me.panels, replaceHistory = replaceHistory || false; var newPanels = me.panels.filter(function(p) { if (p && p.id) { return p.id !== panel.id; } }); me.panels = newPanels; if (replaceHistory) { var url = panel.currentUrl; me.removeHistoryUrl(url); } }, addHistoryUrl: function(url) { var me = this, historyUrl = me.historyUrl; if (!history.replaceState) return; if (historyUrl.length === 0) { historyUrl.push(window.location.href); } historyUrl.push(url); history.replaceState(null, null, url); }, removeHistoryUrl: function(url) { var me = this, historyUrl = me.historyUrl; if (!history.replaceState) return; historyUrl.reverse(); var idx = 0; var found = false; jQuery.each(historyUrl, function(i, h) { if (h === url) { idx = i; found = true; return false; } }); if (found) historyUrl.splice(idx, 1); historyUrl.reverse(); var lastHistoryUrl = me.getLastHistoryUrl(); history.replaceState(null, null, lastHistoryUrl); }, getLastHistoryUrl: function() { var me = this, historyUrl = me.historyUrl; if (historyUrl.length > 0) { return historyUrl.slice(-1).pop(); } return null; }, closeActivePanel: function() { var me = this, panels = me.panels; var panel = me.getActivePanel(); if (panel) { var closed = panel.forceClose(); if (closed) { me.removePanel(panel); } } }, getActivePanel: function() { var me = this, panels = me.panels; if (panels.length > 0) { return panels.slice(-1).pop(); } return null; }, editActivePanel: function() { var me = this; var panel = me.getActivePanel(); if (panel) panel.isChanged = true; }, arePanelsEdited: function() { var me = this, panels = me.panels; var editedPanels = panels.filter(function(p) { return p.isChanged; }); if (editedPanels.length > 0) return true; return false; }, resize: function() { var me = this, panels = me.panels; jQuery.each(panels, function(i, p) { if (p && p.id && p.isOpen) { var bkpAnimate = p.animate; p.animate = false; p.adjustPanelWidth(p.currentOptions); p.getPanel().css('z-index', me.zIndex+i); p.animate = bkpAnimate; } }); }, findZMax: function() { var me = this, panels = me.panels; var zindex = me.zIndex; jQuery.each(panels, function(i, p) { if (p && p.id && p.isOpen) { var pz = parseInt(p.getPanel().css('z-index')); if (pz > zindex) { zindex = pz; } } }); return zindex; }, createUniqueID: function() { var me = this; me.currentGenId++; return ['panel', me.currentGenId].join('_'); }, }; VTE.FastPanel = VTE.FastPanel || { id: 'fastPanel', mask: true, visible: true, // crmv@163519 animate: true, busy: false, isOpen: false, isSwitching: false, mode: 'full', // full, half, custom currentUrl: null, currentModule: null, currentOptions: {}, direction: 'left', delay: 250, cache: {}, modCommentsNewsHtmlCache: null, isCustomIconClicked: false, containerPrefix: 'VTcontainer', containers: [], replaceHistory: false, initialize: function(options) { var me = this, options = options || {}; me.containers = []; me.addContainer('iframeCont', 'iframe'); me.addContainer('ajaxCont', 'ajax'); me.addContainer('searchCont', 'ajax'); me.addContainer('menuCont', 'ajax'); }, showBusy: function() { var me = this; me.progress(me.id, 'light'); me.busy = true; }, hideBusy: function() { var me = this; me.hideprogress(me.id); me.busy = false; }, getPanel: function() { var me = this; return jQuery('#' + me.id); }, addContainer: function(id, type, params) { var me = this, panel = me.getPanel(); var container = null; if (type == 'iframe') { var iframe = jQuery('