From 23cbc01e2c8050c841c0c2fd6d769a14894c7f7e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 26 Jun 2014 08:23:02 +0000 Subject: [PATCH] activating observer for admin instead of app_refresh and using it to invalidate client-side account-cache --- admin/js/app.js | 7 +++-- phpgwapi/js/jsapi/egw_user.js | 59 ++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/admin/js/app.js b/admin/js/app.js index b642a448fa..97ae0cbe17 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -92,7 +92,7 @@ app.classes.admin = AppJS.extend( ); // Register app refresh now that iframe is available - register_app_refresh('admin',jQuery.proxy(this.refresh,this)); + //register_app_refresh('admin',jQuery.proxy(this.refresh,this)); } break; @@ -138,12 +138,13 @@ app.classes.admin = AppJS.extend( * @param {string} _targetapp which app's window should be refreshed, default current * @return {false|*} false to stop regular refresh, thought all observers are run */ - /* as replacement for register_app_refresh in et2_ready, would allow to retire app_refresh stuff ... observer: function(_msg, _app, _id, _type, _msg_type, _targetapp) { switch(_app) { case 'admin': + // invalidate client-side account-cache + this.egw.invalidate_account(_id, _type); // group deleted, added or updated if (_id < 0) { @@ -160,7 +161,7 @@ app.classes.admin = AppJS.extend( } } } - },*/ + }, /** * Special handling for egw_refresh() in admin, to refresh the iframe when diff --git a/phpgwapi/js/jsapi/egw_user.js b/phpgwapi/js/jsapi/egw_user.js index c1b77b9ad9..5dba16db60 100644 --- a/phpgwapi/js/jsapi/egw_user.js +++ b/phpgwapi/js/jsapi/egw_user.js @@ -104,7 +104,64 @@ egw.extend('user', egw.MODULE_GLOBAL, function() list = list.concat(accountStore[type]); } return list; + }, + + /** + * Invalidate client-side account cache + * + * For _type == "add" we invalidate the whole cache currently. + * + * @param {number} _id nummeric account_id, !_id will invalidate whole cache + * @param {string} _type "add", "delete", "update" or "edit" + */ + invalidate_account: function(_id, _type) + { + if (jQuery.isEmptyObject(accountStore)) return; + + switch(_type) + { + case 'delete': + case 'edit': + case 'update': + if (_id) + { + var store = _id < 0 ? accountStore.groups : accountStore.accounts; + for(var i=0; i < store.length; ++i) + { + if (_id == store[i].value) + { + if (_type == 'delete') + { + delete(store[i]); + } + else + { + this.link_title('home-accounts', _id, function(_label) + { + store[i].label = _label; + if (_id < 0) + { + for(var j=0; j < accountStore.owngroups.length; ++j) + { + if (_id == accountStore.owngroups[j].value) + { + accountStore.owngroups[j].label = _label; + break; + } + } + } + }, this, true); // true = force reload + } + break; + } + } + break; + } + // fall through + default: + accountStore = {}; + break; + } } }; - });