mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-17 12:10:49 +01:00
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
/*
|
|
* Calendar owner widget
|
|
*
|
|
* @license https://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
* @package calendar
|
|
* @subpackage etemplate
|
|
* @link https://www.egroupware.org
|
|
* @author Nathan Gray
|
|
*/
|
|
|
|
import {Et2Select} from "../../api/js/etemplate/Et2Select/Et2Select";
|
|
import {css} from "@lion/core";
|
|
import {IsEmail} from "../../api/js/etemplate/Validators/IsEmail";
|
|
|
|
/**
|
|
* Select widget customised for calendar owner, which can be a user
|
|
* account or group, or an entry from almost any app, or an email address
|
|
*
|
|
*/
|
|
export class CalendarOwner extends Et2Select
|
|
{
|
|
|
|
static get styles()
|
|
{
|
|
return [
|
|
...super.styles,
|
|
css`
|
|
/* Larger maximum height before scroll*/
|
|
.select__tags {
|
|
max-height: 10em;
|
|
}
|
|
`
|
|
];
|
|
}
|
|
|
|
constructor(...args : any[])
|
|
{
|
|
super(...args);
|
|
this.searchUrl = "calendar_owner_etemplate_widget::ajax_search";
|
|
this.multiple = true;
|
|
|
|
// Any free entries must be email addresses
|
|
this.defaultValidators.push(new IsEmail());
|
|
}
|
|
|
|
/**
|
|
* Override parent to handle our special additional data types (c#,r#,etc.) when they
|
|
* are not available client side.
|
|
*
|
|
* @param {string|string[]} _value array of selected owners, which can be a number,
|
|
* or a number prefixed with one character indicating the resource type.
|
|
*/
|
|
set_value(_value)
|
|
{
|
|
super.set_value(_value);
|
|
|
|
// If parent didn't find a label, label will be the same as ID so we
|
|
// can find them that way
|
|
let missing_labels = [];
|
|
for(var i = 0; i < this.value.length; i++)
|
|
{
|
|
if(!this.menuItems.find(o => o.value == this.value[i]))
|
|
{
|
|
missing_labels.push(this.value[i]);
|
|
}
|
|
}
|
|
if(Object.keys(missing_labels).length > 0)
|
|
{
|
|
// Proper label was not found by parent - ask directly
|
|
this.egw().json('calendar_owner_etemplate_widget::ajax_owner', [missing_labels], function(data)
|
|
{
|
|
for(let owner in data)
|
|
{
|
|
if(!owner || typeof owner == "undefined")
|
|
{
|
|
continue;
|
|
}
|
|
// Put it in the list of options
|
|
let index = this.select_options.findIndex(o => o.value == owner);
|
|
if(index !== -1)
|
|
{
|
|
this.select_options[index] = data[owner];
|
|
}
|
|
else
|
|
{
|
|
this.select_options.push(data[owner]);
|
|
}
|
|
}
|
|
this.requestUpdate("select_options");
|
|
this.updateComplete.then(() => {this.syncItemsFromValue();});
|
|
}, this, true, this).sendRequest();
|
|
}
|
|
}
|
|
}
|
|
|
|
customElements.define("calendar-owner", CalendarOwner); |