Addressbook: Update CRM view contact info in sidebox if it's changed by push message

This commit is contained in:
nathangray 2021-03-04 13:53:52 -07:00
parent df54dcace4
commit 19bd3a03b0
5 changed files with 81 additions and 6 deletions

View File

@ -3039,6 +3039,10 @@ class addressbook_ui extends addressbook_bo
unset($contact_id); unset($contact_id);
} }
break; break;
default:
// No button, probably a refresh
$content = $this->read($content['id']);
break;
} }
} }
else else
@ -3193,7 +3197,7 @@ class addressbook_ui extends addressbook_bo
// Load CRM code // Load CRM code
Framework::includeJS('.','CRM','addressbook'); Framework::includeJS('.','CRM','addressbook');
$content['view_sidebox'] = addressbook_hooks::getViewDOMID($contact_id, $crm_list); $content['view_sidebox'] = addressbook_hooks::getViewDOMID($content['id'], $crm_list);
$this->tmpl->exec('addressbook.addressbook_ui.view',$content,$sel_options,$readonlys,array( $this->tmpl->exec('addressbook.addressbook_ui.view',$content,$sel_options,$readonlys,array(
'id' => $content['id'], 'id' => $content['id'],
'index' => $content['index'], 'index' => $content['index'],

View File

@ -161,6 +161,39 @@ var AddressbookApp = /** @class */ (function (_super) {
} }
return true; return true;
}; };
/**
* Handle a push notification about entry changes from the websocket
*
* Get's called for data of all apps, but should only handle data of apps it displays,
* which is by default only it's own, but can be for multiple apps eg. for calendar.
*
* @param pushData
* @param {string} pushData.app application name
* @param {(string|number)} pushData.id id of entry to refresh or null
* @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null
* - update: request just modified data from given rows. Sorting is not considered,
* so if the sort field is changed, the row will not be moved.
* - edit: rows changed, but sorting may be affected. Requires full reload.
* - delete: just delete the given rows clientside (no server interaction neccessary)
* - add: requires full reload for proper sorting
* @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary
* @param {number} pushData.account_id User that caused the notification
*/
AddressbookApp.prototype.push = function (pushData) {
var _a, _b;
// don't care about other apps data
if (pushData.app !== this.appname)
return;
// Update the contact list
if (this.et2 && this.et2.getInstanceManager().name == "addressbook.index") {
return _super.prototype.push.call(this, pushData);
}
// Update CRM view (sidebox part), if open
var contact_id = ((_b = (_a = this.et2) === null || _a === void 0 ? void 0 : _a.getArrayMgr("content")) === null || _b === void 0 ? void 0 : _b.getEntry("id")) || 0;
if (this.et2 && contact_id && contact_id == pushData.id) {
this.et2.getInstanceManager().submit();
}
};
/** /**
* Change handler for contact / org selectbox * Change handler for contact / org selectbox
* *

View File

@ -17,7 +17,7 @@ import 'jqueryui';
import '../jsapi/egw_global'; import '../jsapi/egw_global';
import '../etemplate/et2_types'; import '../etemplate/et2_types';
import {EgwApp} from '../../api/js/jsapi/egw_app'; import {EgwApp, PushData} from '../../api/js/jsapi/egw_app';
import {etemplate2} from "../../api/js/etemplate/etemplate2"; import {etemplate2} from "../../api/js/etemplate/etemplate2";
/** /**
@ -183,6 +183,43 @@ class AddressbookApp extends EgwApp
return true; return true;
} }
/**
* Handle a push notification about entry changes from the websocket
*
* Get's called for data of all apps, but should only handle data of apps it displays,
* which is by default only it's own, but can be for multiple apps eg. for calendar.
*
* @param pushData
* @param {string} pushData.app application name
* @param {(string|number)} pushData.id id of entry to refresh or null
* @param {string} pushData.type either 'update', 'edit', 'delete', 'add' or null
* - update: request just modified data from given rows. Sorting is not considered,
* so if the sort field is changed, the row will not be moved.
* - edit: rows changed, but sorting may be affected. Requires full reload.
* - delete: just delete the given rows clientside (no server interaction neccessary)
* - add: requires full reload for proper sorting
* @param {object|null} pushData.acl Extra data for determining relevance. eg: owner or responsible to decide if update is necessary
* @param {number} pushData.account_id User that caused the notification
*/
push(pushData : PushData)
{
// don't care about other apps data
if(pushData.app !== this.appname) return;
// Update the contact list
if(this.et2 && this.et2.getInstanceManager().name == "addressbook.index")
{
return super.push(pushData);
}
// Update CRM view (sidebox part), if open
let contact_id = this.et2?.getArrayMgr("content")?.getEntry("id") || 0;
if(this.et2 && contact_id && contact_id == pushData.id)
{
this.et2.getInstanceManager().submit();
}
}
/** /**
* Change handler for contact / org selectbox * Change handler for contact / org selectbox
* *

View File

@ -160,6 +160,7 @@ var EgwApp = /** @class */ (function () {
* @param {number} pushData.account_id User that caused the notification * @param {number} pushData.account_id User that caused the notification
*/ */
EgwApp.prototype.push = function (pushData) { EgwApp.prototype.push = function (pushData) {
var _a;
// don't care about other apps data, reimplement if your app does care eg. calendar // don't care about other apps data, reimplement if your app does care eg. calendar
if (pushData.app !== this.appname) if (pushData.app !== this.appname)
return; return;
@ -171,7 +172,7 @@ var EgwApp = /** @class */ (function () {
// If we know about it and it's an update, just update. // If we know about it and it's an update, just update.
// This must be before all ACL checks, as responsible might have changed and entry need to be removed // This must be before all ACL checks, as responsible might have changed and entry need to be removed
// (server responds then with null / no entry causing the entry to disappear) // (server responds then with null / no entry causing the entry to disappear)
if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData))) { if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData)) && this.et2) {
return this.et2.getInstanceManager().refresh("", pushData.app, pushData.id, pushData.type); return this.et2.getInstanceManager().refresh("", pushData.app, pushData.id, pushData.type);
} }
// Check grants to see if we know we aren't supposed to show it // Check grants to see if we know we aren't supposed to show it
@ -180,7 +181,7 @@ var EgwApp = /** @class */ (function () {
return; return;
} }
// Nextmatch does the hard part of updating. Try to find one. // Nextmatch does the hard part of updating. Try to find one.
var nm = this.et2.getDOMWidgetById('nm'); var nm = (_a = this.et2) === null || _a === void 0 ? void 0 : _a.getDOMWidgetById('nm');
if (!nm) { if (!nm) {
return; return;
} }

View File

@ -285,7 +285,7 @@ export abstract class EgwApp
// If we know about it and it's an update, just update. // If we know about it and it's an update, just update.
// This must be before all ACL checks, as responsible might have changed and entry need to be removed // This must be before all ACL checks, as responsible might have changed and entry need to be removed
// (server responds then with null / no entry causing the entry to disappear) // (server responds then with null / no entry causing the entry to disappear)
if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData))) if (pushData.type !== "add" && this.egw.dataHasUID(this.uid(pushData)) && this.et2)
{ {
return this.et2.getInstanceManager().refresh("", pushData.app, pushData.id, pushData.type); return this.et2.getInstanceManager().refresh("", pushData.app, pushData.id, pushData.type);
} }
@ -299,7 +299,7 @@ export abstract class EgwApp
} }
// Nextmatch does the hard part of updating. Try to find one. // Nextmatch does the hard part of updating. Try to find one.
let nm = <et2_nextmatch>this.et2.getDOMWidgetById('nm'); let nm = <et2_nextmatch>this.et2?.getDOMWidgetById('nm');
if(!nm) if(!nm)
{ {
return; return;