diff --git a/api/templates/default/etemplate2.css b/api/templates/default/etemplate2.css index fd32a05e35..28bf544cf4 100644 --- a/api/templates/default/etemplate2.css +++ b/api/templates/default/etemplate2.css @@ -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 { diff --git a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php index 65f51197a0..bdf66c7243 100644 --- a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php +++ b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php @@ -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); } } diff --git a/calendar/js/et2_widget_owner.js b/calendar/js/et2_widget_owner.js index f0f9f234ec..51deb610a4 100644 --- a/calendar/js/et2_widget_owner.js +++ b/calendar/js/et2_widget_owner.js @@ -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); diff --git a/calendar/js/et2_widget_owner.ts b/calendar/js/et2_widget_owner.ts index c2682150a5..a8c122fdbd 100644 --- a/calendar/js/et2_widget_owner.ts +++ b/calendar/js/et2_widget_owner.ts @@ -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);