forked from extern/egroupware
Implement discard option for egw.message:
- function new signature: message(_msg, _type, _discard) where the discard is boolean - Add discard checkbox in order to be able to discard an info_message
This commit is contained in:
parent
9566a6b758
commit
e39005ec73
@ -59,8 +59,9 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
||||
*
|
||||
* @param {string} _msg message to show or empty to remove previous message
|
||||
* @param {string} _type 'help', 'info', 'error', 'warning' or 'success' (default)
|
||||
* @param {boolean} _discard if true, it will show a checkbox in order to discard the message, default is false
|
||||
*/
|
||||
message: function(_msg, _type)
|
||||
message: function(_msg, _type, _discard)
|
||||
{
|
||||
var jQuery = _wnd.jQuery;
|
||||
|
||||
@ -95,15 +96,74 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
||||
{
|
||||
// replace p and br-tags with newlines
|
||||
_msg = _msg.replace(new_line_reg, "\n");
|
||||
|
||||
|
||||
var msg_div = jQuery(_wnd.document.createElement('div'))
|
||||
.attr('id','egw_message')
|
||||
.text(_msg)
|
||||
.addClass(_type+'_message')
|
||||
.click(function() {$j(this).remove();})
|
||||
.click(function() {
|
||||
//check if the messeage should be discarded forever
|
||||
if (_type == 'info' && _discard
|
||||
&& msg_chkbox && msg_chkbox.is(':checked'))
|
||||
{
|
||||
var discarded = egw.getLocalStorageItem(egw.app_name(),'discardedMsgs');
|
||||
|
||||
if (!isDiscarded(_msg))
|
||||
{
|
||||
if (!discarded)
|
||||
{
|
||||
discarded = [_msg];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jQuery.isArray(JSON.parse(discarded))) discarded.push(_msg);
|
||||
}
|
||||
egw.setLocalStorageItem(egw.app_name(),'discardedMsgs',JSON.stringify(discarded));
|
||||
}
|
||||
}
|
||||
$j(this).remove();
|
||||
})
|
||||
.css('position', 'absolute');
|
||||
|
||||
// discard checkbox implementation
|
||||
if (_discard && _type === 'info')
|
||||
{
|
||||
// helper function to check if the messaege is discarded
|
||||
var isDiscarded = function (_msg)
|
||||
{
|
||||
var discarded = JSON.parse(egw.getLocalStorageItem(egw.app_name(),'discardedMsgs'));
|
||||
|
||||
if (jQuery.isArray(discarded))
|
||||
{
|
||||
for(var i=0; i< discarded.length; i++)
|
||||
{
|
||||
if (discarded[i] === _msg) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
//discard div container
|
||||
var msg_discard =jQuery(_wnd.document.createElement('div')).addClass('discard');
|
||||
|
||||
// checkbox
|
||||
var msg_chkbox = jQuery(_wnd.document.createElement('input'))
|
||||
.attr({type:"checkbox",name:"msgChkbox"})
|
||||
.click(function(e){e.stopImmediatePropagation();})
|
||||
.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);
|
||||
|
||||
if (isDiscarded(_msg)) return;
|
||||
msg_div.append(msg_discard);
|
||||
}
|
||||
|
||||
parent.prepend(msg_div);
|
||||
|
||||
|
||||
// replace simple a href (NO other attribute, to gard agains XSS!)
|
||||
var matches = a_href_reg.exec(_msg);
|
||||
if (matches)
|
||||
|
@ -961,6 +961,10 @@ td.lettersearch {
|
||||
.help_message {
|
||||
background-image: url(../../default/images/dialog_help.png);
|
||||
}
|
||||
.info_message .discard {
|
||||
float:right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
/**
|
||||
* Message in popup
|
||||
*/
|
||||
|
@ -3798,6 +3798,10 @@ div.admin-config form > table td b {
|
||||
font-weight: bold;
|
||||
background-image: url(../images/dialog_error.png);
|
||||
}
|
||||
.info_message .discard {
|
||||
float:right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
/**
|
||||
* Message in popup
|
||||
*/
|
||||
|
@ -3784,6 +3784,10 @@ div.admin-config form > table td b {
|
||||
font-weight: bold;
|
||||
background-image: url(../images/dialog_error.png);
|
||||
}
|
||||
.info_message .discard {
|
||||
float:right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
/**
|
||||
* Message in popup
|
||||
*/
|
||||
|
@ -487,7 +487,10 @@ div.admin-config form > table {
|
||||
font-weight: bold;
|
||||
background-image: url(../images/dialog_error.png);
|
||||
}
|
||||
|
||||
.info_message .discard {
|
||||
float:right;
|
||||
margin-top: 4px;
|
||||
}
|
||||
/**
|
||||
* Message in popup
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user