* Calendar: disable some owner/participant pre-loading for faster initial open

We no longer send the accounts or owngroups to pre-fill the owner / participant options.   Accounts are pulled from the client-side cache, groups are now always via ajax like other resources
This commit is contained in:
nathangray 2020-04-22 13:08:50 -06:00
parent eb795d523b
commit 09275367c0
4 changed files with 98 additions and 48 deletions

View File

@ -1190,6 +1190,7 @@ div.et2_vfsPath li img {
position: relative;
margin: 0px auto -16px auto;
top: 5px;
background-image: url('images/ajax-loader.gif');
}
.et2_taglist .ms-input-readonly {display: none;}
.et2_taglist div.ms-sel-ctn .ms-close-btn {

View File

@ -48,50 +48,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
}
$sel_options =& self::$request->sel_options[$form_name];
// Get user accounts, formatted nicely for grouping and matching
// the ajax call calendar_uiforms->ajax_owner() - users first
$accounts = array();
$list = array('accounts', 'owngroups');
foreach($list as $type)
{
$account_options = array('account_type' => $type);
$accounts_type = Api\Accounts::link_query('',$account_options);
if($type == 'accounts')
{
$accounts_type = array_intersect_key($accounts_type, $GLOBALS['egw']->acl->get_grants('calendar'));
}
$accounts += $accounts_type;
}
$sel_options += array_map(
function($account_id, $account_name)
{
$data = array(
'value' => ''.$account_id,
'label' => $account_name,
'app' => lang('api-accounts'),
);
if ($account_id > 0)
{
$contact_obj = new Api\Contacts();
if (($contact = $contact_obj->read('account:'.$account_id, true)))
{
$data['icon'] = Api\Framework::link('/api/avatar.php', array(
'contact_id' => $contact['id'],
'etag' => $contact['etag'] ? $contact['etag'] : 1
));
}
}
else
{
// Add in group memberships as strings
$data['resources'] = array_map(function($a) { return ''.$a;},$GLOBALS['egw']->accounts->members($account_id, true));
}
return $data;
},
array_keys($accounts), $accounts
);
if(!is_array($value))
if($value && !is_array($value))
{
// set value with an empty string only if sel options are not
// loaded, for example: setting calendar owner via URL when
@ -215,11 +172,13 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist
// Handle Api\Accounts seperately
if($type == '')
{
$owngroup_options = $options+array('account_type'=>'owngroups');
$own_groups = Api\Accounts::link_query('',$owngroup_options);
$account_options = $options + array('account_type' => 'both');
$_results += $remove_contacts = Api\Accounts::link_query($query, $account_options);
if (!empty($_REQUEST['checkgrants']))
{
$grants = $GLOBALS['egw']->acl->get_grants('calendar');
$grants = (array)$GLOBALS['egw']->acl->get_grants('calendar') + $own_groups;
$_results = array_intersect_key($_results, $grants);
}
}

View File

@ -53,6 +53,10 @@ var et2_calendar_owner = /** @class */ (function (_super) {
};
return _this;
}
et2_calendar_owner.prototype.transformAttributes = function (_attrs) {
_super.prototype.transformAttributes.call(this, _attrs);
_attrs.select_options = this._get_accounts(_attrs.select_options);
};
et2_calendar_owner.prototype.doLoadingFinished = function () {
_super.prototype.doLoadingFinished.call(this);
var widget = this;
@ -89,6 +93,42 @@ var et2_calendar_owner = /** @class */ (function (_super) {
return null;
return this.taglist.getValue();
};
/**
* Get account info for select options from common client-side account cache
*
* @return {Array} select options
*/
et2_calendar_owner.prototype._get_accounts = function (select_options) {
if (!jQuery.isArray(select_options)) {
var options = jQuery.extend({}, select_options);
select_options = [];
for (var key in options) {
if (typeof options[key] == 'object') {
if (typeof (options[key].key) == 'undefined') {
options[key].value = key;
}
select_options.push(options[key]);
}
else {
select_options.push({ value: key, label: options[key] });
}
}
}
var type = this.egw().preference('account_selection', 'common');
var accounts = this.egw().accounts('accounts');
var _loop_1 = function (option) {
if (!select_options.find(function (element) { return element.value == option.value; })) {
option.app = this_1.egw().lang('api-accounts');
select_options.push(option);
}
};
var this_1 = this;
for (var _i = 0, accounts_1 = accounts; _i < accounts_1.length; _i++) {
var option = accounts_1[_i];
_loop_1(option);
}
return select_options;
};
/**
* Override parent to handle our special additional data types (c#,r#,etc.) when they
* are not available client side.
@ -103,7 +143,7 @@ var et2_calendar_owner = /** @class */ (function (_super) {
for (var i = 0; i < this.options.value.length; i++) {
var value = this.options.value[i];
if (value.id == value.label) {
// Proper label was not fount by parent - ask directly
// Proper label was not found by parent - ask directly
egw.json('calendar_owner_etemplate_widget::ajax_owner', value.id, function (data) {
this.widget.options.value[this.i].label = data;
this.widget.set_value(this.widget.options.value);

View File

@ -13,7 +13,9 @@
et2_widget_taglist;
*/
import {et2_register_widget} from "../../api/js/etemplate/et2_core_widget";
import {et2_register_widget, WidgetConfig} from "../../api/js/etemplate/et2_core_widget";
import {ClassWithAttributes} from "../../api/js/etemplate/et2_core_inheritance";
import {et2_selectbox} from "../../api/js/etemplate/et2_widget_selectbox";
/**
* Tag list widget customised for calendar owner, which can be a user
@ -63,6 +65,13 @@ export class et2_calendar_owner extends et2_taglist_email
};
transformAttributes( _attrs)
{
super.transformAttributes(_attrs);
_attrs.select_options = this._get_accounts(_attrs.select_options);
}
doLoadingFinished()
{
super.doLoadingFinished();
@ -106,6 +115,47 @@ export class et2_calendar_owner extends et2_taglist_email
return this.taglist.getValue();
}
/**
* Get account info for select options from common client-side account cache
*
* @return {Array} select options
*/
_get_accounts(select_options)
{
if (!jQuery.isArray(select_options))
{
var options = jQuery.extend({}, select_options);
select_options = [];
for(var key in options)
{
if (typeof options[key] == 'object')
{
if (typeof(options[key].key) == 'undefined')
{
options[key].value = key;
}
select_options.push(options[key]);
}
else
{
select_options.push({value: key, label: options[key]});
}
}
}
var type = this.egw().preference('account_selection', 'common');
var accounts = this.egw().accounts('accounts');
for(const option of accounts)
{
if(!select_options.find(element => element.value == option.value))
{
option.app = this.egw().lang('api-accounts');
select_options.push(option);
}
}
return select_options
}
/**
* Override parent to handle our special additional data types (c#,r#,etc.) when they
* are not available client side.
@ -124,7 +174,7 @@ export class et2_calendar_owner extends et2_taglist_email
var value = this.options.value[i];
if(value.id == value.label)
{
// Proper label was not fount by parent - ask directly
// Proper label was not found by parent - ask directly
egw.json('calendar_owner_etemplate_widget::ajax_owner',value.id,function(data) {
this.widget.options.value[this.i].label = data;
this.widget.set_value(this.widget.options.value);