2014-02-06 16:42:33 +01:00
|
|
|
/**
|
|
|
|
* EGroupware clientside API object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
|
|
|
*/
|
2021-06-05 20:39:39 +02:00
|
|
|
import './egw_core.js';
|
|
|
|
import './egw_json.js'; // for registerJSONPlugin
|
2014-02-06 16:42:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Methods to display a success or error message and the app-header
|
|
|
|
*
|
|
|
|
* @augments Class
|
|
|
|
* @param {string} _app application name object is instanciated for
|
|
|
|
* @param {object} _wnd window object is instanciated for
|
|
|
|
*/
|
|
|
|
egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|
|
|
{
|
2016-02-29 16:50:24 +01:00
|
|
|
"use strict";
|
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
_app; // not used, but required by function signature
|
2014-02-06 18:24:40 +01:00
|
|
|
var error_reg_exp;
|
2014-05-26 15:05:40 +02:00
|
|
|
var a_href_reg = /<a href="([^"]+)">([^<]+)<\/a>/img;
|
2014-06-05 11:54:21 +02:00
|
|
|
var new_line_reg = /<\/?(p|br)\s*\/?>\n?/ig;
|
2020-07-24 12:46:29 +02:00
|
|
|
// keeps alive messages stored
|
|
|
|
var alive_messages = [];
|
2014-02-13 19:47:19 +01:00
|
|
|
// Register an 'error' plugin, displaying using the message system
|
|
|
|
this.registerJSONPlugin(function(type, res, req) {
|
|
|
|
if (typeof res.data == 'string')
|
|
|
|
{
|
|
|
|
egw.message(res.data,'error');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw 'Invalid parameters';
|
|
|
|
}, null, 'error');
|
|
|
|
|
2014-05-26 15:05:40 +02:00
|
|
|
/**
|
|
|
|
* Decode html entities so they can be added via .text(_str), eg. html_entity_decode('&') === '&'
|
|
|
|
*
|
|
|
|
* @param {string} _str
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
function html_entity_decode(_str)
|
|
|
|
{
|
|
|
|
return _str && _str.indexOf('&') != -1 ? jQuery('<span>'+_str+'</span>').text() : _str;
|
|
|
|
}
|
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Display an error or regular message
|
|
|
|
*
|
2014-04-02 21:02:49 +02:00
|
|
|
* Alle messages but type "success" are displayed 'til next message or user clicks on it.
|
|
|
|
*
|
2014-02-06 18:24:40 +01:00
|
|
|
* @param {string} _msg message to show or empty to remove previous message
|
2014-04-02 21:02:49 +02:00
|
|
|
* @param {string} _type 'help', 'info', 'error', 'warning' or 'success' (default)
|
2017-02-01 18:12:18 +01:00
|
|
|
* @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.
|
2020-07-30 15:01:50 +02:00
|
|
|
*
|
|
|
|
* @return {object} returns an object containing data and methods related to the message
|
2014-02-06 16:42:33 +01:00
|
|
|
*/
|
2017-02-01 18:12:18 +01:00
|
|
|
message: function(_msg, _type, _discardID)
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
2014-02-10 17:10:01 +01:00
|
|
|
var jQuery = _wnd.jQuery;
|
2020-07-17 14:09:37 +02:00
|
|
|
var wrapper = jQuery('.egw_message_wrapper').length > 0 ? jQuery('.egw_message_wrapper')
|
2020-07-29 15:45:13 +02:00
|
|
|
: jQuery(_wnd.document.createElement('div')).addClass('egw_message_wrapper noPrint').css('position', 'absolute');
|
2014-05-26 17:39:21 +02:00
|
|
|
if (_msg && !_type)
|
2014-02-06 18:24:40 +01:00
|
|
|
{
|
|
|
|
if (typeof error_reg_exp == 'undefined') error_reg_exp = new RegExp('(error|'+egw.lang('error')+')', 'i');
|
|
|
|
|
|
|
|
_type = _msg.match(error_reg_exp) ? 'error' : 'success';
|
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
|
2014-12-10 12:05:29 +01:00
|
|
|
// if we are NOT in a popup then call the message on top window
|
2020-05-18 20:55:57 +02:00
|
|
|
if (!this.is_popup() && _wnd !== egw.top)
|
2014-12-10 12:05:29 +01:00
|
|
|
{
|
2020-05-18 20:55:57 +02:00
|
|
|
egw(egw.top).message(_msg, _type);
|
2014-12-10 12:05:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-07-17 14:09:37 +02:00
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
var parent = jQuery('div#divAppboxHeader');
|
|
|
|
// popup has no app-header (idots) or it is hidden by onlyPrint class (jdots) --> use body
|
|
|
|
if (!parent.length || parent.hasClass('onlyPrint'))
|
|
|
|
{
|
|
|
|
parent = jQuery('body');
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:46:29 +02:00
|
|
|
for (var m in alive_messages)
|
|
|
|
{
|
|
|
|
// Do not add a same message twice if it's still not dismissed
|
|
|
|
if (alive_messages[m] == _msg) return;
|
|
|
|
}
|
|
|
|
|
2014-02-06 18:24:40 +01:00
|
|
|
if (_msg) // empty _msg just removes pervious message
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
2020-07-24 12:46:29 +02:00
|
|
|
// keeps alive messages
|
|
|
|
alive_messages.push(_msg);
|
|
|
|
// message index in stack
|
|
|
|
var msg_index = alive_messages.length-1;
|
|
|
|
|
2014-06-05 11:54:21 +02:00
|
|
|
// replace p and br-tags with newlines
|
|
|
|
_msg = _msg.replace(new_line_reg, "\n");
|
2014-05-26 15:05:40 +02:00
|
|
|
var msg_div = jQuery(_wnd.document.createElement('div'))
|
2014-02-06 18:24:40 +01:00
|
|
|
.attr('id','egw_message')
|
|
|
|
.text(_msg)
|
|
|
|
.addClass(_type+'_message')
|
2020-08-07 13:29:30 +02:00
|
|
|
.click(function(){
|
|
|
|
if (_type == 'success')
|
|
|
|
{
|
|
|
|
delete(alive_messages[msg_index]);
|
|
|
|
jQuery(msg_div).remove();
|
|
|
|
}
|
|
|
|
})
|
2020-07-17 14:09:37 +02:00
|
|
|
.prependTo(wrapper);
|
|
|
|
var msg_close = jQuery(_wnd.document.createElement('span'))
|
2015-08-14 11:49:57 +02:00
|
|
|
.click(function() {
|
|
|
|
//check if the messeage should be discarded forever
|
2017-02-01 18:12:18 +01:00
|
|
|
if (_type == 'info' && _discardID
|
2015-08-14 11:49:57 +02:00
|
|
|
&& msg_chkbox && msg_chkbox.is(':checked'))
|
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
var discarded = egw.getLocalStorageItem(discardAppName,'discardedMsgs');
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2017-02-01 18:12:18 +01:00
|
|
|
if (!isDiscarded(_discardID))
|
2015-08-14 11:49:57 +02:00
|
|
|
{
|
|
|
|
if (!discarded)
|
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
discarded = [_discardID];
|
2015-08-14 11:49:57 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
if (jQuery.isArray(discarded = JSON.parse(discarded))) discarded.push(_discardID);
|
2015-08-14 11:49:57 +02:00
|
|
|
}
|
2017-02-01 18:12:18 +01:00
|
|
|
egw.setLocalStorageItem(discardAppName,'discardedMsgs',JSON.stringify(discarded));
|
2015-08-14 11:49:57 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-24 12:46:29 +02:00
|
|
|
delete(alive_messages[msg_index]);
|
2020-07-17 14:09:37 +02:00
|
|
|
jQuery(msg_div).remove();
|
2015-08-14 11:49:57 +02:00
|
|
|
})
|
2020-07-17 14:09:37 +02:00
|
|
|
.addClass('close')
|
|
|
|
.appendTo(msg_div);
|
2020-08-07 13:29:30 +02:00
|
|
|
if (_type == 'success') msg_close.hide();
|
2015-08-14 11:49:57 +02:00
|
|
|
// discard checkbox implementation
|
2017-02-01 18:12:18 +01:00
|
|
|
if (_discardID && _type === 'info')
|
2015-08-14 11:49:57 +02:00
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
var discardID = _discardID.split(':');
|
|
|
|
if (discardID.length<2)
|
|
|
|
{
|
|
|
|
_discardID = egw.app_name() +":"+_discardID;
|
|
|
|
}
|
|
|
|
var discardAppName = discardID.length>1? discardID[0]: egw.app_name();
|
|
|
|
|
|
|
|
|
2015-08-14 11:49:57 +02:00
|
|
|
// helper function to check if the messaege is discarded
|
2017-02-01 18:12:18 +01:00
|
|
|
var isDiscarded = function (_id)
|
2015-08-14 11:49:57 +02:00
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
|
|
|
|
var discarded = JSON.parse(egw.getLocalStorageItem(discardAppName,'discardedMsgs'));
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-08-14 11:49:57 +02:00
|
|
|
if (jQuery.isArray(discarded))
|
|
|
|
{
|
|
|
|
for(var i=0; i< discarded.length; i++)
|
|
|
|
{
|
2017-02-01 18:12:18 +01:00
|
|
|
if (discarded[i] === _id) return true;
|
2015-08-14 11:49:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-08-14 11:49:57 +02:00
|
|
|
//discard div container
|
|
|
|
var msg_discard =jQuery(_wnd.document.createElement('div')).addClass('discard');
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-08-14 11:49:57 +02:00
|
|
|
// checkbox
|
|
|
|
var msg_chkbox = jQuery(_wnd.document.createElement('input'))
|
|
|
|
.attr({type:"checkbox",name:"msgChkbox"})
|
2016-02-29 16:50:24 +01:00
|
|
|
.click(function(e){e.stopImmediatePropagation();})
|
2015-08-14 11:49:57 +02:00
|
|
|
.appendTo(msg_discard);
|
|
|
|
// Label
|
|
|
|
jQuery(_wnd.document.createElement('label'))
|
|
|
|
.text(egw.lang("Don't show this again"))
|
|
|
|
.css({"font-weight":"bold"})
|
|
|
|
.attr({for:'msgChkbox'})
|
|
|
|
.appendTo(msg_discard);
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2017-02-01 18:12:18 +01:00
|
|
|
if (isDiscarded(_discardID)) return;
|
2015-08-14 11:49:57 +02:00
|
|
|
msg_div.append(msg_discard);
|
|
|
|
}
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2020-07-17 14:09:37 +02:00
|
|
|
parent.prepend(wrapper);
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2014-05-26 15:05:40 +02:00
|
|
|
// replace simple a href (NO other attribute, to gard agains XSS!)
|
|
|
|
var matches = a_href_reg.exec(_msg);
|
|
|
|
if (matches)
|
|
|
|
{
|
|
|
|
var parts = _msg.split(matches[0]);
|
2015-05-19 20:56:12 +02:00
|
|
|
var href = html_entity_decode(matches[1]);
|
2014-05-26 15:05:40 +02:00
|
|
|
msg_div.text(parts[0]);
|
|
|
|
msg_div.append(jQuery(_wnd.document.createElement('a'))
|
2015-05-19 20:56:12 +02:00
|
|
|
.attr({href: href, target: href.indexOf(egw.webserverUrl) != 0 ? '_blank' : '_self'})
|
2014-05-26 15:05:40 +02:00
|
|
|
.text(matches[2]));
|
|
|
|
msg_div.append(jQuery(_wnd.document.createElement('span')).text(parts[1]));
|
|
|
|
}
|
2014-11-21 17:16:24 +01:00
|
|
|
// center the message
|
2020-07-17 14:09:37 +02:00
|
|
|
wrapper.css('right', ((jQuery(_wnd).innerWidth()-msg_div.width())/2)+'px');
|
2014-11-21 17:16:24 +01:00
|
|
|
|
2014-04-02 21:02:49 +02:00
|
|
|
if (_type == 'success') // clear message again after some time, if no error
|
2014-02-06 18:24:40 +01:00
|
|
|
{
|
2020-07-17 14:09:37 +02:00
|
|
|
_wnd.setTimeout(function() {
|
|
|
|
msg_div.remove();
|
2020-07-24 12:46:29 +02:00
|
|
|
delete(alive_messages[msg_index]);
|
2014-02-06 18:24:40 +01:00
|
|
|
}, 5000);
|
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
}
|
2020-07-30 15:01:50 +02:00
|
|
|
return {
|
|
|
|
node: msg_div,
|
|
|
|
message: _msg,
|
|
|
|
index: msg_index,
|
|
|
|
close: function(){msg_close.click();}
|
|
|
|
};
|
2014-02-06 16:42:33 +01:00
|
|
|
},
|
|
|
|
|
2014-02-10 12:21:58 +01:00
|
|
|
/**
|
|
|
|
* Are we running in a popup
|
|
|
|
*
|
|
|
|
* @returns {boolean} true: popup, false: main window
|
|
|
|
*/
|
|
|
|
is_popup: function ()
|
|
|
|
{
|
|
|
|
var popup = false;
|
|
|
|
try {
|
2014-10-17 10:22:28 +02:00
|
|
|
if (_wnd.opener && _wnd.opener != _wnd && typeof _wnd.opener.top.egw == 'function')
|
2014-02-10 12:21:58 +01:00
|
|
|
{
|
|
|
|
popup = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
// ignore SecurityError exception if opener is different security context / cross-origin
|
|
|
|
}
|
|
|
|
return popup;
|
|
|
|
},
|
|
|
|
|
2014-02-07 10:11:30 +01:00
|
|
|
/**
|
|
|
|
* Active app independent if we are using a framed template-set or not
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
app_name: function()
|
|
|
|
{
|
2014-02-10 12:49:27 +01:00
|
|
|
return !this.is_popup() && _wnd.framework && _wnd.framework.activeApp ? _wnd.framework.activeApp.appName : _wnd.egw_appName;
|
2014-02-07 10:11:30 +01:00
|
|
|
},
|
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
/**
|
|
|
|
* Update app-header and website-title
|
|
|
|
*
|
|
|
|
* @param {string} _header
|
|
|
|
* @param {string} _app Application name, if not for the current app
|
|
|
|
*/
|
|
|
|
app_header: function(_header,_app)
|
|
|
|
{
|
2014-02-10 12:49:27 +01:00
|
|
|
// not for popups and only for framed templates
|
|
|
|
if (!this.is_popup() && _wnd.framework && _wnd.framework.setWebsiteTitle)
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
2014-02-07 10:11:30 +01:00
|
|
|
var app = _app || this.app_name();
|
2014-02-06 16:42:33 +01:00
|
|
|
var title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
|
|
|
|
|
2014-02-07 10:11:30 +01:00
|
|
|
_wnd.framework.setWebsiteTitle.call(_wnd.framework, app, title, _header);
|
2014-02-06 16:42:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 17:10:01 +01:00
|
|
|
_wnd.jQuery('div#divAppboxHeader').text(_header);
|
2014-02-06 16:42:33 +01:00
|
|
|
|
|
|
|
_wnd.document.title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
|
2014-02-25 10:46:05 +01:00
|
|
|
},
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-12-03 18:12:08 +01:00
|
|
|
/**
|
|
|
|
* Loading prompt is for building a loading animation and show it to user
|
|
|
|
* while a request is under progress.
|
2016-02-29 16:50:24 +01:00
|
|
|
*
|
2015-12-07 10:08:09 +01:00
|
|
|
* @param {string} _id a unique id to be able to distinguish loading-prompts
|
|
|
|
* @param {boolean} _stat true to show the loading and false to remove it
|
|
|
|
* @param {string} _msg a message to show while loading
|
2016-02-29 16:50:24 +01:00
|
|
|
* @param {string|jQuery _node} _node DOM selector id or jquery DOM object, default is body
|
|
|
|
* @param {string} _mode defines the animation mode, default mode is spinner
|
|
|
|
* animation modes:
|
2015-12-07 10:08:09 +01:00
|
|
|
* - spinner: a sphere with a spinning bar inside
|
|
|
|
* - horizental: a horizental bar
|
2016-02-29 16:50:24 +01:00
|
|
|
*
|
2015-12-03 18:12:08 +01:00
|
|
|
* @returns {jquery dom object|null} returns jQuery DOM object or null in case of hiding
|
|
|
|
*/
|
2015-12-07 10:08:09 +01:00
|
|
|
loading_prompt: function(_id,_stat,_msg,_node, _mode)
|
2015-12-03 18:12:08 +01:00
|
|
|
{
|
|
|
|
var $container = '';
|
2017-10-11 15:03:34 +02:00
|
|
|
var jQuery = _wnd.jQuery;
|
|
|
|
|
|
|
|
var id = _id? 'egw-loadin-prompt_'+_id: 'egw-loading-prompt_1';
|
2015-12-07 10:08:09 +01:00
|
|
|
var mode = _mode || 'spinner';
|
2015-12-03 18:12:08 +01:00
|
|
|
if (_stat)
|
|
|
|
{
|
2017-10-11 15:03:34 +02:00
|
|
|
var $node = _node? jQuery(_node): jQuery('body');
|
2015-12-03 18:12:08 +01:00
|
|
|
|
2017-10-11 15:03:34 +02:00
|
|
|
var $container = jQuery(_wnd.document.createElement('div'))
|
2015-12-07 10:08:09 +01:00
|
|
|
.attr('id', id)
|
|
|
|
.addClass('egw-loading-prompt-container ui-front');
|
2015-12-03 18:12:08 +01:00
|
|
|
|
2017-10-11 15:03:34 +02:00
|
|
|
var $text = jQuery(_wnd.document.createElement('span'))
|
2015-12-07 10:08:09 +01:00
|
|
|
.addClass('egw-loading-prompt-'+mode+'-msg')
|
|
|
|
.text(_msg)
|
2015-12-03 18:12:08 +01:00
|
|
|
.appendTo($container);
|
2017-10-11 15:03:34 +02:00
|
|
|
var $animator = jQuery(_wnd.document.createElement('div'))
|
2015-12-07 10:08:09 +01:00
|
|
|
.addClass('egw-loading-prompt-'+mode+'-animator')
|
2015-12-03 18:12:08 +01:00
|
|
|
.appendTo($container);
|
2020-03-31 13:03:31 +02:00
|
|
|
if (!_wnd.document.getElementById(id)) $container.insertBefore($node);
|
2015-12-03 18:12:08 +01:00
|
|
|
return $container;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-31 13:03:31 +02:00
|
|
|
$container = jQuery(_wnd.document.getElementById(id));
|
2015-12-03 18:12:08 +01:00
|
|
|
if ($container.length > 0) $container.remove();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2014-02-25 10:46:05 +01:00
|
|
|
|
|
|
|
/**
|
2014-05-22 17:29:14 +02:00
|
|
|
* Refresh given application _targetapp display of entry _app _id, incl. outputting _msg
|
|
|
|
*
|
|
|
|
* Default implementation here only reloads window with it's current url with an added msg=_msg attached
|
|
|
|
*
|
|
|
|
* @param {string} _msg message (already translated) to show, eg. 'Entry deleted'
|
|
|
|
* @param {string} _app application name
|
|
|
|
* @param {(string|number)} _id id of entry to refresh or null
|
|
|
|
* @param {string} _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.
|
2020-07-29 13:58:02 +02:00
|
|
|
* - update-in-place: update row, but do NOT move it, or refresh if uid does not exist
|
2014-05-22 17:29:14 +02:00
|
|
|
* - 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 {string} _targetapp which app's window should be refreshed, default current
|
|
|
|
* @param {(string|RegExp)} _replace regular expression to replace in url
|
|
|
|
* @param {string} _with
|
|
|
|
* @param {string} _msg_type 'error', 'warning' or 'success' (default)
|
2014-05-26 15:29:35 +02:00
|
|
|
* @param {object|null} _links app => array of ids of linked entries
|
|
|
|
* or null, if not triggered on server-side, which adds that info
|
2014-05-22 17:29:14 +02:00
|
|
|
*/
|
2014-05-26 15:29:35 +02:00
|
|
|
refresh: function(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type, _links)
|
2014-02-25 10:46:05 +01:00
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
// Log for debugging purposes
|
2014-06-10 17:27:11 +02:00
|
|
|
this.debug("log", "egw_refresh(%s, %s, %s, %o, %s, %s)", _msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type, _links);
|
2014-05-22 17:29:14 +02:00
|
|
|
|
|
|
|
var win = typeof _targetapp != 'undefined' ? _wnd.egw_appWindow(_targetapp) : _wnd;
|
|
|
|
|
|
|
|
this.message(_msg, _msg_type);
|
|
|
|
|
2014-06-10 17:27:11 +02:00
|
|
|
if(typeof _links == "undefined")
|
|
|
|
{
|
|
|
|
_links = [];
|
|
|
|
}
|
|
|
|
|
2014-05-22 17:29:14 +02:00
|
|
|
// notify app observers: if observer for _app itself returns false, no regular refresh will take place
|
|
|
|
// app's own observer can replace current app_refresh functionality
|
|
|
|
var no_regular_refresh = false;
|
2020-04-21 23:36:17 +02:00
|
|
|
for(var app_obj of _wnd.egw.window.EgwApp) // run observers in main window (eg. not iframe, which might be opener!)
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
2014-05-23 11:19:46 +02:00
|
|
|
if (typeof app_obj.observer == 'function' &&
|
2020-04-29 19:28:17 +02:00
|
|
|
app_obj.observer(_msg, _app, _id, _type, _msg_type, _links) === false && app_obj.appname === _app)
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
|
|
|
no_regular_refresh = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (no_regular_refresh) return;
|
|
|
|
|
2014-05-23 10:21:11 +02:00
|
|
|
// if we have a framework template, let it deal with refresh, unless it returns a DOMwindow for us to refresh
|
|
|
|
if (win.framework && win.framework.refresh &&
|
|
|
|
!(win = win.framework.refresh(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type)))
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if window registered an app_refresh method or overwritten app_refresh, just call it
|
|
|
|
if(typeof win.app_refresh == "function" && typeof win.app_refresh.registered == "undefined" ||
|
|
|
|
typeof win.app_refresh != "undefined" && win.app_refresh.registered(_app))
|
|
|
|
{
|
|
|
|
win.app_refresh(_msg, _app, _id, _type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// etemplate2 specific to avoid reloading whole page
|
2014-09-25 18:03:28 +02:00
|
|
|
if(typeof win.etemplate2 != "undefined" && win.etemplate2.app_refresh)
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
2014-09-25 18:03:28 +02:00
|
|
|
var refresh_done = win.etemplate2.app_refresh(_msg, _app, _id, _type);
|
2014-05-22 17:29:14 +02:00
|
|
|
|
|
|
|
// Refresh target or current app too
|
2014-05-23 10:21:11 +02:00
|
|
|
if ((_targetapp || this.app_name()) != _app)
|
2014-05-22 17:29:14 +02:00
|
|
|
{
|
2014-09-25 18:03:28 +02:00
|
|
|
refresh_done = win.etemplate2.app_refresh(_msg, _targetapp || this.app_name()) || refresh_done;
|
2014-05-22 17:29:14 +02:00
|
|
|
}
|
|
|
|
//In case that we have etemplate2 ready but it's empty and refresh is not done
|
2014-05-23 10:21:11 +02:00
|
|
|
if (refresh_done) return;
|
2014-05-22 17:29:14 +02:00
|
|
|
}
|
|
|
|
|
2014-05-23 10:21:11 +02:00
|
|
|
// fallback refresh by reloading window
|
2014-05-22 17:29:14 +02:00
|
|
|
var href = win.location.href;
|
|
|
|
|
|
|
|
if (typeof _replace != 'undefined')
|
|
|
|
{
|
2014-07-18 11:16:41 +02:00
|
|
|
href = href.replace(typeof _replace == 'string' ? new RegExp(_replace) : _replace, (typeof _with != 'undefined' && _with != null) ? _with : '');
|
2014-05-22 17:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (href.indexOf('msg=') != -1)
|
|
|
|
{
|
|
|
|
href = href.replace(/msg=[^&]*/,'msg='+encodeURIComponent(_msg));
|
|
|
|
}
|
|
|
|
else if (_msg)
|
|
|
|
{
|
|
|
|
href += (href.indexOf('?') != -1 ? '&' : '?') + 'msg=' + encodeURIComponent(_msg);
|
|
|
|
}
|
|
|
|
//alert('egw_refresh() about to call '+href);
|
|
|
|
win.location.href = href;
|
2020-01-23 19:03:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a push notification about entry changes from the websocket
|
|
|
|
*
|
|
|
|
* @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: function(pushData)
|
|
|
|
{
|
|
|
|
// Log for debugging purposes
|
|
|
|
this.debug("log", "push(%o)", pushData);
|
|
|
|
|
|
|
|
if (typeof pushData == "undefined")
|
|
|
|
{
|
|
|
|
this.debug('warn', "Push sent nothing");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify app observers
|
2020-04-21 23:36:17 +02:00
|
|
|
for (var app_obj of _wnd.egw.window.EgwApp) // run observers in main window (eg. not iframe, which might be opener!)
|
2020-01-23 19:03:29 +01:00
|
|
|
{
|
|
|
|
if (typeof app_obj.push == 'function')
|
|
|
|
{
|
|
|
|
app_obj.push(pushData);
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 15:21:58 +02:00
|
|
|
|
|
|
|
// call the global registered push callbacks
|
|
|
|
this.registerPush(pushData);
|
2020-01-23 19:03:29 +01:00
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
};
|
2020-01-23 19:03:29 +01:00
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
});
|