From e39005ec736e33f77d2e665ba69726714dce01a8 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 14 Aug 2015 09:49:57 +0000 Subject: [PATCH] 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 --- phpgwapi/js/jsapi/egw_message.js | 68 ++++++++++++++++++-- phpgwapi/templates/idots/css/traditional.css | 4 ++ pixelegg/css/mobile.css | 4 ++ pixelegg/css/pixelegg.css | 4 ++ pixelegg/less/layout_dialog.less | 5 +- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/phpgwapi/js/jsapi/egw_message.js b/phpgwapi/js/jsapi/egw_message.js index 87fef38f07..1c4798ecda 100644 --- a/phpgwapi/js/jsapi/egw_message.js +++ b/phpgwapi/js/jsapi/egw_message.js @@ -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) diff --git a/phpgwapi/templates/idots/css/traditional.css b/phpgwapi/templates/idots/css/traditional.css index 775a29fd7a..e7f8eb3beb 100755 --- a/phpgwapi/templates/idots/css/traditional.css +++ b/phpgwapi/templates/idots/css/traditional.css @@ -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 */ diff --git a/pixelegg/css/mobile.css b/pixelegg/css/mobile.css index 726c051aa6..dc076bf7a3 100644 --- a/pixelegg/css/mobile.css +++ b/pixelegg/css/mobile.css @@ -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 */ diff --git a/pixelegg/css/pixelegg.css b/pixelegg/css/pixelegg.css index 0dafb2144d..8d47b88dbb 100644 --- a/pixelegg/css/pixelegg.css +++ b/pixelegg/css/pixelegg.css @@ -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 */ diff --git a/pixelegg/less/layout_dialog.less b/pixelegg/less/layout_dialog.less index 9870323d6d..35a7db8ea0 100755 --- a/pixelegg/less/layout_dialog.less +++ b/pixelegg/less/layout_dialog.less @@ -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 */