2022-01-19 21:17:07 +01:00
|
|
|
/**
|
2022-03-10 19:19:57 +01:00
|
|
|
* EGroupware eTemplate2 - Account-selection WebComponent
|
2022-01-19 21:17:07 +01:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @link https://www.egroupware.org
|
2022-03-10 19:19:57 +01:00
|
|
|
* @author Ralf Becker <rb@egroupware.org>
|
2022-01-19 21:17:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
import {Et2Select} from "./Et2Select";
|
2022-12-19 20:00:50 +01:00
|
|
|
import {cleanSelectOptions, SelectOption} from "./FindSelectOptions";
|
2022-06-16 00:43:39 +02:00
|
|
|
import {Et2Image} from "../Et2Image/Et2Image";
|
2022-12-09 21:16:44 +01:00
|
|
|
import {SelectAccountMixin} from "./SelectAccountMixin";
|
2022-12-15 18:22:19 +01:00
|
|
|
import {Et2StaticSelectMixin} from "./StaticOptions";
|
2023-01-27 18:34:40 +01:00
|
|
|
import {html, nothing} from "@lion/core";
|
2022-01-19 21:17:07 +01:00
|
|
|
|
2022-03-10 19:19:57 +01:00
|
|
|
export type AccountType = 'accounts'|'groups'|'both'|'owngroups';
|
2022-01-19 21:17:07 +01:00
|
|
|
|
2022-03-10 19:19:57 +01:00
|
|
|
/**
|
|
|
|
* @customElement et2-select-account
|
|
|
|
*/
|
2022-12-15 18:22:19 +01:00
|
|
|
export class Et2SelectAccount extends SelectAccountMixin(Et2StaticSelectMixin(Et2Select))
|
2022-01-19 21:17:07 +01:00
|
|
|
{
|
2022-03-10 19:19:57 +01:00
|
|
|
static get properties()
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
...super.properties,
|
|
|
|
/**
|
|
|
|
* One of: 'accounts','groups','both','owngroups'
|
|
|
|
*/
|
2022-07-21 17:57:50 +02:00
|
|
|
accountType: String,
|
2022-03-10 19:19:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2022-10-04 23:49:07 +02:00
|
|
|
// all types can search the server. If there are a lot of accounts, local list will
|
|
|
|
// not be complete
|
|
|
|
if(this.egw().preference('account_selection', 'common') !== 'none')
|
2022-08-09 10:47:57 +02:00
|
|
|
{
|
|
|
|
this.searchUrl = "EGroupware\\Api\\Etemplate\\Widget\\Taglist::ajax_search";
|
|
|
|
}
|
2022-10-04 23:49:07 +02:00
|
|
|
|
|
|
|
this.searchOptions = {type: 'account', account_type: 'accounts'};
|
2022-07-21 17:57:50 +02:00
|
|
|
this.__accountType = 'accounts';
|
2022-03-10 19:19:57 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 18:22:19 +01:00
|
|
|
connectedCallback()
|
|
|
|
{
|
|
|
|
super.connectedCallback();
|
|
|
|
|
|
|
|
// Start fetch of select_options
|
|
|
|
const type = this.egw().preference('account_selection', 'common');
|
|
|
|
let fetch = [];
|
|
|
|
// for primary_group we only display owngroups == own memberships, not other groups
|
|
|
|
if(type === 'primary_group' && this.accountType !== 'accounts')
|
|
|
|
{
|
|
|
|
if(this.accountType === 'both')
|
|
|
|
{
|
2022-12-19 20:00:50 +01:00
|
|
|
fetch.push(this.egw().accounts('accounts').then(options => {this.static_options = this.static_options.concat(cleanSelectOptions(options))}));
|
2022-12-15 18:22:19 +01:00
|
|
|
}
|
|
|
|
|
2022-12-19 20:00:50 +01:00
|
|
|
fetch.push(this.egw().accounts('owngroups').then(options => {this.static_options = this.static_options.concat(cleanSelectOptions(options))}));
|
2022-12-15 18:22:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-19 20:00:50 +01:00
|
|
|
fetch.push(this.egw().accounts(this.accountType).then(options => {this.static_options = this.static_options.concat(cleanSelectOptions(options))}));
|
2022-12-15 18:22:19 +01:00
|
|
|
}
|
|
|
|
this.fetchComplete = Promise.all(fetch)
|
2022-12-16 19:48:12 +01:00
|
|
|
.then(() => this._renderOptions());
|
2022-12-15 18:22:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-15 18:30:30 +02:00
|
|
|
firstUpdated(changedProperties?)
|
|
|
|
{
|
|
|
|
super.firstUpdated(changedProperties);
|
|
|
|
// Due to the different way Et2SelectAccount handles options, we call this explicitly
|
|
|
|
this._renderOptions();
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
set accountType(type : AccountType)
|
2022-03-10 19:19:57 +01:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
this.__accountType = type;
|
2022-08-09 10:47:57 +02:00
|
|
|
this.searchOptions.account_type = type;
|
2022-03-10 19:19:57 +01:00
|
|
|
|
2022-03-16 21:36:23 +01:00
|
|
|
super.select_options = this.select_options;
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:57:50 +02:00
|
|
|
get accountType() : AccountType
|
2022-03-16 21:36:23 +01:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
return this.__accountType;
|
2022-03-10 19:19:57 +01:00
|
|
|
}
|
2022-01-19 21:17:07 +01:00
|
|
|
|
2022-03-10 19:19:57 +01:00
|
|
|
/**
|
|
|
|
* Get account info for select options from common client-side account cache
|
|
|
|
*/
|
2022-03-16 21:36:23 +01:00
|
|
|
get select_options() : Array<SelectOption>
|
2022-03-10 19:19:57 +01:00
|
|
|
{
|
|
|
|
const type = this.egw().preference('account_selection', 'common');
|
2022-06-10 18:42:37 +02:00
|
|
|
if(type === 'none' && typeof this.egw().user('apps').admin === 'undefined')
|
2022-03-10 19:19:57 +01:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2022-12-12 21:10:53 +01:00
|
|
|
let select_options : Array<SelectOption> = [...super.select_options] || [];
|
2022-12-15 18:22:19 +01:00
|
|
|
|
2022-09-01 16:30:43 +02:00
|
|
|
return select_options.filter((value, index, self) =>
|
|
|
|
{
|
|
|
|
return self.findIndex(v => v.value === value.value) === index;
|
|
|
|
});
|
2022-03-10 19:19:57 +01:00
|
|
|
}
|
2022-06-10 18:42:37 +02:00
|
|
|
|
|
|
|
set select_options(new_options : SelectOption[])
|
|
|
|
{
|
|
|
|
super.select_options = new_options;
|
|
|
|
}
|
2022-06-15 01:29:58 +02:00
|
|
|
|
2023-01-27 18:34:40 +01:00
|
|
|
/**
|
|
|
|
* Override icon for the select option
|
|
|
|
*
|
|
|
|
* @param option
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
protected _iconTemplate(option)
|
|
|
|
{
|
|
|
|
// lavatar uses a size property, not a CSS variable
|
|
|
|
let style = getComputedStyle(this);
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<et2-lavatar slot="prefix" part="icon" .size=${style.getPropertyValue("--icon-width")}
|
|
|
|
lname=${option.lname || nothing}
|
|
|
|
fname=${option.fname || nothing}
|
|
|
|
image=${option.icon || nothing}
|
|
|
|
>
|
|
|
|
</et2-lavatar>`;
|
|
|
|
}
|
|
|
|
|
2022-06-15 01:29:58 +02:00
|
|
|
/**
|
|
|
|
* Override the prefix image for tags (multiple=true)
|
|
|
|
* The default is probably fine, but we're being explicit here.
|
|
|
|
* @param item
|
|
|
|
* @returns {TemplateResult<1>}
|
|
|
|
* @protected
|
|
|
|
*
|
|
|
|
*/
|
2022-06-16 00:43:39 +02:00
|
|
|
protected _createImage(item) : Et2Image
|
2022-06-15 01:29:58 +02:00
|
|
|
{
|
2023-01-27 18:34:40 +01:00
|
|
|
const image = document.createElement("et2-lavatar");
|
|
|
|
image.contactId = item.value;
|
|
|
|
if(item.lname)
|
2022-11-21 17:16:38 +01:00
|
|
|
{
|
2023-01-27 18:34:40 +01:00
|
|
|
image.lname = item.lname;
|
2022-11-21 17:16:38 +01:00
|
|
|
}
|
2023-01-27 18:34:40 +01:00
|
|
|
if(item.fname)
|
|
|
|
{
|
|
|
|
image.fname = item.fname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's an actual image associated with the account, use that image instead of initials
|
|
|
|
if(item.src)
|
|
|
|
{
|
|
|
|
image.src = item.src;
|
|
|
|
}
|
|
|
|
|
2022-06-16 00:43:39 +02:00
|
|
|
return image;
|
2022-06-15 01:29:58 +02:00
|
|
|
}
|
2022-01-19 21:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-select-account", Et2SelectAccount);
|