mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
Avoid outputting same message multiple times if it's still alive
This commit is contained in:
parent
ae0349487d
commit
7900bfd9cd
@ -28,7 +28,8 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
var error_reg_exp;
|
var error_reg_exp;
|
||||||
var a_href_reg = /<a href="([^"]+)">([^<]+)<\/a>/img;
|
var a_href_reg = /<a href="([^"]+)">([^<]+)<\/a>/img;
|
||||||
var new_line_reg = /<\/?(p|br)\s*\/?>\n?/ig;
|
var new_line_reg = /<\/?(p|br)\s*\/?>\n?/ig;
|
||||||
|
// keeps alive messages stored
|
||||||
|
var alive_messages = [];
|
||||||
// Register an 'error' plugin, displaying using the message system
|
// Register an 'error' plugin, displaying using the message system
|
||||||
this.registerJSONPlugin(function(type, res, req) {
|
this.registerJSONPlugin(function(type, res, req) {
|
||||||
if (typeof res.data == 'string')
|
if (typeof res.data == 'string')
|
||||||
@ -88,11 +89,21 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
parent = jQuery('body');
|
parent = jQuery('body');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if (_msg) // empty _msg just removes pervious message
|
if (_msg) // empty _msg just removes pervious message
|
||||||
{
|
{
|
||||||
|
// keeps alive messages
|
||||||
|
alive_messages.push(_msg);
|
||||||
|
// message index in stack
|
||||||
|
var msg_index = alive_messages.length-1;
|
||||||
|
|
||||||
// replace p and br-tags with newlines
|
// replace p and br-tags with newlines
|
||||||
_msg = _msg.replace(new_line_reg, "\n");
|
_msg = _msg.replace(new_line_reg, "\n");
|
||||||
|
|
||||||
var msg_div = jQuery(_wnd.document.createElement('div'))
|
var msg_div = jQuery(_wnd.document.createElement('div'))
|
||||||
.attr('id','egw_message')
|
.attr('id','egw_message')
|
||||||
.text(_msg)
|
.text(_msg)
|
||||||
@ -119,6 +130,7 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
egw.setLocalStorageItem(discardAppName,'discardedMsgs',JSON.stringify(discarded));
|
egw.setLocalStorageItem(discardAppName,'discardedMsgs',JSON.stringify(discarded));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete(alive_messages[msg_index]);
|
||||||
jQuery(msg_div).remove();
|
jQuery(msg_div).remove();
|
||||||
})
|
})
|
||||||
.addClass('close')
|
.addClass('close')
|
||||||
@ -190,6 +202,7 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
{
|
{
|
||||||
_wnd.setTimeout(function() {
|
_wnd.setTimeout(function() {
|
||||||
msg_div.remove();
|
msg_div.remove();
|
||||||
|
delete(alive_messages[msg_index]);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user