2022-06-30 17:38:14 +02:00
|
|
|
import {cleanSelectOptions, SelectOption} from "../Et2Select/FindSelectOptions";
|
2022-05-27 22:12:31 +02:00
|
|
|
import {css, html, SlotMixin, TemplateResult} from "@lion/core";
|
2022-05-26 22:47:52 +02:00
|
|
|
import {Et2Select} from "../Et2Select/Et2Select";
|
|
|
|
|
|
|
|
|
2022-05-27 22:12:31 +02:00
|
|
|
export class Et2LinkAppSelect extends SlotMixin(Et2Select)
|
2022-05-26 22:47:52 +02:00
|
|
|
{
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
|
|
|
:host {
|
|
|
|
--icon-width: 20px;
|
2022-05-27 22:12:31 +02:00
|
|
|
display: inline-block;
|
2022-05-31 21:40:31 +02:00
|
|
|
min-width: 64px;
|
2022-05-27 22:12:31 +02:00
|
|
|
}
|
2022-07-21 17:57:50 +02:00
|
|
|
:host([appIcons]) {
|
2022-05-27 22:12:31 +02:00
|
|
|
max-width: 75px;
|
|
|
|
}
|
|
|
|
.select__menu {
|
|
|
|
overflow-x: hidden;
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
::part(control) {
|
|
|
|
border: none;
|
|
|
|
box-shadow: initial;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit to just this one application, and hide the selection
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
onlyApp: {type: String},
|
2022-05-26 22:47:52 +02:00
|
|
|
/**
|
|
|
|
* Limit to these applications (comma seperated).
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
applicationList: {type: String},
|
2022-05-26 22:47:52 +02:00
|
|
|
/**
|
|
|
|
* Show application icons instead of application names
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
appIcons: {type: Boolean, reflect: true}
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
get slots()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.slots,
|
2022-05-27 22:12:31 +02:00
|
|
|
"": () =>
|
2022-05-26 22:47:52 +02:00
|
|
|
{
|
2022-05-27 22:12:31 +02:00
|
|
|
|
2022-05-26 22:47:52 +02:00
|
|
|
const icon = document.createElement("et2-image");
|
|
|
|
icon.setAttribute("slot", "prefix");
|
|
|
|
icon.setAttribute("src", "api/navbar");
|
|
|
|
icon.style.width = "var(--icon-width)";
|
2022-08-16 11:38:08 +02:00
|
|
|
icon.style.height = "var(--icon-width)";
|
2022-05-27 22:12:31 +02:00
|
|
|
return icon;
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
protected __applicationList : string[];
|
|
|
|
protected __onlyApp : string;
|
2022-05-26 22:47:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
2022-07-21 17:57:50 +02:00
|
|
|
this.onlyApp = "";
|
|
|
|
this.appIcons = true;
|
|
|
|
this.applicationList = [];
|
2022-05-27 22:22:15 +02:00
|
|
|
this.hoist = true;
|
2022-05-26 22:47:52 +02:00
|
|
|
|
|
|
|
// Select options are based off abilities registered with link system
|
|
|
|
this._reset_select_options();
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
set onlyApp(app : string)
|
2022-06-01 16:05:34 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
this.__onlyApp = app || "";
|
2022-06-06 21:31:33 +02:00
|
|
|
this.updateComplete.then(() =>
|
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
this.style.display = this.onlyApp ? 'none' : '';
|
2022-06-06 21:31:33 +02:00
|
|
|
});
|
2022-06-01 16:05:34 +02:00
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
get onlyApp() : string
|
2022-06-01 16:05:34 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
// __onlyApp may be undefined during creation
|
|
|
|
return this.__onlyApp || "";
|
2022-06-01 16:05:34 +02:00
|
|
|
}
|
|
|
|
|
2022-05-26 22:47:52 +02:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
|
|
|
|
// Set icon
|
2023-01-25 23:14:14 +01:00
|
|
|
this.querySelector(":scope > [slot='prefix']").setAttribute("src", this.egw().link_get_registry(this.value, 'icon') ?? this.value + "/navbar");
|
2022-05-26 22:47:52 +02:00
|
|
|
|
2022-07-07 17:54:18 +02:00
|
|
|
if(!this.value)
|
|
|
|
{
|
|
|
|
// use preference
|
|
|
|
let appname = "";
|
2022-08-16 10:10:36 +02:00
|
|
|
if(typeof this.value != 'undefined' && this.parentNode && this.parentNode.toApp)
|
2022-07-07 17:54:18 +02:00
|
|
|
{
|
2022-08-16 10:10:36 +02:00
|
|
|
appname = this.parentNode.toApp;
|
2022-07-07 17:54:18 +02:00
|
|
|
}
|
|
|
|
this.value = this.egw().preference('link_app', appname || this.egw().app_name());
|
|
|
|
}
|
2022-05-26 22:47:52 +02:00
|
|
|
// Register to
|
2022-05-27 23:39:51 +02:00
|
|
|
this.addEventListener("change", this._handleChange);
|
2022-06-01 16:05:34 +02:00
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
if(this.__onlyApp)
|
2022-07-07 17:54:18 +02:00
|
|
|
{
|
|
|
|
this.style.display = 'none';
|
|
|
|
}
|
2022-05-27 23:39:51 +02:00
|
|
|
}
|
2022-05-26 22:47:52 +02:00
|
|
|
|
2022-05-27 23:39:51 +02:00
|
|
|
disconnectedCallback()
|
|
|
|
{
|
|
|
|
super.disconnectedCallback();
|
|
|
|
this.removeEventListener("change", this._handleChange);
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before update() to compute values needed during the update
|
|
|
|
*
|
|
|
|
* @param changedProperties
|
|
|
|
*/
|
|
|
|
willUpdate(changedProperties)
|
|
|
|
{
|
|
|
|
super.willUpdate(changedProperties);
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
if(changedProperties.has("onlyApp") || changedProperties.has("applicationList"))
|
2022-05-26 22:47:52 +02:00
|
|
|
{
|
|
|
|
this._reset_select_options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
set applicationList(app_list : string[])
|
2022-05-31 21:40:31 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
let oldValue = this.__applicationList;
|
2022-05-31 21:40:31 +02:00
|
|
|
if(typeof app_list == "string")
|
|
|
|
{
|
|
|
|
app_list = (<string>app_list).split(",");
|
|
|
|
}
|
2022-07-21 17:57:50 +02:00
|
|
|
this.__applicationList = app_list;
|
|
|
|
this.requestUpdate("applicationList", oldValue);
|
2022-05-31 21:40:31 +02:00
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
get applicationList() : string[]
|
2022-05-31 21:40:31 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
return this.__applicationList;
|
2022-05-31 21:40:31 +02:00
|
|
|
}
|
|
|
|
|
2022-07-07 17:54:18 +02:00
|
|
|
get value() : string
|
2022-06-01 17:42:50 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
return this.onlyApp ? this.onlyApp : <string>super.value;
|
2022-06-01 17:42:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set value(new_value)
|
|
|
|
{
|
|
|
|
super.value = new_value;
|
|
|
|
}
|
|
|
|
|
2022-09-06 19:11:13 +02:00
|
|
|
_handleChange(e)
|
2022-05-27 23:39:51 +02:00
|
|
|
{
|
|
|
|
// Set icon
|
2023-01-25 23:14:14 +01:00
|
|
|
this.querySelector(":scope > [slot='prefix']").setAttribute("src", this.egw().link_get_registry(this.value, 'icon'));
|
2022-05-27 23:39:51 +02:00
|
|
|
|
|
|
|
// update preference
|
|
|
|
let appname = "";
|
2022-08-16 10:10:36 +02:00
|
|
|
if(typeof this.value != 'undefined' && this.parentNode && this.parentNode.toApp)
|
2022-05-27 23:39:51 +02:00
|
|
|
{
|
2022-08-16 10:10:36 +02:00
|
|
|
appname = this.parentNode.toApp;
|
2022-05-27 23:39:51 +02:00
|
|
|
}
|
|
|
|
this.egw().set_preference(appname || this.egw().app_name(), 'link_app', this.value);
|
|
|
|
}
|
|
|
|
|
2022-05-26 22:47:52 +02:00
|
|
|
/**
|
|
|
|
* Limited select options here
|
|
|
|
* This method will check properties and set select options appropriately
|
|
|
|
*/
|
|
|
|
private _reset_select_options()
|
|
|
|
{
|
|
|
|
let select_options = [];
|
|
|
|
|
|
|
|
// Limit to one app
|
2022-07-21 17:57:50 +02:00
|
|
|
if(this.onlyApp)
|
2022-05-26 22:47:52 +02:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
select_options.push({value: this.onlyApp, label: this.egw().lang(this.onlyApp)});
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
2022-07-21 17:57:50 +02:00
|
|
|
else if(this.applicationList.length > 0)
|
2022-05-26 22:47:52 +02:00
|
|
|
{
|
2022-08-03 23:30:22 +02:00
|
|
|
select_options = this.applicationList.map((app) =>
|
|
|
|
{
|
|
|
|
return {value: app, label: this.egw().lang(app)};
|
|
|
|
});
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//@ts-ignore link_app_list gives {app:name} instead of an array, but parent will fix it
|
|
|
|
select_options = this.egw().link_app_list('query');
|
|
|
|
if(typeof select_options['addressbook-email'] !== 'undefined')
|
|
|
|
{
|
|
|
|
delete select_options['addressbook-email'];
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 17:06:55 +02:00
|
|
|
if (!this.value)
|
|
|
|
{
|
|
|
|
this.value = <string>this.egw().preference('link_app', this.egw().app_name());
|
|
|
|
}
|
2022-06-30 17:38:14 +02:00
|
|
|
this.select_options = cleanSelectOptions(select_options);
|
2022-05-26 22:47:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_optionTemplate(option : SelectOption) : TemplateResult
|
|
|
|
{
|
|
|
|
return html`
|
|
|
|
<sl-menu-item value="${option.value}" title="${option.title}">
|
2022-07-21 17:57:50 +02:00
|
|
|
${this.appIcons ? "" : option.label}
|
2022-05-26 22:47:52 +02:00
|
|
|
${this._iconTemplate(option.value)}
|
|
|
|
</sl-menu-item>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
_iconTemplate(appname)
|
|
|
|
{
|
2023-01-25 23:14:14 +01:00
|
|
|
let url = appname ? this.egw().link_get_registry(appname, 'icon') : "";
|
2022-05-26 22:47:52 +02:00
|
|
|
return html`
|
|
|
|
<et2-image style="width: var(--icon-width)" slot="prefix" src="${url}"></et2-image>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-link-apps", Et2LinkAppSelect);
|