2022-03-17 20:06:29 +01:00
|
|
|
import {css, html, ifDefined, LitElement, repeat, SlotMixin} from '@lion/core';
|
2022-03-15 00:06:42 +01:00
|
|
|
import {DialogButton, Et2Dialog} from "./Et2Dialog";
|
2022-03-16 20:53:50 +01:00
|
|
|
import {et2_template} from "../et2_widget_template";
|
|
|
|
import {Et2DialogContent} from "./Et2DialogContent";
|
2022-08-18 22:46:44 +02:00
|
|
|
import shoelace from "../Styles/shoelace";
|
2022-03-15 00:06:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This handles the visible portion of the dialog, including the title & close button.
|
|
|
|
*
|
2022-03-16 20:53:50 +01:00
|
|
|
* Note we can't extend Et2Widget. If I try, something in the render / creation breaks and calling open() gives an
|
|
|
|
* error with modal: true
|
2022-03-15 00:06:42 +01:00
|
|
|
*/
|
2022-03-16 20:53:50 +01:00
|
|
|
export class Et2DialogOverlay extends SlotMixin(LitElement)
|
2022-03-15 00:06:42 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
protected buttons : DialogButton[];
|
|
|
|
|
|
|
|
protected _dialog : Et2Dialog;
|
|
|
|
|
|
|
|
|
2022-03-28 19:28:40 +02:00
|
|
|
/**
|
|
|
|
* I don't know what's going on with styles here, but if we define Et2DialogOverlay.styles it breaks
|
|
|
|
* dialog display in Firefox.
|
|
|
|
* The styles are added in render(), which is bad from a performance standpoint, but good in that it works.
|
|
|
|
*/
|
|
|
|
static get _styles()
|
2022-03-15 00:06:42 +01:00
|
|
|
{
|
2022-08-18 22:46:44 +02:00
|
|
|
return [shoelace,
|
|
|
|
css`
|
2022-03-15 00:06:42 +01:00
|
|
|
:host {
|
|
|
|
display: inline-block;
|
|
|
|
background: white;
|
|
|
|
position: relative;
|
|
|
|
border: 1px solid silver;
|
2022-03-21 21:51:43 +01:00
|
|
|
box-shadow: -2px 1px 9px 3px #b4b4b4;
|
2022-05-20 19:40:14 +02:00
|
|
|
min-width: 250px;
|
|
|
|
touch-action: none;
|
|
|
|
box-sizing: border-box;
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
:host([hidden]) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2022-03-16 20:53:50 +01:00
|
|
|
.overlay {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2022-05-20 19:40:14 +02:00
|
|
|
height: 100%;
|
2022-03-16 20:53:50 +01:00
|
|
|
}
|
2022-03-15 00:06:42 +01:00
|
|
|
.overlay__header {
|
|
|
|
display: flex;
|
2022-03-23 21:50:00 +01:00
|
|
|
border-bottom: 1px inset;
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.overlay__heading {
|
|
|
|
margin: 0px;
|
2022-03-23 21:50:00 +01:00
|
|
|
padding: 6px 10px 0px;
|
2022-03-15 00:06:42 +01:00
|
|
|
flex: 1;
|
2022-03-23 21:50:00 +01:00
|
|
|
font-size: 130%;
|
2022-03-21 21:51:43 +01:00
|
|
|
font-weight: 400;
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
2022-03-16 20:53:50 +01:00
|
|
|
#overlay-content-node-wrapper {
|
|
|
|
flex: 1 1 auto;
|
2022-03-21 15:43:53 +01:00
|
|
|
padding: 10px;
|
2022-03-16 20:53:50 +01:00
|
|
|
}
|
2022-03-15 00:06:42 +01:00
|
|
|
|
|
|
|
.overlay__heading > .overlay__close-button {
|
|
|
|
flex: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.overlay__close-button {
|
2022-03-21 21:51:43 +01:00
|
|
|
min-width: 24px;
|
|
|
|
min-height: 24px;
|
2022-03-15 00:06:42 +01:00
|
|
|
border-width: 0;
|
|
|
|
padding: 0;
|
|
|
|
font-size: 24px;
|
|
|
|
}
|
2022-03-15 21:10:53 +01:00
|
|
|
#overlay-content-buttons {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: stretch;
|
|
|
|
gap: 5px;
|
2022-03-21 21:51:43 +01:00
|
|
|
border-top: 1px solid silver;
|
|
|
|
margin-top: 0.5em;
|
|
|
|
padding: 5px;
|
2022-03-15 21:10:53 +01:00
|
|
|
}
|
2022-03-22 22:49:42 +01:00
|
|
|
/* Override style for legacy nextmatch action dialogs */
|
|
|
|
::slotted([slot="content"]) {
|
|
|
|
display: block !important;
|
|
|
|
position: relative !important;
|
|
|
|
inset: initial !important;
|
|
|
|
}
|
2022-03-15 21:10:53 +01:00
|
|
|
::slotted([slot="buttons"]) {
|
|
|
|
flex: 1 0 auto;
|
|
|
|
}
|
|
|
|
::slotted([align="right"]) {
|
|
|
|
margin-left: auto;
|
|
|
|
order: 1;
|
2022-08-18 22:46:44 +02:00
|
|
|
}`];
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
|
|
|
|
2022-03-16 20:53:50 +01:00
|
|
|
get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
// Allow to force size, otherwise it sizes to contents
|
|
|
|
width: Number,
|
|
|
|
height: Number,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 00:06:42 +01:00
|
|
|
get slots()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.slots,
|
|
|
|
buttons: () =>
|
|
|
|
{
|
|
|
|
return this._buttonsTemplate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.buttons = [];
|
|
|
|
}
|
|
|
|
|
2022-03-15 21:10:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Need to wait for Overlay
|
|
|
|
async getUpdateComplete()
|
|
|
|
{
|
2022-03-16 20:53:50 +01:00
|
|
|
let result = await super.getUpdateComplete();
|
2022-03-21 15:43:53 +01:00
|
|
|
if(this._contentNode && this._contentNode instanceof LitElement)
|
2022-03-16 20:53:50 +01:00
|
|
|
{
|
2022-03-21 15:43:53 +01:00
|
|
|
await (<LitElement>this._contentNode).updateComplete;
|
2022-03-16 20:53:50 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
// Need to wait for Overlay
|
|
|
|
this.updateComplete
|
|
|
|
.then(async() =>
|
|
|
|
{
|
2022-03-21 15:43:53 +01:00
|
|
|
if(this._contentNode && this._contentNode instanceof LitElement)
|
2022-03-16 20:53:50 +01:00
|
|
|
{
|
|
|
|
// Re-do render to get proper images
|
|
|
|
this._contentNode.requestUpdate();
|
|
|
|
|
2022-03-21 15:43:53 +01:00
|
|
|
await this._contentNode.updateComplete;
|
2022-03-16 20:53:50 +01:00
|
|
|
}
|
|
|
|
});
|
2022-03-15 21:10:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
egw() : IegwAppLocal
|
|
|
|
{
|
|
|
|
if(this._dialog)
|
|
|
|
{
|
|
|
|
return this._dialog.egw();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return egw();
|
|
|
|
}
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Block until after the paint - This is needed to deal with children not fully "done" before the OverlayController
|
|
|
|
* tries to do things with them
|
|
|
|
*
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
*/
|
|
|
|
async performUpdate()
|
|
|
|
{
|
|
|
|
await new Promise((resolve) => setTimeout(() => resolve()));
|
|
|
|
return super.performUpdate();
|
|
|
|
}
|
|
|
|
|
2022-03-16 20:53:50 +01:00
|
|
|
get _contentNode() : Et2DialogContent | et2_template
|
2022-03-15 21:10:53 +01:00
|
|
|
{
|
2022-03-16 20:53:50 +01:00
|
|
|
// @ts-ignore
|
2022-03-15 21:10:53 +01:00
|
|
|
return this.querySelector("[slot='content']");
|
|
|
|
}
|
|
|
|
|
2022-03-15 00:06:42 +01:00
|
|
|
/** @private */
|
|
|
|
__dispatchCloseEvent()
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event('close-overlay'));
|
|
|
|
}
|
|
|
|
|
|
|
|
render()
|
|
|
|
{
|
2022-03-16 20:53:50 +01:00
|
|
|
// This style is just for this dialog
|
2022-03-28 19:28:40 +02:00
|
|
|
let styles = [Et2DialogOverlay._styles];
|
2022-03-16 20:53:50 +01:00
|
|
|
|
2022-03-28 19:28:40 +02:00
|
|
|
if(this.width && Number.isInteger(this.width))
|
|
|
|
{
|
|
|
|
styles.push(css`.overlay {width: ${this.width}px}`);
|
|
|
|
}
|
|
|
|
if(this.height && Number.isInteger(this.height))
|
|
|
|
{
|
|
|
|
styles.push(css`.overlay {height: ${this.height}px}`);
|
|
|
|
}
|
2022-03-15 00:06:42 +01:00
|
|
|
return html`
|
2022-03-28 19:28:40 +02:00
|
|
|
<style>${styles}</style>
|
2022-03-15 00:06:42 +01:00
|
|
|
<div class="overlay">
|
|
|
|
<div class="overlay__header">
|
|
|
|
<h1 class="overlay__heading">
|
|
|
|
<slot name="heading"></slot>
|
|
|
|
</h1>
|
|
|
|
<slot name="header"></slot>
|
2022-04-29 14:28:32 +02:00
|
|
|
${this._closeButtonTemplate()}
|
2022-03-15 00:06:42 +01:00
|
|
|
</div>
|
|
|
|
<div id="overlay-content-node-wrapper">
|
|
|
|
<slot name="content"></slot>
|
|
|
|
</div>
|
|
|
|
<div id="overlay-content-buttons">
|
|
|
|
<slot name="buttons"></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-04-29 14:28:32 +02:00
|
|
|
_closeButtonTemplate()
|
|
|
|
{
|
|
|
|
if (this._dialog.noCloseButton)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return html`<button
|
|
|
|
@click="${this.__dispatchCloseEvent}"
|
|
|
|
id="close-button"
|
|
|
|
title="${this.egw().lang("Close")}"
|
|
|
|
aria-label="${this.egw().lang("Close dialog")}"
|
|
|
|
class="overlay__close-button"
|
|
|
|
>
|
|
|
|
<slot name="close-icon">×</slot>
|
|
|
|
</button>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-03-15 00:06:42 +01:00
|
|
|
_buttonsTemplate()
|
|
|
|
{
|
2022-03-22 22:49:42 +01:00
|
|
|
if(!this.buttons)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-15 21:10:53 +01:00
|
|
|
// Set button._parent here, otherwise button will have trouble finding our egw()
|
|
|
|
return html`${repeat(this.buttons, (button : DialogButton) => button.id, (button, index) =>
|
|
|
|
{
|
|
|
|
return html`
|
2022-03-17 20:06:29 +01:00
|
|
|
<et2-button ._parent=${this} id=${button.id} button_id=${button.button_id}
|
2022-03-17 22:21:15 +01:00
|
|
|
label=${button.label}
|
2022-03-17 20:06:29 +01:00
|
|
|
.image=${ifDefined(button.image)}
|
2022-04-06 23:08:18 +02:00
|
|
|
.noSubmit=${true}
|
2022-07-04 22:19:16 +02:00
|
|
|
?disabled=${button.disabled}
|
2022-03-17 22:21:15 +01:00
|
|
|
align=${ifDefined(button.align)}>
|
2022-03-15 21:10:53 +01:00
|
|
|
</et2-button>
|
|
|
|
`
|
|
|
|
})}`;
|
2022-03-15 00:06:42 +01:00
|
|
|
}
|
2022-07-04 22:19:16 +02:00
|
|
|
}
|