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-03-10 19:19:57 +01:00
|
|
|
import {SelectOption} from "./FindSelectOptions";
|
2022-06-16 00:43:39 +02:00
|
|
|
import {Et2Image} from "../Et2Image/Et2Image";
|
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-01-19 21:17:07 +01:00
|
|
|
export class Et2SelectAccount extends Et2Select
|
|
|
|
{
|
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-08-09 10:47:57 +02:00
|
|
|
// currently only account_selection "Primary group and search" needs the search,
|
|
|
|
// all other types have the accounts fully local
|
|
|
|
if (this.egw().preference('account_selection', 'common') === 'primary_group')
|
|
|
|
{
|
|
|
|
this.searchUrl = "EGroupware\\Api\\Etemplate\\Widget\\Taglist::ajax_search";
|
|
|
|
}
|
|
|
|
else // always allow local search
|
|
|
|
{
|
|
|
|
this.search = true;
|
|
|
|
}
|
|
|
|
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-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-07-29 09:22:25 +02:00
|
|
|
let select_options : Array<SelectOption> = [];
|
2022-03-10 19:19:57 +01:00
|
|
|
// for primary_group we only display owngroups == own memberships, not other groups
|
2022-07-21 17:57:50 +02:00
|
|
|
if (type === 'primary_group' && this.accountType !== 'accounts')
|
2022-03-10 19:19:57 +01:00
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
if (this.accountType === 'both')
|
2022-03-10 19:19:57 +01:00
|
|
|
{
|
|
|
|
select_options = this.egw().accounts('accounts');
|
|
|
|
}
|
|
|
|
select_options = select_options.concat(this.egw().accounts('owngroups'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-21 17:57:50 +02:00
|
|
|
select_options = this.egw().accounts(this.accountType);
|
2022-03-10 19:19:57 +01:00
|
|
|
}
|
2022-07-27 11:46:45 +02:00
|
|
|
// egw.accounts returns value as number, causing the et2-select to not match the option
|
|
|
|
select_options.forEach(option => {
|
|
|
|
option.value = option.value.toString();
|
|
|
|
});
|
2022-03-10 19:19:57 +01:00
|
|
|
return select_options;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2022-06-16 00:43:39 +02:00
|
|
|
const image = super._createImage(item);
|
|
|
|
image.src = "/egroupware/api/avatar.php?account_id=" + item.value + "&etag=1";
|
|
|
|
return image;
|
2022-06-15 01:29:58 +02:00
|
|
|
}
|
2022-01-19 21:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("et2-select-account", Et2SelectAccount);
|