From cf9e3ae4e175de49c946f76a1e7570702bac38f5 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 23 Feb 2021 00:07:44 +0200 Subject: [PATCH] WIP to display calls in calendar --- api/js/jsapi/egw_app.js | 37 +++++++++++++++++++++++ api/js/jsapi/egw_app.ts | 41 ++++++++++++++++++++++++++ calendar/inc/class.calendar_so.inc.php | 14 ++++++--- calendar/js/et2_widget_event.js | 15 +++++++++- calendar/js/et2_widget_event.ts | 18 ++++++++++- 5 files changed, 119 insertions(+), 6 deletions(-) diff --git a/api/js/jsapi/egw_app.js b/api/js/jsapi/egw_app.js index 75c6111e86..fea13684b8 100644 --- a/api/js/jsapi/egw_app.js +++ b/api/js/jsapi/egw_app.js @@ -11,6 +11,7 @@ * @author Nathan Gray */ Object.defineProperty(exports, "__esModule", { value: true }); +exports.EgwApp = void 0; require("jquery"); require("jqueryui"); require("../jsapi/egw_global"); @@ -190,6 +191,42 @@ var EgwApp = /** @class */ (function () { var id_app = _senders[0].id.split('::'); egw.open(id_app[1], this.appname); }; + /** + * Open a CRM view for a contact + * + * @param _action + * @param _senders + * @param _contact_id default: use contact_id from data of _senders[0].id + */ + EgwApp.prototype.openCRMview = function (_action, _senders) { + var contact_id = _senders; + if (typeof _senders === 'object') { + var data = egw.dataGetUIDdata(_senders[0].id); + contact_id = data.data.contact_id; + } + if (typeof contact_id !== 'undefined') { + var crm_list_1 = egw.preference('crm_list', 'addressbook'); + if (!crm_list_1 || crm_list_1 === '~edit~') + crm_list_1 = 'infolog'; + var open_1 = function (_title) { + var title = _title || this.egw.link_title('addressbook', contact_id, open_1); + if (title) { + this.egw.openTab(contact_id, 'addressbook', 'view', { + crm_list: crm_list_1 + }, { + displayName: title, + icon: this.egw.link('/api/avatar.php', { + contact_id: contact_id, + etag: (new Date).valueOf() / 86400 | 0 // cache for a day, better then no invalidation + }), + refreshCallback: 'app.addressbook.view_refresh', + id: contact_id + '-' + crm_list_1 + }); + } + }.bind(this); + open_1(); + } + }; EgwApp.prototype._do_action = function (action_id, selected) { }; /** diff --git a/api/js/jsapi/egw_app.ts b/api/js/jsapi/egw_app.ts index 251a7488e5..8a073ac2e1 100644 --- a/api/js/jsapi/egw_app.ts +++ b/api/js/jsapi/egw_app.ts @@ -292,6 +292,47 @@ export abstract class EgwApp egw.open(id_app[1], this.appname); } + /** + * Open a CRM view for a contact + * + * @param _action + * @param _senders + * @param _contact_id default: use contact_id from data of _senders[0].id + */ + openCRMview(_action, _senders) + { + let contact_id = _senders; + if (typeof _senders === 'object') + { + let data = egw.dataGetUIDdata(_senders[0].id); + contact_id = data.data.contact_id; + } + if (typeof contact_id !== 'undefined') + { + let crm_list = egw.preference('crm_list', 'addressbook'); + if (!crm_list || crm_list === '~edit~') crm_list = 'infolog'; + let open = function(_title) + { + let title = _title || this.egw.link_title('addressbook', contact_id, open); + if (title) + { + this.egw.openTab(contact_id,'addressbook', 'view', { + crm_list: crm_list + }, { + displayName: title, + icon: this.egw.link('/api/avatar.php', { + contact_id: contact_id, + etag: (new Date).valueOf()/86400|0 // cache for a day, better then no invalidation + }), + refreshCallback: 'app.addressbook.view_refresh', + id: contact_id + '-'+crm_list + }); + } + }.bind(this); + open(); + } + } + _do_action(action_id : string, selected : []) { } diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index 3ed58130d2..a640128d26 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1214,12 +1214,18 @@ class calendar_so 'filter'=> $filter, 'query' => $query, )); - foreach(self::$integration_data as $data) + foreach(self::$integration_data as $app => $data) { - if (is_array($data['selects'])) + foreach(isset($data[1]) ? $data : [$data] as $key => $data) { - //echo $app; _debug_array($data); - $selects = array_merge($selects,$data['selects']); + // create a flat array, if app implementes multiple hooks using given app-name + self::$integration_data[$data['selects'][0]['app']] = $data; + + if (is_array($data['selects'])) + { + //echo $app; _debug_array($data); + $selects = array_merge($selects,$data['selects']); + } } } } diff --git a/calendar/js/et2_widget_event.js b/calendar/js/et2_widget_event.js index 68ca793010..54d82c5f8f 100644 --- a/calendar/js/et2_widget_event.js +++ b/calendar/js/et2_widget_event.js @@ -1057,7 +1057,20 @@ var et2_calendar_event = /** @class */ (function (_super) { break; case 'series': case 'single': - egw.open(edit_id, event_data.app || 'calendar', 'edit', extra_params); + // ToDo: find a nicer way to open CRM view for calls + if (event_data.app === 'stylite') { + var contact_id = void 0; + for (var uid in event_data.participants) { + if (typeof uid === 'string' && uid[0] === 'c') { + contact_id = parseInt(uid.substr(1)); + } + } + if (contact_id) + app.calendar.openCRMview({}, contact_id); + } + else { + egw.open(edit_id, event_data.app || 'calendar', 'edit', extra_params); + } break; case 'cancel': default: diff --git a/calendar/js/et2_widget_event.ts b/calendar/js/et2_widget_event.ts index 73d6affb46..efaf762374 100644 --- a/calendar/js/et2_widget_event.ts +++ b/calendar/js/et2_widget_event.ts @@ -1334,7 +1334,23 @@ export class et2_calendar_event extends et2_valueWidget implements et2_IDetached break; case 'series': case 'single': - egw.open(edit_id, event_data.app||'calendar', 'edit', extra_params); + // ToDo: find a nicer way to open CRM view for calls + if (event_data.app === 'stylite') + { + let contact_id; + for(let uid in event_data.participants) + { + if (typeof uid === 'string' && uid[0] === 'c') + { + contact_id = parseInt(uid.substr(1)); + } + } + if (contact_id) app.calendar.openCRMview({}, contact_id); + } + else + { + egw.open(edit_id, event_data.app||'calendar', 'edit', extra_params); + } break; case 'cancel': default: