2022-06-17 21:07:33 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Image selection WebComponent
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
*/
|
|
|
|
|
2023-09-13 19:55:33 +02:00
|
|
|
import {Et2Select} from "../Et2Select";
|
2023-12-06 18:33:14 +01:00
|
|
|
import {css, html, TemplateResult} from "lit";
|
2023-09-13 19:55:33 +02:00
|
|
|
import {SelectOption} from "../FindSelectOptions";
|
2023-12-06 18:33:14 +01:00
|
|
|
import {SlOption} from "@shoelace-style/shoelace";
|
2022-06-17 21:07:33 +02:00
|
|
|
|
|
|
|
export class Et2SelectThumbnail extends Et2Select
|
|
|
|
{
|
|
|
|
static get styles()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
...super.styles,
|
|
|
|
css`
|
|
|
|
|
|
|
|
/* Hide selected options from the dropdown */
|
|
|
|
::slotted([checked])
|
|
|
|
{
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
/* Hide dropdown icon */
|
2024-10-21 22:57:10 +02:00
|
|
|
|
|
|
|
::part(expand-icon), .expand-icon {
|
2022-06-17 21:07:33 +02:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(...args : any[])
|
|
|
|
{
|
|
|
|
super(...args);
|
|
|
|
this.search = false;
|
|
|
|
this.allowFreeEntries = true;
|
|
|
|
this.editModeEnabled = true;
|
|
|
|
this.multiple = true;
|
|
|
|
this.pill = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an entry that is not in the options and add it to the value
|
|
|
|
* Overridden here to set the icon as the text, since this is a thumbnail
|
|
|
|
*
|
|
|
|
* @param {string} text Used as both value and label
|
|
|
|
*/
|
|
|
|
public createFreeEntry(text : string) : boolean
|
|
|
|
{
|
|
|
|
if(!this.validateFreeEntry(text))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Make sure not to double-add
|
|
|
|
if(!this.select_options.find(o => o.value == text))
|
|
|
|
{
|
2022-12-09 17:03:43 +01:00
|
|
|
this.__select_options.push(<SelectOption>{
|
2022-06-17 21:07:33 +02:00
|
|
|
value: text,
|
|
|
|
label: "",
|
|
|
|
icon: text
|
|
|
|
});
|
|
|
|
this.requestUpdate('select_options');
|
|
|
|
}
|
2023-12-06 18:33:14 +01:00
|
|
|
this.requestUpdate();
|
2022-06-17 21:07:33 +02:00
|
|
|
|
|
|
|
// Make sure not to double-add
|
|
|
|
if(this.multiple && this.value.indexOf(text) == -1)
|
|
|
|
{
|
|
|
|
this.value.push(text);
|
|
|
|
}
|
|
|
|
else if(!this.multiple)
|
|
|
|
{
|
|
|
|
this.value = text;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
get tagTag() : string
|
|
|
|
{
|
|
|
|
return "et2-thumbnail-tag";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-06 18:33:14 +01:00
|
|
|
* Custom tag
|
2022-06-17 21:07:33 +02:00
|
|
|
*
|
2023-12-06 18:33:14 +01:00
|
|
|
* Override this to customise display when multiple=true.
|
|
|
|
* There is no restriction on the tag used, unlike _optionTemplate()
|
|
|
|
*
|
|
|
|
* @param {Et2Option} option
|
|
|
|
* @param {number} index
|
|
|
|
* @returns {TemplateResult}
|
2022-06-17 21:07:33 +02:00
|
|
|
* @protected
|
|
|
|
*/
|
2023-12-06 18:33:14 +01:00
|
|
|
protected _tagTemplate(option : SlOption, index : number) : TemplateResult
|
2022-06-17 21:07:33 +02:00
|
|
|
{
|
|
|
|
// Different image - slot in just an image so we can have complete control over styling
|
2023-12-06 18:33:14 +01:00
|
|
|
return html`
|
2024-10-21 22:57:10 +02:00
|
|
|
<et2-thumbnail-tag
|
|
|
|
?removable=${this.multiple && !this.readonly}
|
|
|
|
>
|
2023-12-06 18:33:14 +01:00
|
|
|
<img
|
|
|
|
part="image"
|
|
|
|
slot="prefix"
|
|
|
|
src="${option.value}"
|
|
|
|
/>
|
|
|
|
</et2-thumbnail-tag>
|
|
|
|
`;
|
2022-06-17 21:07:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-select-thumbnail", Et2SelectThumbnail);
|