2022-07-19 00:34:58 +02:00
|
|
|
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
|
2024-07-12 00:36:27 +02:00
|
|
|
import {css, html, LitElement, nothing} from "lit";
|
2022-07-19 00:34:58 +02:00
|
|
|
import {Et2LinkAppSelect} from "./Et2LinkAppSelect";
|
|
|
|
import {LinkInfo} from "./Et2Link";
|
|
|
|
import {Et2Button} from "../Et2Button/Et2Button";
|
2024-07-12 00:36:27 +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";
|
2022-07-19 00:34:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find and select a single entry using the link system.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2024-07-12 00:36:27 +02:00
|
|
|
@customElement("et2-link-add")
|
2024-05-07 22:46:44 +02:00
|
|
|
export class Et2LinkAdd extends Et2InputWidget(LitElement)
|
2022-07-19 00:34:58 +02:00
|
|
|
{
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
2024-07-12 00:36:27 +02:00
|
|
|
.form-control {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.form-control-input {
|
|
|
|
display: flex;
|
|
|
|
flex: 1 1 auto;
|
|
|
|
position: relative;
|
|
|
|
max-width: 100%;
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:36:27 +02:00
|
|
|
/**
|
|
|
|
* Either an array of LinkInfo (defined in Et2Link.ts) or array with keys to_app and to_id
|
|
|
|
*/
|
|
|
|
@property({type: Object})
|
|
|
|
value : LinkInfo[] & { to_app : string, to_id : string }
|
|
|
|
/**
|
|
|
|
* Limit to the listed applications (comma seperated)
|
|
|
|
*/
|
|
|
|
@property()
|
|
|
|
applicationList : string
|
2022-07-19 00:34:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {LinkInfo}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private _value : LinkInfo;
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.handleButtonClick = this.handleButtonClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:36:27 +02:00
|
|
|
/**
|
|
|
|
* Limit to just this application - hides app selection
|
|
|
|
*/
|
|
|
|
@property()
|
2022-07-19 00:34:58 +02:00
|
|
|
set application(app)
|
|
|
|
{
|
|
|
|
app = app || "";
|
|
|
|
|
|
|
|
// If initial value got set before only_app, it still needs app in pre-render value
|
2024-07-12 00:36:27 +02:00
|
|
|
if(this.value && app)
|
2022-07-19 00:34:58 +02:00
|
|
|
{
|
2024-07-12 00:36:27 +02:00
|
|
|
this.value.app = app;
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
2024-07-12 00:36:27 +02:00
|
|
|
this.requestUpdate("application")
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get application()
|
|
|
|
{
|
2024-07-12 00:36:27 +02:00
|
|
|
return this.value.app;
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get _appNode() : Et2LinkAppSelect
|
|
|
|
{
|
2024-07-12 00:36:27 +02:00
|
|
|
return this.shadowRoot.querySelector("et2-link-apps");
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get _buttonNode() : Et2Button
|
|
|
|
{
|
2024-07-12 00:36:27 +02:00
|
|
|
return this.shadowRoot.querySelector("et2-button");
|
2022-07-19 00:34:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add button was clicked
|
|
|
|
* @param {MouseEvent} e
|
|
|
|
*/
|
|
|
|
handleButtonClick(e : MouseEvent)
|
|
|
|
{
|
|
|
|
this.egw().open(this.value.to_app + ":" + this.value.to_id, this._appNode.value, 'add');
|
|
|
|
}
|
|
|
|
|
2024-07-12 00:36:27 +02:00
|
|
|
render()
|
|
|
|
{
|
|
|
|
const hasLabel = this.label ? true : false;
|
|
|
|
const hasHelpText = this.helpText ? true : false;
|
|
|
|
const isEditable = !(this.disabled || this.readonly);
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="form-control"
|
|
|
|
class=${classMap({
|
|
|
|
'link-add': true,
|
|
|
|
'link-add__readonly': !isEditable,
|
|
|
|
'vlink-add__disabled': this.disabled,
|
|
|
|
'form-control': true,
|
|
|
|
'form-control--medium': true,
|
|
|
|
'form-control--has-label': hasLabel,
|
|
|
|
'form-control--has-help-text': hasHelpText
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<label
|
|
|
|
id="label"
|
|
|
|
part="form-control-label"
|
|
|
|
class="form-control__label"
|
|
|
|
aria-hidden=${hasLabel ? 'false' : 'true'}
|
|
|
|
>
|
|
|
|
<slot name="label">${this.label}</slot>
|
|
|
|
</label>
|
|
|
|
<div part="form-control-input" class="form-control-input">
|
|
|
|
<slot part="prefix" name="prefix"></slot>
|
|
|
|
<et2-link-apps
|
|
|
|
onlyApp=${this.application || nothing}
|
|
|
|
applicationList=${this.applicationList || nothing}
|
|
|
|
?disabled=${this.disabled}
|
|
|
|
?readonly=${this.readonly}
|
|
|
|
.value=${this.value?.app}
|
|
|
|
></et2-link-apps>
|
|
|
|
<et2-button
|
|
|
|
id=${this.id + "_add"}
|
|
|
|
image="add"
|
|
|
|
aria-label=${this.egw().lang("Add entry")}
|
|
|
|
?disabled=${this.disabled}
|
|
|
|
?readonly=${this.readonly}
|
|
|
|
noSubmit
|
|
|
|
@click=${this.handleButtonClick}
|
|
|
|
></et2-button>
|
|
|
|
<slot part="suffix" name="suffix"></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|