2024-05-27 22:28:10 +02:00
|
|
|
import {css, html, LitElement, nothing, PropertyValues} from "lit";
|
2024-04-25 19:35:34 +02:00
|
|
|
import {customElement} from "lit/decorators/custom-element.js";
|
|
|
|
import {property} from "lit/decorators/property.js";
|
|
|
|
import {classMap} from "lit/directives/class-map.js";
|
2024-05-08 16:32:23 +02:00
|
|
|
import {repeat} from "lit/directives/repeat.js";
|
2024-07-09 19:43:45 +02:00
|
|
|
import {until} from "lit/directives/until.js";
|
2024-04-25 19:35:34 +02:00
|
|
|
import "@shoelace-style/shoelace/dist/components/split-panel/split-panel.js";
|
|
|
|
import styles from "./EgwFramework.styles";
|
2024-05-08 16:32:23 +02:00
|
|
|
import {egw} from "../../api/js/jsapi/egw_global";
|
2024-07-09 19:43:45 +02:00
|
|
|
import {SlAlert, SlDropdown, SlTab, SlTabGroup} from "@shoelace-style/shoelace";
|
2024-05-08 16:32:23 +02:00
|
|
|
import {EgwFrameworkApp} from "./EgwFrameworkApp";
|
2024-07-09 19:43:45 +02:00
|
|
|
import {EgwFrameworkMessage} from "./EgwFrameworkMessage";
|
2024-04-25 19:35:34 +02:00
|
|
|
|
2024-04-26 00:05:14 +02:00
|
|
|
/**
|
|
|
|
* @summary Accessable, webComponent-based EGroupware framework
|
|
|
|
*
|
|
|
|
* @dependency sl-dropdown
|
|
|
|
* @dependency sl-icon-button
|
|
|
|
*
|
|
|
|
* @slot - Current application
|
|
|
|
* @slot banner - Very top, used for things like persistant, system wide messages. Normally hidden.
|
|
|
|
* @slot header - Top of page, contains logo, app icons.
|
|
|
|
* @slot header-right - Top right, contains user info / actions.
|
|
|
|
* @slot status - Home of the status app, it is limited in size and can be resized and hidden.
|
|
|
|
* @slot footer - Very bottom. Normally hidden.
|
|
|
|
* *
|
|
|
|
* @csspart base - Wraps it all.
|
|
|
|
* @csspart banner -
|
|
|
|
* @csspart header -
|
|
|
|
* @csspart open-applications - Tab group that has the currently open applications
|
|
|
|
* @csspart status-split - Status splitter
|
|
|
|
* @csspart main
|
|
|
|
* @csspart status
|
|
|
|
* @csspart footer
|
|
|
|
*
|
|
|
|
* @cssproperty [--icon-size=32] - Height of icons used in the framework
|
2024-07-05 00:03:51 +02:00
|
|
|
* @cssproperty [--tab-icon-size=32] - Height of application icons in header bar
|
|
|
|
* @cssproperty [--tab-icon-size-active=40] - Height of active application icon
|
2024-04-26 00:05:14 +02:00
|
|
|
*/
|
2024-04-25 19:35:34 +02:00
|
|
|
@customElement('egw-framework')
|
|
|
|
//@ts-ignore
|
|
|
|
export class EgwFramework extends LitElement
|
|
|
|
{
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
styles,
|
|
|
|
|
|
|
|
// TEMP STUFF
|
|
|
|
css`
|
2024-04-26 18:13:24 +02:00
|
|
|
:host .placeholder {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
:host(.placeholder) .placeholder {
|
2024-04-25 19:35:34 +02:00
|
|
|
width: 100%;
|
|
|
|
display: block;
|
|
|
|
font-size: 200%;
|
|
|
|
text-align: center;
|
|
|
|
background-color: var(--placeholder-background-color, silver);
|
|
|
|
}
|
|
|
|
|
|
|
|
.placeholder:after {
|
|
|
|
content: " (placeholder)";
|
|
|
|
}
|
|
|
|
|
|
|
|
.egw_fw__base {
|
|
|
|
--placeholder-background-color: #75bd20;
|
|
|
|
}
|
|
|
|
|
|
|
|
.egw_fw__status .placeholder {
|
|
|
|
writing-mode: vertical-rl;
|
|
|
|
text-orientation: mixed;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
2024-04-26 18:13:24 +02:00
|
|
|
:host(.placeholder) [class*="left"] .placeholder {
|
|
|
|
background-color: color-mix(in lch, var(--placeholder-background-color), rgba(.5, .5, 1, .5));
|
|
|
|
}
|
|
|
|
|
|
|
|
:host(.placeholder) [class*="right"] .placeholder {
|
|
|
|
background-color: color-mix(in lch, var(--placeholder-background-color), rgba(.5, 1, .5, .5));
|
2024-04-25 19:35:34 +02:00
|
|
|
}
|
|
|
|
|
2024-04-26 18:13:24 +02:00
|
|
|
:host(.placeholder) [class*="footer"] .placeholder {
|
2024-04-25 19:35:34 +02:00
|
|
|
background-color: color-mix(in lch, var(--placeholder-background-color), rgba(1, 1, 1, .05));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::slotted(div#egw_fw_sidebar_r) {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@property()
|
|
|
|
layout = "default";
|
|
|
|
|
2024-05-08 21:46:09 +02:00
|
|
|
/**
|
|
|
|
* This is the list of all applications we know about
|
|
|
|
*/
|
2024-04-26 00:05:14 +02:00
|
|
|
@property({type: Array, attribute: "application-list"})
|
2024-05-29 00:14:52 +02:00
|
|
|
applicationList : ApplicationInfo[] = [];
|
2024-04-25 19:35:34 +02:00
|
|
|
|
2024-07-08 21:45:04 +02:00
|
|
|
// Keep track of open popups
|
|
|
|
private _popups : Window[] = [];
|
|
|
|
|
2024-07-09 19:43:45 +02:00
|
|
|
// Keep track of open messages
|
|
|
|
private _messages : SlAlert[] = [];
|
|
|
|
|
2024-05-08 21:46:09 +02:00
|
|
|
private get tabs() : SlTabGroup { return this.shadowRoot.querySelector("sl-tab-group");}
|
|
|
|
|
2024-05-14 16:17:06 +02:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
if(this.egw.window && this.egw.window.opener == null && !this.egw.window.framework)
|
|
|
|
{
|
|
|
|
// This works, but stops a lot else from working
|
2024-05-27 18:49:06 +02:00
|
|
|
this.egw.window.framework = this;
|
2024-05-14 16:17:06 +02:00
|
|
|
}
|
|
|
|
if(this.egw.window?.framework && this.egw.window?.framework !== this)
|
|
|
|
{
|
|
|
|
// Override framework setSidebox, use arrow function to force context
|
|
|
|
this.egw.framework.setSidebox = (applicationName, sideboxData, hash?) => this.setSidebox(applicationName, sideboxData, hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 22:28:10 +02:00
|
|
|
protected firstUpdated(_changedProperties : PropertyValues)
|
|
|
|
{
|
|
|
|
super.firstUpdated(_changedProperties);
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
// Load hidden apps like status, as long as they can be loaded
|
2024-05-27 22:28:10 +02:00
|
|
|
this.applicationList.forEach((app) =>
|
|
|
|
{
|
2024-05-29 00:14:52 +02:00
|
|
|
if(app.status == "5" && app.url && !app.url.match(/menuaction\=none/))
|
2024-05-27 22:28:10 +02:00
|
|
|
{
|
|
|
|
this.loadApp(app.name);
|
|
|
|
}
|
|
|
|
});
|
2024-05-29 00:14:52 +02:00
|
|
|
// Load additional tabs
|
|
|
|
Object.values(this.tabApps).forEach(app => this.loadApp(app.name));
|
2024-05-27 22:28:10 +02:00
|
|
|
|
|
|
|
// Init timer
|
|
|
|
this.egw.add_timer('topmenu_info_timer');
|
2024-06-17 17:25:40 +02:00
|
|
|
|
2024-07-05 21:30:49 +02:00
|
|
|
// These need egw fully loaded
|
2024-06-17 17:25:40 +02:00
|
|
|
this.getEgwComplete().then(() =>
|
|
|
|
{
|
2024-07-09 19:43:45 +02:00
|
|
|
// Regisert the "message" plugin
|
|
|
|
this.egw.registerJSONPlugin((type, res, req) =>
|
|
|
|
{
|
|
|
|
//Check whether all needed parameters have been passed and call the alertHandler function
|
|
|
|
if((typeof res.data.message != 'undefined'))
|
|
|
|
{
|
|
|
|
this.message(res.data.message, res.data.type)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw 'Invalid parameters';
|
|
|
|
}, null, 'message');
|
|
|
|
|
2024-07-05 21:30:49 +02:00
|
|
|
// Quick add
|
|
|
|
this.egw.link_quick_add('topmenu_info_quick_add');
|
|
|
|
|
|
|
|
// Deal with bug where avatar menu does not position correctly
|
2024-06-17 17:25:40 +02:00
|
|
|
(<SlDropdown>this.querySelector("#topmenu_info_user_avatar"))?.popup?.dispatchEvent(new Event("slotchange"));
|
|
|
|
});
|
2024-05-27 22:28:10 +02:00
|
|
|
}
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
/**
|
|
|
|
* Special tabs that are not directly associated with an application (CRM)
|
|
|
|
* @type {[]}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
protected get tabApps() : { [id : string] : ApplicationInfo }
|
|
|
|
{
|
|
|
|
return JSON.parse(egw.getSessionItem('api', 'fw_tab_apps') || null) || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected set tabApps(apps : { [id : string] : ApplicationInfo })
|
|
|
|
{
|
|
|
|
egw.setSessionItem('api', 'fw_tab_apps', JSON.stringify(apps));
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:32:23 +02:00
|
|
|
get egw() : typeof egw
|
2024-04-25 19:35:34 +02:00
|
|
|
{
|
2024-05-08 16:32:23 +02:00
|
|
|
return window.egw ?? <typeof egw>{
|
2024-05-02 19:17:15 +02:00
|
|
|
// Dummy egw so we don't get failures from missing methods
|
2024-04-25 19:35:34 +02:00
|
|
|
lang: (t) => t,
|
2024-05-02 19:17:15 +02:00
|
|
|
preference: (n, app, promise? : Function | boolean | undefined) => Promise.resolve(""),
|
|
|
|
set_preference(_app : string, _name : string, _val : any, _callback? : Function) {}
|
2024-04-25 19:35:34 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-05-30 23:19:21 +02:00
|
|
|
/**
|
|
|
|
* A promise for if egw is loaded
|
|
|
|
*
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
getEgwComplete()
|
|
|
|
{
|
|
|
|
let egwLoading = Promise.resolve();
|
|
|
|
if(typeof this.egw.window['egw_ready'] !== "undefined")
|
|
|
|
{
|
|
|
|
egwLoading = this.egw.window['egw_ready'];
|
|
|
|
}
|
|
|
|
return egwLoading;
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:32:23 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param _function Framework function to be called on the server.
|
|
|
|
* @param _ajax_exec_url Actual function we want to call.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
public getMenuaction(_fun, _ajax_exec_url, appName = 'home')
|
|
|
|
{
|
|
|
|
let baseUrl = this.getBaseUrl();
|
|
|
|
|
|
|
|
// Check whether the baseurl is actually set. If not, then this application
|
|
|
|
// resides inside the same egw instance as the jdots framework. We'll simply
|
|
|
|
// return a menu action and not a full featured url here.
|
|
|
|
if(baseUrl != '')
|
|
|
|
{
|
|
|
|
baseUrl = baseUrl + 'json.php?menuaction=';
|
|
|
|
}
|
|
|
|
|
|
|
|
const menuaction = _ajax_exec_url ? _ajax_exec_url.match(/menuaction=([^&]+)/) : null;
|
|
|
|
|
|
|
|
// use template handler to call current framework, eg. pixelegg
|
|
|
|
return baseUrl + appName + '.kdots_framework.' + _fun + '.template' +
|
|
|
|
(menuaction ? '.' + menuaction[1] : '');
|
|
|
|
};
|
|
|
|
|
2024-05-27 18:49:06 +02:00
|
|
|
public getApplicationByName(appName)
|
|
|
|
{
|
|
|
|
return this.querySelector(`egw-app[name="${appName}"]`);
|
|
|
|
}
|
|
|
|
|
2024-05-14 16:17:06 +02:00
|
|
|
/**
|
|
|
|
* Load an application into the framework
|
|
|
|
*
|
2024-05-27 18:49:06 +02:00
|
|
|
* Loading is done by name, and we look up everything we need in the applicationList.
|
|
|
|
* If already loaded, this just returns the existing EgwFrameworkApp, optionally activated & with new URL loaded.
|
2024-05-14 16:17:06 +02:00
|
|
|
*
|
|
|
|
* @param {string} appname
|
|
|
|
* @param {boolean} active
|
|
|
|
* @param {string} url
|
|
|
|
* @returns {EgwFrameworkApp}
|
|
|
|
*/
|
|
|
|
public loadApp(appname : string, active = false, url = null) : EgwFrameworkApp
|
2024-05-08 16:32:23 +02:00
|
|
|
{
|
2024-05-29 00:14:52 +02:00
|
|
|
const existing : EgwFrameworkApp = this.querySelector(`egw-app[id="${appname}"]`);
|
2024-05-14 16:17:06 +02:00
|
|
|
if(existing)
|
|
|
|
{
|
|
|
|
if(active)
|
|
|
|
{
|
|
|
|
this.tabs.show(appname);
|
|
|
|
}
|
|
|
|
if(url)
|
|
|
|
{
|
2024-05-31 18:22:13 +02:00
|
|
|
existing.load(url);
|
2024-05-14 16:17:06 +02:00
|
|
|
}
|
|
|
|
return existing;
|
|
|
|
}
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
const app = this.applicationList.find(a => a.name == appname) ??
|
|
|
|
this.tabApps[appname];
|
|
|
|
|
|
|
|
if(!app)
|
|
|
|
{
|
|
|
|
console.log("Cannot load unknown app '" + appname + "'");
|
|
|
|
return null;
|
|
|
|
}
|
2024-05-08 16:32:23 +02:00
|
|
|
let appComponent = <EgwFrameworkApp>document.createElement("egw-app");
|
2024-05-27 18:49:06 +02:00
|
|
|
appComponent.setAttribute("id", appname);
|
2024-05-29 00:14:52 +02:00
|
|
|
appComponent.setAttribute("name", app.internalName || appname);
|
2024-05-14 16:17:06 +02:00
|
|
|
appComponent.url = url ?? app?.url;
|
2024-05-29 00:14:52 +02:00
|
|
|
if(app.title)
|
|
|
|
{
|
|
|
|
appComponent.title = app.title;
|
|
|
|
}
|
2024-05-08 21:46:09 +02:00
|
|
|
|
2024-05-08 16:32:23 +02:00
|
|
|
this.append(appComponent);
|
2024-05-08 21:46:09 +02:00
|
|
|
// App was not in the tab list
|
|
|
|
if(typeof app.opened == "undefined")
|
|
|
|
{
|
|
|
|
app.opened = this.shadowRoot.querySelectorAll("sl-tab").length;
|
2024-05-30 18:57:31 +02:00
|
|
|
// Need to update tabApps directly, reference doesn't work
|
|
|
|
if(typeof this.tabApps[appname] == "object")
|
|
|
|
{
|
|
|
|
let tabApps = {...this.tabApps};
|
|
|
|
tabApps[appname] = app;
|
|
|
|
this.tabApps = tabApps;
|
|
|
|
}
|
2024-05-14 16:17:06 +02:00
|
|
|
this.requestUpdate("applicationList");
|
2024-05-08 21:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until new tab is there to activate it
|
2024-05-29 00:14:52 +02:00
|
|
|
if(active || app.active)
|
2024-05-08 21:46:09 +02:00
|
|
|
{
|
2024-06-11 01:33:05 +02:00
|
|
|
// Wait for egw
|
|
|
|
this.getEgwComplete().then(() =>
|
2024-05-08 21:46:09 +02:00
|
|
|
{
|
2024-06-11 01:33:05 +02:00
|
|
|
// Wait for redraw after getEgwComplete promise
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
// Tabs present
|
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
2024-06-11 17:03:04 +02:00
|
|
|
this.showTab(appname);
|
2024-06-11 01:33:05 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2024-05-08 21:46:09 +02:00
|
|
|
}
|
2024-05-08 16:32:23 +02:00
|
|
|
|
|
|
|
return appComponent;
|
|
|
|
}
|
|
|
|
|
2024-05-27 18:49:06 +02:00
|
|
|
public get activeApp() : EgwFrameworkApp
|
|
|
|
{
|
|
|
|
return this.querySelector("egw-app[active]");
|
|
|
|
}
|
|
|
|
|
2024-05-14 16:17:06 +02:00
|
|
|
/**
|
|
|
|
* Load a link into the framework
|
|
|
|
*
|
|
|
|
* @param {string} _link
|
|
|
|
* @param {string} _app
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
public linkHandler(_link : string, _app : string)
|
|
|
|
{
|
2024-05-29 00:14:52 +02:00
|
|
|
// Determine the app string from the application parameter
|
2024-05-14 16:17:06 +02:00
|
|
|
let app = null;
|
|
|
|
if(_app && typeof _app == 'string')
|
|
|
|
{
|
|
|
|
app = this.applicationList.find(a => a.name == _app);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!app)
|
|
|
|
{
|
|
|
|
//The app parameter was false or not a string or the application specified did not exists.
|
|
|
|
//Determine the target application from the link that had been passed to this function
|
|
|
|
app = this.parseAppFromUrl(_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(app)
|
|
|
|
{
|
|
|
|
if(_app == '_tab')
|
|
|
|
{
|
|
|
|
// add target flag
|
|
|
|
_link += '&target=_tab';
|
|
|
|
const appname = app.appName + ":" + btoa(_link);
|
2024-05-29 00:14:52 +02:00
|
|
|
this.applicationList.push({
|
|
|
|
...app,
|
|
|
|
name: appname,
|
|
|
|
url: _link,
|
|
|
|
title: 'view'
|
|
|
|
});
|
|
|
|
app = this.applicationList[this.applicationList.length - 1];
|
2024-05-14 16:17:06 +02:00
|
|
|
}
|
|
|
|
this.loadApp(app.name, true, _link);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Display some error messages to have visible feedback
|
|
|
|
if(typeof _app == 'string')
|
|
|
|
{
|
|
|
|
egw_alertHandler('Application "' + _app + '" not found.',
|
|
|
|
'The application "' + _app + '" the link "' + _link + '" points to is not registered.');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw_alertHandler("No appropriate target application has been found.",
|
|
|
|
"Target link: " + _link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
public tabLinkHandler(_link : string, _extra = {
|
|
|
|
id: ""
|
|
|
|
})
|
|
|
|
{
|
|
|
|
const app = this.parseAppFromUrl(_link);
|
|
|
|
if(app)
|
|
|
|
{
|
|
|
|
const appname = app.name + "-" + btoa(_extra.id ? _extra.id : _link).replace(/=/g, 'i');
|
|
|
|
if(this.getApplicationByName(appname))
|
|
|
|
{
|
|
|
|
this.loadApp(appname, true, _link);
|
|
|
|
return appname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add target flag
|
|
|
|
_link += '&fw_target=' + appname;
|
|
|
|
// create an actual clone of existing app object
|
|
|
|
let clone = {
|
|
|
|
...app,
|
|
|
|
..._extra,
|
|
|
|
//isFrameworkTab: true, ??
|
|
|
|
name: appname,
|
|
|
|
internalName: app.name,
|
|
|
|
url: _link,
|
|
|
|
// Need to override to open, base app might already be opened
|
|
|
|
opened: undefined
|
|
|
|
};
|
|
|
|
// Store only in session
|
|
|
|
let tabApps = {...this.tabApps};
|
|
|
|
tabApps[appname] = clone;
|
|
|
|
this.tabApps = tabApps;
|
|
|
|
this.loadApp(appname, true);
|
|
|
|
|
|
|
|
return appname;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw_alertHandler("No appropriate target application has been found.",
|
|
|
|
"Target link: " + _link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 18:49:06 +02:00
|
|
|
/**
|
|
|
|
* Open a (centered) popup window with given size and url
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
* @param {number} _width
|
|
|
|
* @param {number} _height
|
|
|
|
* @param {string} _windowName or "_blank"
|
|
|
|
* @param {string|boolean} _app app-name for framework to set correct opener or false for current app
|
|
|
|
* @param {boolean} _returnID true: return window, false: return undefined
|
|
|
|
* @param {type} _status "yes" or "no" to display status bar of popup
|
|
|
|
* @param {DOMWindow} _parentWnd parent window
|
|
|
|
* @returns {DOMWindow|undefined}
|
|
|
|
*/
|
|
|
|
public openPopup(_url, _width, _height, _windowName, _app, _returnID, _status, _parentWnd)
|
|
|
|
{
|
2024-06-17 23:18:51 +02:00
|
|
|
const windowID = this.egw.openPopup(_url, _width, _height, _windowName, _app, true, _status, true);
|
2024-05-27 18:49:06 +02:00
|
|
|
|
|
|
|
windowID.framework = this;
|
2024-07-08 21:45:04 +02:00
|
|
|
this._popups.push(windowID);
|
2024-05-27 18:49:06 +02:00
|
|
|
|
|
|
|
if(_returnID !== false)
|
|
|
|
{
|
|
|
|
return windowID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-08 21:45:04 +02:00
|
|
|
/**
|
|
|
|
* Collect and close all already closed windows
|
|
|
|
* egw.open_link expects it from the framework
|
|
|
|
*/
|
|
|
|
public popups_garbage_collector()
|
|
|
|
{
|
|
|
|
for(var i = 0; i < this._popups.length; i++)
|
|
|
|
{
|
|
|
|
if(this._popups[i].closed)
|
|
|
|
{
|
|
|
|
this._popups.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-14 16:17:06 +02:00
|
|
|
/**
|
|
|
|
* Tries to obtain the application from a menuaction
|
|
|
|
* @param {string} _url
|
|
|
|
*/
|
|
|
|
protected parseAppFromUrl(_url : string)
|
|
|
|
{
|
|
|
|
let _app = null;
|
|
|
|
|
|
|
|
// Check the menuaction parts from the url
|
|
|
|
let matches = _url.match(/menuaction=([a-z0-9_-]+)\./i) ||
|
|
|
|
// Check the url for a scheme of "/app/something.php"
|
|
|
|
_url.match(/\/([^\/]+)\/[^\/]+\.php/i);
|
|
|
|
if(matches)
|
|
|
|
{
|
|
|
|
// check if this is a regular app-name
|
|
|
|
_app = this.applicationList.find(a => a.name == matches[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print
|
|
|
|
*/
|
|
|
|
public async print()
|
|
|
|
{
|
2024-05-27 18:49:06 +02:00
|
|
|
const appElement : EgwFrameworkApp = this.activeApp;
|
2024-05-14 16:17:06 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(appElement)
|
|
|
|
{
|
|
|
|
await appElement.print();
|
|
|
|
}
|
|
|
|
const appWindow = this.egw.window;
|
|
|
|
appWindow.setTimeout(appWindow.print, 0);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
// Ignore rejected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async setSidebox(appname, sideboxData, hash)
|
|
|
|
{
|
|
|
|
const app = this.loadApp(appname);
|
|
|
|
app.setSidebox(sideboxData, hash);
|
|
|
|
}
|
|
|
|
|
2024-07-09 19:43:45 +02:00
|
|
|
/**
|
|
|
|
* Show a message, with an optional type
|
|
|
|
*
|
|
|
|
* @param {string} message
|
|
|
|
* @param {"" | "help" | "info" | "error" | "warning" | "success"} type
|
|
|
|
* @param {number} duration The length of time, seconds, the alert will show before closing itself. Success
|
|
|
|
* messages are shown for 5s, other messages require manual closing by the user.
|
|
|
|
* @param {boolean} closable=true Message can be closed by the user
|
|
|
|
* @param {string} _discardID unique string id (appname:id) in order to register
|
|
|
|
* the message as discardable. Discardable messages offer a checkbox to never be shown again.
|
|
|
|
* If no appname given, the id will be prefixed with current app. The discardID will be stored in local storage.
|
|
|
|
* @returns {Promise<SlAlert>} SlAlert element
|
|
|
|
*/
|
|
|
|
public async message(message : string, type : "" | "help" | "info" | "error" | "warning" | "success" = "", duration : null | number = null, closable = true, _discardID : null | string = null)
|
|
|
|
{
|
|
|
|
if(message && !type)
|
|
|
|
{
|
|
|
|
const error_reg_exp = new RegExp('(error|' + egw.lang('error') + ')', 'i');
|
|
|
|
type = message.match(error_reg_exp) ? 'error' : 'success';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not add a same message twice if it's still not dismissed
|
|
|
|
const hash = await this.egw.hashString(message);
|
|
|
|
if(typeof this._messages[hash] !== "undefined")
|
|
|
|
{
|
|
|
|
return this._messages[hash];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Already discarded, just stop
|
|
|
|
if(_discardID && EgwFrameworkMessage.isDiscarded(_discardID))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const attributes = {
|
|
|
|
type: type,
|
|
|
|
closable: closable,
|
|
|
|
duration: duration * 1000,
|
|
|
|
discard: _discardID,
|
|
|
|
message: message,
|
|
|
|
"data-hash": hash
|
|
|
|
}
|
|
|
|
if(!duration)
|
|
|
|
{
|
|
|
|
delete attributes.duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
const alert = Object.assign(document.createElement("egw-message"), attributes);
|
|
|
|
alert.addEventListener("sl-hide", (e) =>
|
|
|
|
{
|
|
|
|
delete this._messages[e.target["data-hash"] ?? ""];
|
|
|
|
});
|
|
|
|
this._messages[hash] = alert;
|
|
|
|
document.body.append(alert);
|
|
|
|
await alert.updateComplete;
|
|
|
|
|
|
|
|
alert.toast();
|
|
|
|
|
|
|
|
return alert;
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:32:23 +02:00
|
|
|
protected getBaseUrl() {return "";}
|
|
|
|
|
2024-04-26 00:05:14 +02:00
|
|
|
/**
|
|
|
|
* An application tab is chosen, show the app
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @protected
|
|
|
|
*/
|
2024-05-08 16:32:23 +02:00
|
|
|
protected handleApplicationTabShow(event)
|
2024-06-11 17:03:04 +02:00
|
|
|
{
|
|
|
|
// Create & show app
|
|
|
|
this.showTab(event.target.activeTab.panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public showTab(appname)
|
2024-04-26 00:05:14 +02:00
|
|
|
{
|
2024-05-08 16:32:23 +02:00
|
|
|
this.querySelectorAll("egw-app").forEach(app => app.removeAttribute("active"));
|
|
|
|
|
|
|
|
let appComponent = this.querySelector(`egw-app#${appname}`);
|
|
|
|
if(!appComponent)
|
|
|
|
{
|
|
|
|
appComponent = this.loadApp(appname);
|
|
|
|
}
|
|
|
|
appComponent.setAttribute("active", "");
|
|
|
|
|
|
|
|
// Update the list on the server
|
2024-06-11 01:33:05 +02:00
|
|
|
const tabGroup : SlTabGroup = this.shadowRoot.querySelector("sl-tab-group.egw_fw__open_applications");
|
|
|
|
tabGroup.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.updateTabs(appComponent);
|
|
|
|
});
|
2024-05-08 16:32:23 +02:00
|
|
|
}
|
2024-04-26 00:05:14 +02:00
|
|
|
|
2024-05-08 16:32:23 +02:00
|
|
|
/**
|
|
|
|
* An application tab is closed
|
|
|
|
*/
|
|
|
|
protected handleApplicationTabClose(event)
|
|
|
|
{
|
|
|
|
const tabGroup : SlTabGroup = this.shadowRoot.querySelector("sl-tab-group.egw_fw__open_applications");
|
|
|
|
const tab = event.target;
|
|
|
|
const panel = tabGroup.querySelector(`sl-tab-panel[name="${tab.panel}"]`);
|
|
|
|
|
|
|
|
// Show the previous tab if the tab is currently active
|
|
|
|
if(tab.active)
|
|
|
|
{
|
|
|
|
tabGroup.show(tab.previousElementSibling.panel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Show will update, but closing in the background we call directly
|
2024-06-11 01:33:05 +02:00
|
|
|
tabGroup.updateComplete.then(() =>
|
|
|
|
{
|
|
|
|
this.updateTabs(tabGroup.querySelector("sl-tab[active]"));
|
|
|
|
});
|
2024-05-08 16:32:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the tab + panel
|
|
|
|
tab.remove();
|
2024-05-27 18:49:06 +02:00
|
|
|
if(panel)
|
|
|
|
{
|
|
|
|
panel.remove();
|
|
|
|
}
|
2024-05-08 16:32:23 +02:00
|
|
|
}
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
/**
|
|
|
|
* Store last status of tabs
|
|
|
|
* tab status being used in order to open all previous opened
|
|
|
|
* tabs and to activate the last active tab
|
|
|
|
*/
|
2024-05-08 16:32:23 +02:00
|
|
|
private updateTabs(activeTab)
|
|
|
|
{
|
2024-05-29 00:14:52 +02:00
|
|
|
//Send the current tab list to the server
|
|
|
|
let data = this.assembleTabList(activeTab);
|
|
|
|
|
2024-06-11 01:33:05 +02:00
|
|
|
// Update session tabs
|
|
|
|
let tabs = {};
|
|
|
|
Object.keys(this.tabApps).forEach((t) =>
|
|
|
|
{
|
|
|
|
if(data.some(d => d.appName == t))
|
|
|
|
{
|
|
|
|
tabs[t] = this.tabApps[t];
|
|
|
|
tabs[t].active = t == activeTab.id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.tabApps = tabs;
|
|
|
|
|
|
|
|
|
2024-05-29 00:14:52 +02:00
|
|
|
//Serialize the tab list and check whether it really has changed since the last
|
|
|
|
//submit
|
|
|
|
var serialized = egw.jsonEncode(data);
|
|
|
|
if(serialized != this.serializedTabState)
|
|
|
|
{
|
|
|
|
this.serializedTabState = serialized;
|
|
|
|
if(this.tabApps)
|
|
|
|
{
|
|
|
|
this._setTabAppsSession(this.tabApps);
|
|
|
|
}
|
|
|
|
egw.jsonq('EGroupware\\Api\\Framework\\Ajax::ajax_tab_changed_state', [data]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private assembleTabList(activeTab)
|
|
|
|
{
|
|
|
|
let appList = []
|
2024-05-08 16:32:23 +02:00
|
|
|
Array.from(this.shadowRoot.querySelectorAll("sl-tab-group.egw_fw__open_applications sl-tab")).forEach((tab : SlTab) =>
|
|
|
|
{
|
2024-06-11 01:33:05 +02:00
|
|
|
appList.push({appName: tab.panel, active: activeTab.id == tab.panel})
|
2024-05-08 16:32:23 +02:00
|
|
|
});
|
2024-05-29 00:14:52 +02:00
|
|
|
return appList;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _setTabAppsSession(_tabApps)
|
|
|
|
{
|
|
|
|
if(_tabApps)
|
|
|
|
{
|
|
|
|
egw.setSessionItem('api', 'fw_tab_apps', JSON.stringify(_tabApps));
|
|
|
|
}
|
2024-04-26 00:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders one application into the 9-dots application menu
|
|
|
|
*
|
|
|
|
* @param app
|
|
|
|
* @returns {TemplateResult<1>}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected _applicationListAppTemplate(app)
|
|
|
|
{
|
2024-05-08 21:46:09 +02:00
|
|
|
if(app.status !== "1")
|
|
|
|
{
|
|
|
|
return nothing;
|
|
|
|
}
|
|
|
|
|
2024-04-26 00:05:14 +02:00
|
|
|
return html`
|
|
|
|
<sl-tooltip placement="bottom" role="menuitem" content="${app.title}">
|
|
|
|
<et2-button-icon src="${app.icon}" aria-label="${app.title}" role="menuitem" noSubmit
|
2024-05-08 21:46:09 +02:00
|
|
|
helptext="${app.title}"
|
|
|
|
@click=${() =>
|
|
|
|
{
|
|
|
|
this.loadApp(app.name, true);
|
|
|
|
(<SlDropdown>this.shadowRoot.querySelector(".egw_fw__app_list")).hide();
|
|
|
|
}}
|
|
|
|
></et2-button-icon>
|
2024-04-26 00:05:14 +02:00
|
|
|
</sl-tooltip>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected _applicationTabTemplate(app)
|
|
|
|
{
|
|
|
|
return html`
|
2024-05-08 21:46:09 +02:00
|
|
|
<sl-tab slot="nav" panel="${app.name}" closable aria-label="${app.title}" ?active=${app.active}>
|
2024-04-26 00:05:14 +02:00
|
|
|
<sl-tooltip placement="bottom" content="${app.title}" hoist>
|
|
|
|
<et2-image src="${app.icon}"></et2-image>
|
|
|
|
</sl-tooltip>
|
|
|
|
</sl-tab>`;
|
|
|
|
}
|
|
|
|
|
2024-04-25 19:35:34 +02:00
|
|
|
render()
|
|
|
|
{
|
2024-04-26 00:05:14 +02:00
|
|
|
const iconSize = getComputedStyle(this).getPropertyValue("--icon-size");
|
|
|
|
const statusPosition = this.egw?.preference("statusPosition", "common") ?? parseInt(iconSize) ?? "36";
|
2024-04-25 19:35:34 +02:00
|
|
|
|
|
|
|
const classes = {
|
|
|
|
"egw_fw__base": true
|
|
|
|
}
|
|
|
|
classes[`egw_fw__layout-${this.layout}`] = true;
|
|
|
|
|
2024-05-30 23:19:21 +02:00
|
|
|
return html`${until(this.getEgwComplete().then(() => html`
|
2024-04-25 19:35:34 +02:00
|
|
|
<div class=${classMap(classes)} part="base">
|
|
|
|
<div class="egw_fw__banner" part="banner" role="banner">
|
|
|
|
<slot name="banner"><span class="placeholder">Banner</span></slot>
|
|
|
|
</div>
|
|
|
|
<header class="egw_fw__header" part="header">
|
|
|
|
<slot name="logo"></slot>
|
2024-04-26 00:05:14 +02:00
|
|
|
<sl-dropdown class="egw_fw__app_list" role="menu">
|
2024-04-25 19:35:34 +02:00
|
|
|
<sl-icon-button slot="trigger" name="grid-3x3-gap"
|
|
|
|
label="${this.egw.lang("Application list")}"
|
|
|
|
aria-description="${this.egw.lang("Activate for a list of applications")}"
|
|
|
|
></sl-icon-button>
|
2024-04-26 00:05:14 +02:00
|
|
|
${repeat(this.applicationList, (app) => this._applicationListAppTemplate(app))}
|
2024-04-25 19:35:34 +02:00
|
|
|
</sl-dropdown>
|
2024-04-26 00:05:14 +02:00
|
|
|
<sl-tab-group part="open-applications" class="egw_fw__open_applications" activation="manual"
|
|
|
|
role="tablist"
|
2024-05-08 16:32:23 +02:00
|
|
|
@sl-tab-show=${this.handleApplicationTabShow}
|
|
|
|
@sl-close=${this.handleApplicationTabClose}
|
|
|
|
>
|
2024-05-29 00:14:52 +02:00
|
|
|
${repeat([...this.applicationList, ...Object.values(this.tabApps)]
|
2024-05-27 22:28:10 +02:00
|
|
|
.filter(app => typeof app.opened !== "undefined" && app.status !== "5")
|
2024-05-08 21:46:09 +02:00
|
|
|
.sort((a, b) => a.opened - b.opened), (app) => this._applicationTabTemplate(app))}
|
2024-04-26 00:05:14 +02:00
|
|
|
</sl-tab-group>
|
2024-04-25 19:35:34 +02:00
|
|
|
<slot name="header"><span class="placeholder">header</span></slot>
|
|
|
|
<slot name="header-right"><span class="placeholder">header-right</span></slot>
|
|
|
|
</header>
|
|
|
|
<div class="egw_fw__divider">
|
|
|
|
<sl-split-panel part="status-split" position-in-pixels="${statusPosition}" primary="end"
|
2024-04-26 00:05:14 +02:00
|
|
|
snap="150px ${iconSize} 0px"
|
|
|
|
snap-threshold="${Math.min(40, parseInt(iconSize) - 5)}"
|
2024-04-25 19:35:34 +02:00
|
|
|
aria-label="Side menu resize">
|
2024-04-26 18:13:24 +02:00
|
|
|
<main slot="start" part="main" class="egw_fw__main">
|
2024-04-25 19:35:34 +02:00
|
|
|
<slot></slot>
|
|
|
|
</main>
|
|
|
|
<sl-icon slot="divider" name="grip-vertical"></sl-icon>
|
|
|
|
<aside slot="end" class="egw_fw__status" part="status">
|
|
|
|
<slot name="status"><span class="placeholder">status</span></slot>
|
|
|
|
</aside>
|
|
|
|
</sl-split-panel>
|
|
|
|
</div>
|
|
|
|
<footer class="egw_fw__footer" part="footer">
|
|
|
|
<slot name="footer"><span class="placeholder">footer</span></slot>
|
|
|
|
</footer>
|
|
|
|
</div>
|
2024-05-30 23:19:21 +02:00
|
|
|
`), html`<span>Waiting for egw...</span>
|
|
|
|
<slot></slot>`)}`;
|
2024-04-25 19:35:34 +02:00
|
|
|
}
|
2024-05-29 00:14:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Information we keep and use about each app on the client side
|
|
|
|
* This might not be limited to actual EGw apps,
|
|
|
|
*/
|
|
|
|
export interface ApplicationInfo
|
|
|
|
{
|
|
|
|
/* Internal name, used for reference & indexing. Might not be an egw app, might have extra bits */
|
|
|
|
name : string,
|
|
|
|
/* Must be an egw app, used for the EgwFrameworkApp, preferences, etc. */
|
|
|
|
internalName? : string,
|
|
|
|
icon : string
|
|
|
|
title : string,
|
|
|
|
url : string,
|
|
|
|
/* What type of application (1: normal, 5: loaded but no tab) */
|
|
|
|
status : string,// = "1",
|
|
|
|
/* Is the app open, and at what place in the tab list */
|
|
|
|
opened? : number,
|
|
|
|
/* Is the app currently active */
|
|
|
|
active? : boolean// = false
|
2024-04-25 19:35:34 +02:00
|
|
|
}
|