From fa928efc57395b797b1c8e947933acf237ee0609 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 19 Dec 2018 15:31:17 -0700 Subject: [PATCH] Calendar - Pass group members on load to save some user data lookups --- ...ss.calendar_owner_etemplate_widget.inc.php | 36 ++++++++++++++++++- calendar/js/et2_widget_event.js | 29 +++++++-------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php index 71113190a3..f415629a78 100644 --- a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php +++ b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php @@ -104,14 +104,44 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist { $resource = array('app'=> 'api-accounts'); } + else if ($owner < 0) + { + // Add in group memberships as strings + $info['resources'] = array_map(function($a) { return ''.$a;},$GLOBALS['egw']->accounts->members($owner, true)); + } else { continue; } - $sel_options[] = array('value' => $owner, 'label' => $label, 'app' => lang($resource['app'])) + $info; + $option = array('value' => $owner, 'label' => $label, 'app' => lang($resource['app'])) + $info; + $sel_option_index = $this->get_index($sel_options, 'value', $owner); + if($sel_option_index === false) + { + $sel_options[] = $option; + } + else + { + $sel_options[$sel_option_index] = array_merge($sel_options[$sel_option_index], $option); + } } } + /** + * Get the index of an array (sel_options) containing the given value + * + * @param Array $array + * @param string $key key we're checking to match value + * @param string $value Value we're looking for + * @return boolean|int Returns index + */ + private function get_index(&$array, $key, $value) + { + foreach($array as $_key => $_value) + { + if($_value[$key] === $value) return $_key; + } + return false; + } /** * Validate input * @@ -247,6 +277,10 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist 'contact_id' => $contact['id'], 'etag' => $contact['etag'] ? $contact['etag'] : 1 )); + if($id < 0) + { + $value['resources'] = $GLOBALS['egw']->accounts->members($id, true); + } break; default : // do nothing diff --git a/calendar/js/et2_widget_event.js b/calendar/js/et2_widget_event.js index 7641618a93..e3ec118261 100644 --- a/calendar/js/et2_widget_event.js +++ b/calendar/js/et2_widget_event.js @@ -1024,9 +1024,9 @@ et2_calendar_event.owner_check = function owner_check(event, parent, owner_too) var length = parent_owner.length; for(var i = 0; i < length; i++ ) { - // Handle grouped resources like mailing lists, they won't match so + // Handle groups & grouped resources like mailing lists, they won't match so // we need the list - pull it from sidebox owner - if(isNaN(parent_owner[i]) && options && options.find) + if((isNaN(parent_owner[i]) || parent_owner[i] < 0) && options && options.find) { var resource = options.find(function(element) {return element.id == parent_owner[i];}) || {}; if(resource && resource.resources) @@ -1036,14 +1036,6 @@ et2_calendar_event.owner_check = function owner_check(event, parent, owner_too) continue; } } - - if (parseInt(parent_owner[i]) < 0) - { - // Add in groups, if we can get them (this is syncronous) - egw.accountData(parent_owner[i],'account_id',true,function(members) { - parent_owner = parent_owner.concat(Object.keys(members)); - }); - } } var participants = jQuery.extend([],Object.keys(event.participants)); for(var i = 0; i < participants.length; i++ ) @@ -1052,10 +1044,19 @@ et2_calendar_event.owner_check = function owner_check(event, parent, owner_too) // Expand group invitations if (parseInt(id) < 0) { - // Add in groups, if we can get them (this is syncronous) - egw.accountData(id,'account_id',true,function(members) { - participants = participants.concat(Object.keys(members)); - }); + // Add in groups, if we can get them from options, great + var resource; + if(options && options.find && (resource = options.find(function(element) {return element.id === id;})) && resource.resources) + { + participants = participants.concat(resource.resources); + } + else + { + // Add in groups, if we can get them (this is asynchronous) + egw.accountData(id,'account_id',true,function(members) { + participants = participants.concat(Object.keys(members)); + }); + } } if(parent.options.owner == id || parent_owner.indexOf &&