2022-01-04 23:38:10 +01:00
|
|
|
/**
|
2022-03-01 12:35:33 +01:00
|
|
|
* EGroupware eTemplate2 - Select WebComponent
|
2022-01-04 23:38:10 +01:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2022-03-03 18:38:56 +01:00
|
|
|
import {css, html, PropertyValues, TemplateResult} from "@lion/core";
|
2022-01-13 23:28:52 +01:00
|
|
|
import {StaticOptions} from "./StaticOptions";
|
2022-03-01 12:35:33 +01:00
|
|
|
import {Et2widgetWithSelectMixin} from "./Et2WidgetWithSelectMixin";
|
|
|
|
import {SelectOption} from "./FindSelectOptions";
|
2022-03-12 13:49:25 +01:00
|
|
|
import {Et2InvokerMixin} from "../Et2Url/Et2InvokerMixin";
|
2022-06-16 00:43:39 +02:00
|
|
|
import {SlMenuItem, SlSelect} from "@shoelace-style/shoelace";
|
2022-05-27 22:12:31 +02:00
|
|
|
import {egw} from "../../jsapi/egw_global";
|
|
|
|
import shoelace from "../Styles/shoelace";
|
2022-05-31 01:05:00 +02:00
|
|
|
import {Et2WithSearchMixin} from "./SearchMixin";
|
2022-06-16 00:43:39 +02:00
|
|
|
import {Et2Tag} from "./Tag/Et2Tag";
|
2022-01-04 23:38:10 +01:00
|
|
|
|
2022-03-01 13:31:13 +01:00
|
|
|
// export Et2WidgetWithSelect which is used as type in other modules
|
2022-05-27 22:12:31 +02:00
|
|
|
export class Et2WidgetWithSelect extends Et2widgetWithSelectMixin(SlSelect)
|
|
|
|
{
|
|
|
|
};
|
2022-03-01 13:31:13 +01:00
|
|
|
|
2022-06-10 18:25:31 +02:00
|
|
|
// @ts-ignore SlSelect styles is a single CSSResult, not an array, so TS complains
|
2022-05-31 01:05:00 +02:00
|
|
|
export class Et2Select extends Et2WithSearchMixin(Et2InvokerMixin(Et2WidgetWithSelect))
|
2022-01-04 23:38:10 +01:00
|
|
|
{
|
2022-01-13 23:28:52 +01:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
2022-06-10 18:25:31 +02:00
|
|
|
// Parent (SlSelect) returns a single cssResult, not an array
|
|
|
|
super.styles,
|
2022-05-27 22:12:31 +02:00
|
|
|
shoelace,
|
2022-01-13 23:28:52 +01:00
|
|
|
css`
|
|
|
|
:host {
|
2022-04-22 21:07:22 +02:00
|
|
|
display: block;
|
2022-06-10 22:11:57 +02:00
|
|
|
--icon-width: 20px;
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
2022-03-12 13:49:25 +01:00
|
|
|
|
2022-06-10 22:11:57 +02:00
|
|
|
|
|
|
|
::slotted(img), img {
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:43:39 +02:00
|
|
|
/* Get rid of padding before/after options */
|
|
|
|
sl-menu::part(base) {
|
|
|
|
padding: 0px;
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:11:57 +02:00
|
|
|
/* Avoid double scrollbar if there are a lot of options */
|
|
|
|
.select__menu
|
|
|
|
{
|
|
|
|
max-height: initial;
|
|
|
|
}
|
2022-01-04 23:38:10 +01:00
|
|
|
|
2022-06-16 00:43:39 +02:00
|
|
|
/** multiple=true uses tags for each value **/
|
|
|
|
/* styling for icon inside tag (not option) */
|
|
|
|
.tag_image {
|
|
|
|
margin-right: var(--sl-spacing-x-small);
|
|
|
|
}
|
|
|
|
/* Maximum height + scrollbar on tags (+ other styling) */
|
|
|
|
.select__tags {
|
|
|
|
max-height: 5em;
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
|
|
gap: 0.1rem 0.5rem;
|
|
|
|
}
|
|
|
|
/* Keep overflow tag right-aligned. It's the only sl-tag. */
|
|
|
|
.select__tags sl-tag {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
select:hover {
|
|
|
|
box-shadow: 1px 1px 1px rgb(0 0 0 / 60%);
|
|
|
|
}`
|
|
|
|
];
|
|
|
|
}
|
2022-01-04 23:38:10 +01:00
|
|
|
|
2022-05-27 23:39:51 +02:00
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* Toggle between single and multiple selection
|
|
|
|
*/
|
|
|
|
multiple: {
|
|
|
|
type: Boolean,
|
|
|
|
reflect: true,
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Add a button to switch to multiple with given number of rows
|
|
|
|
*/
|
|
|
|
expand_multiple_rows: {
|
|
|
|
type: Number,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 23:28:52 +01:00
|
|
|
get slots()
|
2022-01-04 23:38:10 +01:00
|
|
|
{
|
2022-01-13 23:28:52 +01:00
|
|
|
return {
|
|
|
|
...super.slots,
|
|
|
|
input: () =>
|
|
|
|
{
|
|
|
|
return document.createElement("select");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 18:25:31 +02:00
|
|
|
constructor(...args : any[])
|
2022-05-27 23:39:51 +02:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
this._triggerChange = this._triggerChange.bind(this);
|
2022-06-14 23:14:17 +02:00
|
|
|
this._doResize = this._doResize.bind(this);
|
2022-05-27 23:39:51 +02:00
|
|
|
}
|
|
|
|
|
2022-01-13 23:28:52 +01:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
2022-05-27 23:39:51 +02:00
|
|
|
|
|
|
|
this.getUpdateComplete().then(() =>
|
|
|
|
{
|
|
|
|
this.addEventListener("sl-clear", this._triggerChange)
|
2022-06-07 00:41:29 +02:00
|
|
|
this.addEventListener("sl-change", this._triggerChange);
|
2022-06-14 23:14:17 +02:00
|
|
|
this.addEventListener("sl-after-show", this._doResize)
|
2022-05-27 23:39:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnectedCallback()
|
|
|
|
{
|
|
|
|
super.disconnectedCallback();
|
|
|
|
|
|
|
|
this.removeEventListener("sl-clear", this._triggerChange)
|
2022-06-08 22:01:00 +02:00
|
|
|
this.removeEventListener("sl-change", this._triggerChange);
|
2022-06-14 23:14:17 +02:00
|
|
|
this.removeEventListener("sl-after-show", this._doResize);
|
2022-04-01 19:12:19 +02:00
|
|
|
}
|
|
|
|
|
2022-06-10 18:25:31 +02:00
|
|
|
firstUpdated(changedProperties?)
|
2022-04-01 19:12:19 +02:00
|
|
|
{
|
|
|
|
super.firstUpdated(changedProperties);
|
2022-03-01 17:29:13 +01:00
|
|
|
|
2022-06-02 17:59:08 +02:00
|
|
|
// If no value is set, choose the first option
|
|
|
|
// Only do this on firstUpdated() otherwise it is impossible to clear the field
|
|
|
|
const valueArray = Array.isArray(this.value) ? this.value : (!this.value ? [] : this.value.toString().split(','));
|
2022-06-10 13:07:27 +02:00
|
|
|
// value not in options --> use empty_label, if exists, or first option otherwise
|
|
|
|
if(!this.multiple && this.select_options.length > 0 && this.select_options.filter((option) => valueArray.find(val => val == option.value)).length === 0)
|
2022-03-01 17:29:13 +01:00
|
|
|
{
|
2022-06-10 13:07:27 +02:00
|
|
|
this.value = this.empty_label ? "" : "" + this.select_options[0]?.value; // ""+ to cast value of 0 to "0", to not replace with ""
|
2022-03-01 17:29:13 +01:00
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
|
|
|
|
2022-05-27 23:39:51 +02:00
|
|
|
_triggerChange(e)
|
|
|
|
{
|
|
|
|
this.dispatchEvent(new Event("change"));
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:14:17 +02:00
|
|
|
/**
|
|
|
|
* Change the menu sizing to allow the menu to be wider than the field width, but no smaller
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
private _doResize(e)
|
|
|
|
{
|
|
|
|
this.menu.style.minWidth = this.menu.style.width;
|
|
|
|
this.menu.style.width = "";
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:38:56 +01:00
|
|
|
/**
|
|
|
|
* Get the node where we're putting the selection options
|
|
|
|
*
|
|
|
|
* @returns {HTMLElement}
|
|
|
|
*/
|
|
|
|
get _optionTargetNode() : HTMLElement
|
|
|
|
{
|
2022-05-27 22:12:31 +02:00
|
|
|
return <HTMLElement><unknown>this;
|
2022-03-03 18:38:56 +01:00
|
|
|
}
|
|
|
|
|
2022-03-12 13:49:25 +01:00
|
|
|
/**
|
|
|
|
* @deprecated use this.multiple = multi
|
|
|
|
*
|
|
|
|
* @param multi
|
|
|
|
*/
|
2022-03-10 14:48:27 +01:00
|
|
|
set_multiple(multi)
|
|
|
|
{
|
2022-03-12 13:49:25 +01:00
|
|
|
this.multiple = multi;
|
|
|
|
}
|
|
|
|
|
2022-06-10 13:07:27 +02:00
|
|
|
set_value(val : string | string[] | number)
|
2022-03-14 20:13:47 +01:00
|
|
|
{
|
2022-06-10 13:07:27 +02:00
|
|
|
if (typeof val === 'number')
|
|
|
|
{
|
|
|
|
val = val.toString();
|
|
|
|
}
|
|
|
|
this.value = val || '';
|
2022-06-02 16:12:38 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 20:13:47 +01:00
|
|
|
/**
|
|
|
|
* Reimplemented to allow/keep string[] as value
|
|
|
|
*
|
|
|
|
* @param value string|string[]
|
|
|
|
*/
|
|
|
|
_callParser(value = this.formattedValue)
|
|
|
|
{
|
2022-05-27 23:39:51 +02:00
|
|
|
if(this.multiple && Array.isArray(value))
|
2022-03-14 20:13:47 +01:00
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return super._callParser(value);
|
|
|
|
}
|
|
|
|
|
2022-03-18 21:25:54 +01:00
|
|
|
private _set_invoker(rows)
|
|
|
|
{
|
|
|
|
this._invokerAction = () => {
|
|
|
|
this.multiple = true;
|
|
|
|
this._inputNode.size = parseInt(rows) || 4;
|
|
|
|
this._invokerNode.style.display = 'none';
|
|
|
|
}
|
|
|
|
this._invokerTitle = egw.lang('Switch to multiple');
|
|
|
|
this._invokerLabel = '+';
|
|
|
|
}
|
|
|
|
|
|
|
|
transformAttributes(attrs)
|
|
|
|
{
|
|
|
|
if (attrs.expand_multiple_rows)
|
|
|
|
{
|
|
|
|
this._set_invoker(attrs.expand_multiple_rows);
|
|
|
|
}
|
|
|
|
super.transformAttributes(attrs);
|
2022-06-17 19:41:29 +02:00
|
|
|
|
|
|
|
// Deal with initial value of multiple set as CSV
|
|
|
|
if(this.multiple && typeof this.value == "string")
|
|
|
|
{
|
|
|
|
this.value = this.value.length ? this.value.split(",") : [];
|
|
|
|
}
|
2022-03-18 21:25:54 +01:00
|
|
|
}
|
|
|
|
|
2022-03-12 13:49:25 +01:00
|
|
|
set expand_multiple_rows(rows)
|
|
|
|
{
|
|
|
|
if (rows && !this.multiple)
|
2022-03-10 14:48:27 +01:00
|
|
|
{
|
2022-03-18 21:25:54 +01:00
|
|
|
this._set_invoker(rows);
|
2022-03-12 13:49:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._invokerLabel = undefined;
|
|
|
|
}
|
2022-03-14 20:13:47 +01:00
|
|
|
this.__expand_multiple_rows = rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
get expand_multiple_rows()
|
|
|
|
{
|
|
|
|
return this.__expand_multiple_rows;
|
2022-03-12 13:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to check if invoker can be activated: not disabled, empty or invalid
|
|
|
|
*
|
|
|
|
* Overwritten to NOT disable if empty.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* */
|
|
|
|
_toggleInvokerDisabled()
|
|
|
|
{
|
|
|
|
if (this._invokerNode)
|
|
|
|
{
|
|
|
|
const invokerNode = /** @type {HTMLElement & {disabled: boolean}} */ (this._invokerNode);
|
|
|
|
invokerNode.disabled = this.disabled || this.hasFeedbackFor.length > 0;
|
2022-03-10 14:48:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 20:02:27 +01:00
|
|
|
/** @param {import('@lion/core').PropertyValues } changedProperties */
|
|
|
|
updated(changedProperties : PropertyValues)
|
2022-01-13 23:28:52 +01:00
|
|
|
{
|
2022-02-18 20:02:27 +01:00
|
|
|
super.updated(changedProperties);
|
2022-03-03 18:38:56 +01:00
|
|
|
|
|
|
|
if(changedProperties.has('select_options') || changedProperties.has("value") || changedProperties.has('empty_label'))
|
2022-01-04 23:38:10 +01:00
|
|
|
{
|
2022-02-18 20:02:27 +01:00
|
|
|
// Re-set value, the option for it may have just shown up
|
2022-05-27 22:12:31 +02:00
|
|
|
this.value = this.value || "";
|
2022-01-04 23:38:10 +01:00
|
|
|
}
|
2022-03-10 14:48:27 +01:00
|
|
|
|
|
|
|
// propagate multiple to selectbox
|
2022-06-16 00:43:39 +02:00
|
|
|
if(changedProperties.has('multiple'))
|
2022-03-10 14:48:27 +01:00
|
|
|
{
|
2022-03-12 13:49:25 +01:00
|
|
|
// switch the expand button off
|
2022-06-16 00:43:39 +02:00
|
|
|
if(this.multiple)
|
2022-03-12 13:49:25 +01:00
|
|
|
{
|
|
|
|
this.expand_multiple_rows = 0;
|
|
|
|
}
|
2022-03-10 14:48:27 +01:00
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 00:43:39 +02:00
|
|
|
/**
|
|
|
|
* Override this method from SlSelect to stick our own tags in there
|
|
|
|
*/
|
|
|
|
syncItemsFromValue()
|
|
|
|
{
|
|
|
|
if(typeof super.syncItemsFromValue === "function")
|
|
|
|
{
|
|
|
|
super.syncItemsFromValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only applies to multiple
|
|
|
|
if(typeof this.displayTags !== "object" || !this.multiple)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let overflow = null;
|
|
|
|
if(this.maxTagsVisible > 0 && this.displayTags.length > this.maxTagsVisible)
|
|
|
|
{
|
|
|
|
overflow = this.displayTags.pop();
|
|
|
|
}
|
|
|
|
const checkedItems = Object.values(this.menuItems).filter(item => this.value.includes(item.value));
|
|
|
|
this.displayTags = checkedItems.map(item => this._createTagNode(item));
|
|
|
|
|
|
|
|
// Re-slice & add overflow tag
|
|
|
|
if(overflow)
|
|
|
|
{
|
|
|
|
this.displayTags = this.displayTags.slice(0, this.maxTagsVisible);
|
|
|
|
this.displayTags.push(overflow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 23:28:52 +01:00
|
|
|
_emptyLabelTemplate() : TemplateResult
|
|
|
|
{
|
2022-05-31 01:05:00 +02:00
|
|
|
if(!this.empty_label || this.multiple)
|
2022-01-04 23:38:10 +01:00
|
|
|
{
|
2022-01-13 23:28:52 +01:00
|
|
|
return html``;
|
2022-01-04 23:38:10 +01:00
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
return html`
|
2022-05-27 22:12:31 +02:00
|
|
|
<sl-menu-item value="">${this.empty_label}</sl-menu-item>`;
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
2022-01-04 23:38:10 +01:00
|
|
|
|
2022-06-16 00:43:39 +02:00
|
|
|
/**
|
|
|
|
* Tag used for rendering options
|
|
|
|
* Used for finding & filtering options, they're created by the mixed-in class
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
public get optionTag()
|
|
|
|
{
|
|
|
|
return "sl-menu-item";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-13 23:28:52 +01:00
|
|
|
_optionTemplate(option : SelectOption) : TemplateResult
|
|
|
|
{
|
2022-05-27 22:12:31 +02:00
|
|
|
let icon = option.icon ? html`
|
2022-06-10 22:11:57 +02:00
|
|
|
<et2-image slot="prefix" part="icon" style="width: var(--icon-width)"
|
|
|
|
src="${option.icon}"></et2-image>` : "";
|
2022-05-27 22:12:31 +02:00
|
|
|
|
2022-06-16 19:02:16 +02:00
|
|
|
// Tag used must match this.optionTag, but you can't use the variable directly.
|
|
|
|
// Pass option along so SearchMixin can grab it if needed
|
2022-01-13 23:28:52 +01:00
|
|
|
return html`
|
2022-06-16 19:02:16 +02:00
|
|
|
<sl-menu-item value="${option.value}" title="${option.title}" class="${option.class}" .option=${option}>
|
2022-05-27 22:12:31 +02:00
|
|
|
${icon}
|
2022-02-18 20:02:27 +01:00
|
|
|
${option.label}
|
2022-05-27 22:12:31 +02:00
|
|
|
</sl-menu-item>`;
|
2022-01-04 23:38:10 +01:00
|
|
|
}
|
2022-06-16 00:43:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag used for rendering tags when multiple=true
|
|
|
|
* Used for creating, finding & filtering options.
|
|
|
|
* @see createTagNode()
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
public get tagTag()
|
|
|
|
{
|
|
|
|
return "et2-tag";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customise how tags are rendered. This overrides what SlSelect
|
|
|
|
* does in syncItemsFromValue().
|
|
|
|
* This is a copy+paste from SlSelect.syncItemsFromValue().
|
|
|
|
*
|
|
|
|
* @param item
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected _createTagNode(item)
|
|
|
|
{
|
|
|
|
const tag = <Et2Tag>document.createElement(this.tagTag);
|
|
|
|
tag.value = item.value;
|
|
|
|
tag.textContent = this.getItemLabel(item);
|
|
|
|
tag.class = item.classList.value + " search_tag";
|
|
|
|
tag.addEventListener("dblclick", this._handleDoubleClick);
|
|
|
|
tag.addEventListener("click", this.handleTagInteraction);
|
|
|
|
tag.addEventListener("keydown", this.handleTagInteraction);
|
|
|
|
tag.addEventListener("sl-remove", (event) =>
|
|
|
|
{
|
|
|
|
event.stopPropagation();
|
|
|
|
if(!this.disabled)
|
|
|
|
{
|
|
|
|
item.checked = false;
|
|
|
|
this.syncValueFromItems();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let image = this._createImage(item);
|
|
|
|
if(image)
|
|
|
|
{
|
|
|
|
tag.prepend(image);
|
|
|
|
}
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected _createImage(item)
|
|
|
|
{
|
|
|
|
let image = item.querySelector("et2-image");
|
|
|
|
if(image)
|
|
|
|
{
|
|
|
|
image = image.clone();
|
|
|
|
image.slot = "prefix";
|
|
|
|
image.class = "tag_image";
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public get menuItems() : HTMLElement[]
|
|
|
|
{
|
|
|
|
return [...this.querySelectorAll<SlMenuItem>(this.optionTag)];
|
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
2022-01-04 23:38:10 +01:00
|
|
|
|
2022-06-10 18:25:31 +02:00
|
|
|
customElements.define("et2-select", Et2Select);
|
2022-01-13 23:28:52 +01:00
|
|
|
/**
|
|
|
|
* Use a single StaticOptions, since it should have no state
|
|
|
|
* @type {StaticOptions}
|
|
|
|
*/
|
|
|
|
const so = new StaticOptions();
|
|
|
|
|
|
|
|
|
2022-01-17 23:12:46 +01:00
|
|
|
export class Et2SelectApp extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.app(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-app", Et2SelectApp);
|
|
|
|
|
|
|
|
export class Et2SelectBitwise extends Et2Select
|
|
|
|
{
|
|
|
|
set value(new_value)
|
|
|
|
{
|
|
|
|
let oldValue = this._value;
|
|
|
|
let expanded_value = [];
|
2022-03-16 21:36:23 +01:00
|
|
|
let options = this.select_options;
|
2022-01-17 23:12:46 +01:00
|
|
|
for(let index in options)
|
|
|
|
{
|
|
|
|
let right = parseInt(options[index].value);
|
|
|
|
if(!!(new_value & right))
|
|
|
|
{
|
|
|
|
expanded_value.push(right);
|
|
|
|
}
|
|
|
|
}
|
2022-05-27 22:12:31 +02:00
|
|
|
super.value = expanded_value;
|
2022-01-17 23:12:46 +01:00
|
|
|
|
|
|
|
this.requestUpdate("value", oldValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-bitwise", Et2SelectBitwise);
|
|
|
|
|
2022-01-13 23:28:52 +01:00
|
|
|
export class Et2SelectBool extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-13 23:28:52 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
2022-01-17 23:12:46 +01:00
|
|
|
|
2022-03-16 21:36:23 +01:00
|
|
|
this.select_options = so.bool(this);
|
|
|
|
}
|
2022-01-13 23:28:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-bool", Et2SelectBool);
|
|
|
|
|
2022-01-14 17:29:14 +01:00
|
|
|
export class Et2SelectCategory extends Et2Select
|
|
|
|
{
|
2022-06-07 00:09:08 +02:00
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
2022-06-16 00:43:39 +02:00
|
|
|
/* Category color on options */
|
|
|
|
::slotted(*) {
|
|
|
|
border-left: 3px solid var(--category-color, transparent);
|
|
|
|
}
|
|
|
|
.select--standard .select__control {
|
|
|
|
border-left: 4px solid transparent;
|
|
|
|
}
|
2022-06-07 00:09:08 +02:00
|
|
|
`
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* Include global categories
|
|
|
|
*/
|
|
|
|
global_categories: {type: Boolean},
|
|
|
|
/**
|
|
|
|
* Show categories from this application. If not set, will be the current application
|
|
|
|
*/
|
|
|
|
application: {type: String},
|
|
|
|
/**
|
|
|
|
* Show categories below this parent category
|
|
|
|
*/
|
|
|
|
parent_cat: {type: Number}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-14 17:29:14 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
2022-06-07 00:09:08 +02:00
|
|
|
this.select_options = so.cat(this);
|
2022-01-14 17:29:14 +01:00
|
|
|
}
|
2022-06-16 00:43:39 +02:00
|
|
|
|
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
|
|
|
|
if(typeof this.application == 'undefined')
|
|
|
|
{
|
|
|
|
this.application =
|
|
|
|
// When the widget is first created, it doesn't have a parent and can't find it's instanceManager
|
|
|
|
(this.getInstanceManager() && this.getInstanceManager().app) ||
|
|
|
|
this.egw().app_name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updated(changedProperties : PropertyValues)
|
|
|
|
{
|
|
|
|
super.updated(changedProperties);
|
|
|
|
|
|
|
|
if(changedProperties.has("value"))
|
|
|
|
{
|
|
|
|
this.doLabelChange()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doLabelChange()
|
|
|
|
{
|
|
|
|
// Update the display label when checked menu item's label changes
|
|
|
|
if(this.multiple)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const checkedItem = this.menuItems.find(item => item.value === this.value);
|
|
|
|
this.displayLabel = checkedItem ? checkedItem.textContent : '';
|
|
|
|
this.querySelector("[slot=prefix].tag_image")?.remove();
|
|
|
|
if(checkedItem)
|
|
|
|
{
|
|
|
|
let image = this._createImage(checkedItem)
|
|
|
|
if(image)
|
|
|
|
{
|
|
|
|
this.append(image);
|
|
|
|
}
|
|
|
|
this.dropdown.querySelector(".select__control").style.borderColor =
|
|
|
|
getComputedStyle(checkedItem).getPropertyValue("--category-color") || "transparent";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get tagTag() : string
|
|
|
|
{
|
|
|
|
return "et2-category-tag";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customise how tags are rendered. This overrides parent to set application
|
|
|
|
*
|
|
|
|
* @param item
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected _createTagNode(item)
|
|
|
|
{
|
|
|
|
let tag = super._createTagNode(item);
|
|
|
|
tag.application = this.application;
|
|
|
|
return tag;
|
|
|
|
}
|
2022-01-14 17:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-cat", Et2SelectCategory);
|
|
|
|
|
2022-01-17 23:12:46 +01:00
|
|
|
export class Et2SelectCountry extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.country(this, {});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-country", Et2SelectCountry);
|
|
|
|
|
|
|
|
export class Et2SelectDay extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.day(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-day", Et2SelectDay);
|
|
|
|
|
|
|
|
export class Et2SelectDayOfWeek extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.dow(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-dow", Et2SelectDayOfWeek);
|
|
|
|
|
|
|
|
export class Et2SelectHour extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.hour(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-hour", Et2SelectHour);
|
|
|
|
|
|
|
|
export class Et2SelectMonth extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.month(this);
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-month", Et2SelectMonth);
|
|
|
|
|
|
|
|
export class Et2SelectNumber extends Et2Select
|
|
|
|
{
|
2022-06-03 18:18:18 +02:00
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* Step between numbers
|
|
|
|
*/
|
|
|
|
interval: {type: Number},
|
|
|
|
min: {type: Number},
|
|
|
|
max: {type: Number},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add one or more leading zeros
|
|
|
|
* Set to how many zeros you want (000)
|
|
|
|
*/
|
|
|
|
leading_zero: {type: String},
|
|
|
|
/**
|
|
|
|
* Appended after every number
|
|
|
|
*/
|
|
|
|
suffix: {type: String}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
2022-06-03 18:18:18 +02:00
|
|
|
this.min = 1;
|
|
|
|
this.max = 10;
|
|
|
|
this.interval = 1;
|
|
|
|
this.leading_zero = "";
|
|
|
|
this.suffix = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
updated(changedProperties : PropertyValues)
|
|
|
|
{
|
|
|
|
super.updated(changedProperties);
|
2022-03-16 21:36:23 +01:00
|
|
|
|
2022-06-03 18:18:18 +02:00
|
|
|
if(changedProperties.has('min') || changedProperties.has('max') || changedProperties.has('interval') || changedProperties.has('suffix'))
|
|
|
|
{
|
|
|
|
this.select_options = so.number(this);
|
|
|
|
}
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-number", Et2SelectNumber);
|
|
|
|
|
2022-06-03 18:18:18 +02:00
|
|
|
export class Et2SelectPercent extends Et2SelectNumber
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.min = 0;
|
|
|
|
this.max = 100;
|
|
|
|
this.interval = 10;
|
|
|
|
this.suffix = "%%";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-percent", Et2SelectPercent);
|
|
|
|
|
2022-01-17 23:12:46 +01:00
|
|
|
export class Et2SelectPriority extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.priority(this);
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-priority", Et2SelectPriority);
|
|
|
|
|
|
|
|
export class Et2SelectState extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.state(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-state", Et2SelectState);
|
|
|
|
|
|
|
|
export class Et2SelectTimezone extends Et2Select
|
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.select_options = so.timezone(this, {other: this.other || []});
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
|
|
|
customElements.define("et2-select-timezone", Et2SelectTimezone);
|
|
|
|
|
2022-06-03 18:18:18 +02:00
|
|
|
export class Et2SelectYear extends Et2SelectNumber
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
constructor()
|
2022-01-17 23:12:46 +01:00
|
|
|
{
|
2022-03-16 21:36:23 +01:00
|
|
|
super();
|
2022-06-03 18:18:18 +02:00
|
|
|
this.min = -3;
|
|
|
|
this.max = 2;
|
|
|
|
}
|
2022-03-16 21:36:23 +01:00
|
|
|
|
2022-06-03 18:18:18 +02:00
|
|
|
updated(changedProperties : PropertyValues)
|
|
|
|
{
|
|
|
|
super.updated(changedProperties);
|
|
|
|
|
|
|
|
if(changedProperties.has('min') || changedProperties.has('max') || changedProperties.has('interval') || changedProperties.has('suffix'))
|
|
|
|
{
|
|
|
|
this.select_options = so.year(this);
|
|
|
|
}
|
2022-01-17 23:12:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
|
2022-02-21 19:58:56 +01:00
|
|
|
customElements.define("et2-select-year", Et2SelectYear);
|