From eb5652dc203fd7ea3c4867df327e6850aac85288 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 29 Jun 2018 10:12:59 +0200 Subject: [PATCH] * Api: get avatar showing up for taglist accounts and calendar owner --- api/src/Framework.php | 8 ++++- ...ss.calendar_owner_etemplate_widget.inc.php | 30 +++++++++++++++++-- calendar/js/et2_widget_owner.js | 10 +++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/api/src/Framework.php b/api/src/Framework.php index 0ab3d0316d..170b2d6f8d 100644 --- a/api/src/Framework.php +++ b/api/src/Framework.php @@ -1479,6 +1479,7 @@ abstract class Framework extends Framework\Extra { $list['accounts']['filter']['group'] = $GLOBALS['egw_info']['user']['account_primary_group']; } + $contact_obj = new Contacts(); foreach($list as $type => &$accounts) { $options = array('account_type' => $type) + $accounts; @@ -1486,7 +1487,12 @@ abstract class Framework extends Framework\Extra $accounts = array(); foreach($key_pair as $account_id => $name) { - $accounts[] = array('value' => $account_id, 'label' => $name); + $contact = $contact_obj->read('account:'.$account_id, true); + $accounts[] = array('value' => $account_id, 'label' => $name, 'icon' => self::link('/index.php', array( + 'menuaction' => 'addressbook.addressbook_ui.photo', + 'contact_id' => $contact['id'], + 'etag' => $contact['etag'] + ))); } } diff --git a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php index 74fe42ea07..7f2fee7957 100644 --- a/calendar/inc/class.calendar_owner_etemplate_widget.inc.php +++ b/calendar/inc/class.calendar_owner_etemplate_widget.inc.php @@ -64,10 +64,17 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist } $sel_options += array_map( function($account_id, $account_name) { + $contact_obj = new Api\Contacts(); + $contact = $contact_obj->read('account:'.$account_id, true); return array( 'value' => ''.$account_id, 'label' => $account_name, - 'app' => lang('api-accounts') + 'app' => lang('api-accounts'), + 'icon' => Api\Framework::link('/index.php', array( + 'menuaction' => 'addressbook.addressbook_ui.photo', + 'contact_id' => $contact['id'], + 'etag' => $contact['etag'] ? $contact['etag'] : 1 + )) ); }, array_keys($accounts), $accounts @@ -80,7 +87,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist // calendar app is not yet loaded. $value = !empty($sel_options) ? array(): explode(',', $value); } - + // Add external owners that a select account widget will not find foreach($value as &$owner) { @@ -161,6 +168,7 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist $remove_contacts = array(); $resources = array_merge(array('' => $bo->resources['']),$bo->resources); + $contacts_obj = new Api\Contacts(); foreach($resources as $type => $data) { $mapped = array(); @@ -193,7 +201,6 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist { case 'l': // Include mailing lists - $contacts_obj = new Api\Contacts(); $lists = array_filter( $contacts_obj->get_lists(Api\Acl::READ), function($element) use($query) { @@ -229,6 +236,23 @@ class calendar_owner_etemplate_widget extends Etemplate\Widget\Taglist { $value = array_merge($value, $value['label']); } + switch($type) + { + case 'r': + // TODO: fetch resources photo + break; + case 'c': + case '': + $contact = $contacts_obj->read($type === '' ? 'account:'.$id : $id, true); + if (is_array($contact)) $value['icon'] = Api\Framework::link('/index.php', array( + 'menuaction' => 'addressbook.addressbook_ui.photo', + 'contact_id' => $contact['id'], + 'etag' => $contact['etag'] ? $contact['etag'] : 1 + )); + break; + default : + // do nothing + } $mapped[] = $value; } } diff --git a/calendar/js/et2_widget_owner.js b/calendar/js/et2_widget_owner.js index b524383a36..17f5d14734 100644 --- a/calendar/js/et2_widget_owner.js +++ b/calendar/js/et2_widget_owner.js @@ -83,6 +83,16 @@ var et2_calendar_owner = (function(){ "use strict"; return et2_taglist_email.ext if (item.class) label.addClass(item.class); if (typeof item.title != 'undefined') label.attr('title', item.title); if (typeof item.data != 'undefined') label.attr('data', item.data); + if (typeof item.icon != 'undefined') + { + var wrapper = jQuery('
').addClass('et2_taglist_tags_icon_wrapper'); + jQuery('') + .addClass('et2_taglist_tags_icon') + .css({"background-image": "url("+(item.icon.match(/^(http|https|\/)/) ? item.icon : egw.image(item.icon, item.app))+")"}) + .appendTo(wrapper); + label.appendTo(wrapper); + return wrapper; + } return label; } },