2022-06-22 23:47:28 +02:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - Select Country 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";
|
|
|
|
import {Et2StaticSelectMixin, StaticOptions as so} from "../StaticOptions";
|
|
|
|
import {egw} from "../../../jsapi/egw_global";
|
|
|
|
import {SelectOption} from "../FindSelectOptions";
|
2023-09-19 23:20:36 +02:00
|
|
|
import {html} from "lit";
|
2022-06-22 23:47:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Customised Select widget for countries
|
|
|
|
* This widget uses CSS from api/templates/default/css/flags.css to set flags
|
|
|
|
*/
|
2022-06-23 07:19:47 +02:00
|
|
|
egw(window).includeCSS("api/templates/default/css/flags.css")
|
2022-06-22 23:47:28 +02:00
|
|
|
|
2022-07-15 20:56:24 +02:00
|
|
|
export class Et2SelectCountry extends Et2StaticSelectMixin(Et2Select)
|
2022-06-22 23:47:28 +02:00
|
|
|
{
|
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/* Reflect the value so we can use CSS selectors */
|
|
|
|
value: {type: String, reflect: true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.search = true;
|
|
|
|
|
|
|
|
(<Promise<SelectOption[]>>so.country(this, {}, true)).then(options =>
|
|
|
|
{
|
2023-09-13 19:55:33 +02:00
|
|
|
this._static_options = options
|
2022-07-15 20:56:24 +02:00
|
|
|
this.requestUpdate("select_options");
|
2022-06-22 23:47:28 +02:00
|
|
|
});
|
|
|
|
}
|
2022-08-26 19:48:02 +02:00
|
|
|
|
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
2023-09-19 23:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the element for the flag
|
|
|
|
*
|
|
|
|
* @param option
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected _iconTemplate(option)
|
|
|
|
{
|
|
|
|
return html`
|
|
|
|
<span slot="prefix" part="flag country_${option.value}_flag"
|
|
|
|
style="width: var(--icon-width)">
|
|
|
|
</span>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to render each option into the select
|
|
|
|
* Override to get flags in
|
|
|
|
*
|
|
|
|
* @param {SelectOption} option
|
|
|
|
* @returns {TemplateResult}
|
|
|
|
*
|
|
|
|
protected _optionTemplate(option : SelectOption) : TemplateResult
|
|
|
|
{
|
|
|
|
// Exclude non-matches when searching
|
|
|
|
if(typeof option.isMatch == "boolean" && !option.isMatch)
|
|
|
|
{
|
|
|
|
return html``;
|
|
|
|
}
|
2022-08-26 19:48:02 +02:00
|
|
|
|
2023-09-19 23:20:36 +02:00
|
|
|
return html`
|
|
|
|
<sl-option
|
|
|
|
part="option"
|
|
|
|
value="${value}"
|
|
|
|
title="${!option.title || this.noLang ? option.title : this.egw().lang(option.title)}"
|
|
|
|
class="${option.class}" .option=${option}
|
|
|
|
.selected=${this.getValueAsArray().some(v => v == value)}
|
|
|
|
?disabled=${option.disabled}
|
|
|
|
>
|
|
|
|
${this._iconTemplate(option)}
|
|
|
|
${this.noLang ? option.label : this.egw().lang(option.label)}
|
|
|
|
</sl-option>`;
|
2022-08-26 19:48:02 +02:00
|
|
|
}
|
2023-09-19 23:20:36 +02:00
|
|
|
*/
|
2022-06-22 23:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-select-country", Et2SelectCountry);
|