From 1624ceae075d3f848c9a29075694f9bb8c3208d4 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 30 Jul 2020 15:01:50 +0200 Subject: [PATCH] Return an object for egw message in order to have access to it after display --- admin/inc/class.admin_hooks.inc.php | 2 -- admin/js/app.js | 10 +++++++--- admin/js/app.ts | 11 +++++++---- api/js/jsapi/egw_global.d.ts | 14 ++++++++------ api/js/jsapi/egw_message.js | 8 ++++++++ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/admin/inc/class.admin_hooks.inc.php b/admin/inc/class.admin_hooks.inc.php index 3eddf302c4..346ce54188 100644 --- a/admin/inc/class.admin_hooks.inc.php +++ b/admin/inc/class.admin_hooks.inc.php @@ -173,8 +173,6 @@ class admin_hooks } // allow apps to hook into "Admin >> Clear cache and register hooks" Api\Hooks::process('clear_cache', array(), true); - - Api\Json\Response::get()->apply('egw.message', array(lang('Done'), 'success')); } /** diff --git a/admin/js/app.js b/admin/js/app.js index 5de25c8bd4..c56ee3e622 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -1101,9 +1101,13 @@ var AdminApp = /** @class */ (function (_super) { * cache to use different method not requiring eg. so much memory */ AdminApp.prototype.clear_cache = function () { - this.egw.message(this.egw.lang('Clear cache and register hooks') + "\n" + this.egw.lang('Please wait...'), 'info'); - this.egw.json('admin.admin_hooks.ajax_clear_cache').sendRequest(true, undefined, jQuery.proxy(function (_xmlhttp, _err) { - this.egw.json('admin.admin_hooks.ajax_clear_cache&errored=1').sendRequest(true); + var wait = this.egw.message(this.egw.lang('Clear cache and register hooks') + "\n" + this.egw.lang('Please wait...'), 'info'); + var success = function () { + wait.close(); + egw.message('Done'); + }; + this.egw.json('admin.admin_hooks.ajax_clear_cache', null, success).sendRequest(true, undefined, jQuery.proxy(function (_xmlhttp, _err) { + this.egw.json('admin.admin_hooks.ajax_clear_cache&errored=1', null, success).sendRequest(true); }, this)); }; /** diff --git a/admin/js/app.ts b/admin/js/app.ts index c513578e51..ab03fea05a 100644 --- a/admin/js/app.ts +++ b/admin/js/app.ts @@ -1335,11 +1335,14 @@ class AdminApp extends EgwApp */ clear_cache() { - this.egw.message(this.egw.lang('Clear cache and register hooks')+"\n"+this.egw.lang('Please wait...'),'info'); - - this.egw.json('admin.admin_hooks.ajax_clear_cache').sendRequest(true, undefined, jQuery.proxy(function(_xmlhttp, _err) + let wait = this.egw.message(this.egw.lang('Clear cache and register hooks')+"\n"+this.egw.lang('Please wait...'),'info'); + let success = function (){ + wait.close(); + egw.message('Done'); + }; + this.egw.json('admin.admin_hooks.ajax_clear_cache', null, success).sendRequest(true, undefined, jQuery.proxy(function(_xmlhttp, _err) { - this.egw.json('admin.admin_hooks.ajax_clear_cache&errored=1').sendRequest(true); + this.egw.json('admin.admin_hooks.ajax_clear_cache&errored=1', null, success).sendRequest(true); }, this)); } diff --git a/api/js/jsapi/egw_global.d.ts b/api/js/jsapi/egw_global.d.ts index 778c609299..02f04a55a6 100644 --- a/api/js/jsapi/egw_global.d.ts +++ b/api/js/jsapi/egw_global.d.ts @@ -547,7 +547,7 @@ declare interface IegwGlobal * @param {function} _callback * @param {object} _context */ - accountData(_account_ids : number|number[], _field : string, _resolve_groups : boolean, + accountData(_account_ids : number|number[], _field : string, _resolve_groups : boolean, _callback : Function, _context : object) : void; /** * Set account data. This one can be called from the server to pre-fill the cache. @@ -827,8 +827,10 @@ declare interface IegwWndLocal extends IegwGlobal * @param {string} _discardID unique string id (appname:id) in order to register * the message as discardable. If no appname given, the id will be prefixed with * current app. The discardID will be stored in local storage. + * + * @returns {object} returns an object containing data and methods related to the message */ - message(_msg : string, _type? : "help"|"info"|"error"|"warning"|"success", _discardID? : string) : void; + message(_msg: string, _type?: "help" | "info" | "error" | "warning" | "success", _discardID?: string): {node: JQuery, message: string, index: number, close: Function}; /** * Are we running in a popup * @@ -886,7 +888,7 @@ declare interface IegwWndLocal extends IegwGlobal * @param {object|null} _links app => array of ids of linked entries * or null, if not triggered on server-side, which adds that info */ - refresh(_msg : string, _app : string, _id? : string|number, _type? : "update"|"edit"|"delete"|"add"|null, + refresh(_msg : string, _app : string, _id? : string|number, _type? : "update"|"edit"|"delete"|"add"|null, _targetapp? : string, _replace? : string|RegExp, _with? : string, _msg_type? : "error"|"warning"|"success", _links? : object) : void; /** * Handle a push notification about entry changes from the websocket @@ -925,7 +927,7 @@ declare interface IegwWndLocal extends IegwGlobal * } * @return {boolean} false if Notification is not supported by browser */ - notification(_title : string, _options : {dir?: "ltr"|"rtl"|"auto", lang: string, body?: string, icon?: string, + notification(_title : string, _options : {dir?: "ltr"|"rtl"|"auto", lang: string, body?: string, icon?: string, tag?: string, onclick: Function, onshow?: Function, onclose?: Function, onerror?: Function}) : false|void; /** * Check Notification availability by browser @@ -974,7 +976,7 @@ declare interface IegwWndLocal extends IegwGlobal * - This option only makes sense to be enabled when the open_link requested without user interaction * @param {string} _mime_type if given, we check if any app has registered a mime-handler for that type and use it */ - open_link(_link : string, _target? : string, _popup? : string, _target_app? : string, + open_link(_link : string, _target? : string, _popup? : string, _target_app? : string, _check_popup_blocker? : boolean, _mime_type? : string) : Window|void; /** * Open a (centered) popup window with given size and url @@ -989,7 +991,7 @@ declare interface IegwWndLocal extends IegwGlobal * @param {boolean} _skip_framework * @returns {Window|void} */ - openPopup(_url : string, _width : number, _height : number|"availHeight", _windowName? : string, _app? : string|boolean, + openPopup(_url : string, _width : number, _height : number|"availHeight", _windowName? : string, _app? : string|boolean, _returnID? : boolean, _status? : "yes"|"no", _skip_framework? : boolean) : Window|void; /** * Get available height of screen diff --git a/api/js/jsapi/egw_message.js b/api/js/jsapi/egw_message.js index 7f23d6e793..2843dd6aa5 100644 --- a/api/js/jsapi/egw_message.js +++ b/api/js/jsapi/egw_message.js @@ -62,6 +62,8 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd) * @param {string} _discardID unique string id (appname:id) in order to register * the message as discardable. If no appname given, the id will be prefixed with * current app. The discardID will be stored in local storage. + * + * @return {object} returns an object containing data and methods related to the message */ message: function(_msg, _type, _discardID) { @@ -206,6 +208,12 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd) }, 5000); } } + return { + node: msg_div, + message: _msg, + index: msg_index, + close: function(){msg_close.click();} + }; }, /**