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:
Hadi Nategh 2015-08-17 15:17:54 +00:00
parent 44a8ac5fe1
commit 17e08c744e
7 changed files with 82 additions and 5 deletions

View File

@ -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} _msg message to show or empty to remove previous message
* @param {string} _type 'help', 'info', 'error', 'warning' or 'success' (default) * @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; var jQuery = _wnd.jQuery;
@ -100,8 +101,67 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
.attr('id','egw_message') .attr('id','egw_message')
.text(_msg) .text(_msg)
.addClass(_type+'_message') .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'); .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); parent.prepend(msg_div);
// replace simple a href (NO other attribute, to gard agains XSS!) // replace simple a href (NO other attribute, to gard agains XSS!)

View File

@ -263,6 +263,7 @@ domain name for mail-address, eg. "%1" common de Domainname für E-Mail Adresse,
domestic common de Inland domestic common de Inland
dominica common de DOMINICA dominica common de DOMINICA
dominican republic common de DOMINIKANISCHE REPUBLIK dominican republic common de DOMINIKANISCHE REPUBLIK
don't show this again common de Text nicht mehr anzeigen
done common de Fertig done common de Fertig
dos international common de DOS International dos international common de DOS International
download common de Herunterladen download common de Herunterladen

View File

@ -263,6 +263,7 @@ domain name for mail-address, eg. "%1" common en Domain name for mail address, e
domestic common en Domestic domestic common en Domestic
dominica common en DOMINICA dominica common en DOMINICA
dominican republic common en DOMINICAN REPUBLIC dominican republic common en DOMINICAN REPUBLIC
don't show this again common en Don't show this again
done common en Done done common en Done
dos international common en DOS International dos international common en DOS International
download common en Download download common en Download

View File

@ -961,6 +961,10 @@ td.lettersearch {
.help_message { .help_message {
background-image: url(../../default/images/dialog_help.png); background-image: url(../../default/images/dialog_help.png);
} }
.info_message .discard {
float:right;
margin-top: 4px;
}
/** /**
* Message in popup * Message in popup
*/ */

View File

@ -3798,6 +3798,10 @@ div.admin-config form > table td b {
font-weight: bold; font-weight: bold;
background-image: url(../images/dialog_error.png); background-image: url(../images/dialog_error.png);
} }
.info_message .discard {
float:right;
margin-top: 4px;
}
/** /**
* Message in popup * Message in popup
*/ */

View File

@ -3784,6 +3784,10 @@ div.admin-config form > table td b {
font-weight: bold; font-weight: bold;
background-image: url(../images/dialog_error.png); background-image: url(../images/dialog_error.png);
} }
.info_message .discard {
float:right;
margin-top: 4px;
}
/** /**
* Message in popup * Message in popup
*/ */

View File

@ -487,7 +487,10 @@ div.admin-config form > table {
font-weight: bold; font-weight: bold;
background-image: url(../images/dialog_error.png); background-image: url(../images/dialog_error.png);
} }
.info_message .discard {
float:right;
margin-top: 4px;
}
/** /**
* Message in popup * Message in popup
*/ */