mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:19:00 +01:00
get notifications-popup ready for content-security, install as object in app.notifications and use data-poll-intervall of script tag to pass poll frequency
This commit is contained in:
parent
5842f5fd07
commit
4ed52a2b16
@ -7,16 +7,13 @@
|
||||
* @subpackage ajaxpopup
|
||||
* @link http://www.egroupware.org
|
||||
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ajax methods for notifications
|
||||
*/
|
||||
class notifications_ajax {
|
||||
public $public_functions = array(
|
||||
'get_notification' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Appname
|
||||
*/
|
||||
@ -108,12 +105,6 @@ class notifications_ajax {
|
||||
$this->db = $GLOBALS['egw']->db;
|
||||
}
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*
|
||||
*/
|
||||
public function __destruct() {}
|
||||
|
||||
/**
|
||||
* public AJAX trigger function to be called by the JavaScript client
|
||||
*
|
||||
@ -283,20 +274,20 @@ class notifications_ajax {
|
||||
|
||||
$message = 'data:text/html;charset=' . translation::charset() .';base64,'.base64_encode($message);
|
||||
}
|
||||
$this->response->addScriptCall('append_notification_message',$notification['notify_id'],$notification['notify_message'],$message);
|
||||
$this->response->addScriptCall('app.notifications.append',$notification['notify_id'],$notification['notify_message'],$message);
|
||||
}
|
||||
|
||||
switch($this->preferences[self::_appname]['egwpopup_verbosity']) {
|
||||
case 'low':
|
||||
$this->response->addScript('notificationbell_switch("active");');
|
||||
$this->response->addScriptCall('app.notifications.bell', 'active');
|
||||
break;
|
||||
case 'high':
|
||||
$this->response->addAlert(lang('eGroupWare has notifications for you'));
|
||||
$this->response->addScript('egwpopup_display();');
|
||||
$this->response->addAlert(lang('EGroupware has notifications for you'));
|
||||
$this->response->addScriptCall('app.notifications.display');
|
||||
break;
|
||||
case 'medium':
|
||||
default:
|
||||
$this->response->addScript('egwpopup_display();');
|
||||
$this->response->addScriptCall('app.notifications.display');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -12,24 +12,23 @@
|
||||
* @author Cornelius Weiss <nelius@cwtech.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
$notification_config = config::read('notifications');
|
||||
if ($GLOBALS['egw_info']['user']['apps']['notifications'])
|
||||
{
|
||||
$GLOBALS['egw']->translation->add_app('notifications');
|
||||
$notification_config = config::read('notifications');
|
||||
translation::add_app('notifications');
|
||||
$popup_poll_interval = empty($notification_config['popup_poll_interval']) ? 60 : $notification_config['popup_poll_interval'];
|
||||
echo '<script src="'. $GLOBALS['egw_info']['server']['webserver_url']. '/notifications/js/notificationajaxpopup.js?'.
|
||||
filemtime(EGW_SERVER_ROOT.'/notifications/js/notificationajaxpopup.js'). '" type="text/javascript"></script>';
|
||||
echo '<script type="text/javascript">var lab = egw_LAB || $LAB; lab.wait(function(){egwpopup_init("'.$popup_poll_interval.'");});</script>';
|
||||
filemtime(EGW_SERVER_ROOT.'/notifications/js/notificationajaxpopup.js'). '" type="text/javascript" id="notifications_script_id" data-poll-interval="'.$popup_poll_interval.'"></script>';
|
||||
echo '
|
||||
<div id="egwpopup" style="display: none; z-index: 999;">
|
||||
<div id="egwpopup_header">'.lang('Notification'). '<span style="float:right;">'.
|
||||
html::submit_button('egwpopup_close_button', 'X', 'egwpopup_button_close();',true,'', 'close.button') .
|
||||
html::submit_button('egwpopup_close_button', 'X', '', true, 'id="egwpopup_close_button"', 'close.button') .
|
||||
'</span></div>
|
||||
<div id="egwpopup_message"></div>
|
||||
<div id="egwpopup_footer">
|
||||
<input id="egwpopup_ok_button" type="submit" value="'. lang('ok'). '" onClick="egwpopup_button_ok();">
|
||||
<input id="egwpopup_ok_button" type="button" value="'. lang('ok'). '">
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
unset($notification_config);
|
||||
}
|
||||
unset($notification_config);
|
||||
|
@ -1,174 +1,225 @@
|
||||
/**
|
||||
* eGroupWare - Notifications
|
||||
* EGroupware Notifications - clientside javascript
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package notifications
|
||||
* @subpackage ajaxpoup
|
||||
* @link http://www.egroupware.org
|
||||
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>
|
||||
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>, Ralf Becker <rb@stylite.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
var notifymessages = {};
|
||||
var EGW_BROWSER_NOTIFY_ALLOWED = 0;
|
||||
|
||||
function egwpopup_init(_i) {
|
||||
window.setTimeout("egwpopup_refresh(" + _i + ");", 1000);
|
||||
}
|
||||
|
||||
function egwpopup_setTimeout(_i) {
|
||||
window.setTimeout("egwpopup_refresh(" + _i + ");", _i*1000);
|
||||
}
|
||||
function egwpopup_refresh(_i) {
|
||||
var request = xajax_doXMLHTTP("notifications.notifications_ajax.get_notifications", check_browser_notify());
|
||||
request.request.error = function(_xmlhttp,_err){if(console) {console.log(request);console.log(_err)}};
|
||||
egwpopup_setTimeout(_i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if browser supports / allows desktop notifications
|
||||
* Installs app.notifications used to poll notifications from server and display them
|
||||
*/
|
||||
function check_browser_notify() {
|
||||
return window.webkitNotifications && window.webkitNotifications.checkPermission() == EGW_BROWSER_NOTIFY_ALLOWED;
|
||||
}
|
||||
|
||||
function egwpopup_display() {
|
||||
var egwpopup;
|
||||
var egwpopup_message;
|
||||
var Browserwidth;
|
||||
var Browserheight;
|
||||
var egwpopup_ok_button;
|
||||
egwpopup = document.getElementById("egwpopup");
|
||||
egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup_ok_button = document.getElementById("egwpopup_ok_button");
|
||||
egwpopup.style.display = "block";
|
||||
egwpopup.style.position = "absolute";
|
||||
egwpopup.style.width = "500px";
|
||||
Browserwidth = (window.innerWidth || document.body.clientWidth || 640)
|
||||
Browserheight = (window.innerHeight || document.body.clientHeight || 480)
|
||||
egwpopup.style.left = (Browserwidth/2 - 250) + "px";
|
||||
egwpopup.style.top = (Browserheight/4) + "px";
|
||||
egwpopup_message.style.maxHeight = (Browserheight/2) + "px";
|
||||
for(var show in notifymessages) break;
|
||||
egwpopup_message.innerHTML = notifymessages[show];
|
||||
var num = 0;
|
||||
for(var id in notifymessages) ++num;
|
||||
if(num-1 > 0 ) {
|
||||
egwpopup_ok_button.value = "OK (" + (num-1) + ")";
|
||||
} else {
|
||||
egwpopup_ok_button.value = "OK";
|
||||
}
|
||||
if(window.webkitNotifications && window.webkitNotifications.checkPermission() != EGW_BROWSER_NOTIFY_ALLOWED &&
|
||||
jQuery('#desktop_perms').length == 0)
|
||||
{
|
||||
var label = 'Desktop notifications';
|
||||
try {
|
||||
if(egw) label = egw.lang(label);
|
||||
} catch(err) {}
|
||||
var desktop_button = jQuery('<button id="desktop_perms">' + label + '</button>')
|
||||
.click(function() {
|
||||
window.webkitNotifications.requestPermission();
|
||||
jQuery(this).hide();
|
||||
});
|
||||
desktop_button.appendTo(jQuery(egwpopup_ok_button).parent());
|
||||
}
|
||||
}
|
||||
|
||||
function notificationbell_switch(mode) {
|
||||
var notificationbell;
|
||||
notificationbell = document.getElementById("notificationbell");
|
||||
if(mode == "active") {
|
||||
notificationbell.style.display = "inline";
|
||||
} else {
|
||||
notificationbell.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
function egwpopup_button_ok() {
|
||||
var egwpopup;
|
||||
var egwpopup_message;
|
||||
egwpopup = document.getElementById("egwpopup");
|
||||
egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup_message.scrollTop = 0;
|
||||
|
||||
for(var confirmed in notifymessages) break;
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", confirmed);
|
||||
delete notifymessages[confirmed];
|
||||
(function()
|
||||
{
|
||||
var notifymessages = {};
|
||||
var EGW_BROWSER_NOTIFY_ALLOWED = 0;
|
||||
|
||||
for(var id in notifymessages) break;
|
||||
if (id == undefined) {
|
||||
/**
|
||||
* Constructor inits polling and installs handlers, polling frequence is passed via data-poll-interval of script tag
|
||||
*/
|
||||
function notifications() {
|
||||
var notification_script = document.getElementById('notifications_script_id');
|
||||
var popup_poll_interval = notification_script && notification_script.getAttribute('data-poll-interval');
|
||||
this.setTimeout(popup_poll_interval || 60);
|
||||
var self = this;
|
||||
jQuery('#egwpopup_ok_button').click(function() { self.button_ok.apply(self); });
|
||||
jQuery('#egwpopup_close_button').click(function() { self.button_close.apply(self); });
|
||||
jQuery('#notificationbell').click(function() { self.display.apply(self); });
|
||||
};
|
||||
|
||||
/**
|
||||
* Poll server in given frequency via Ajax
|
||||
* @param _i
|
||||
*/
|
||||
notifications.prototype.setTimeout = function(_i) {
|
||||
var self = this;
|
||||
window.setTimeout(function(){
|
||||
var request = xajax_doXMLHTTP("notifications.notifications_ajax.get_notifications", self.check_browser_notify());
|
||||
request.request.error = function(_xmlhttp,_err){
|
||||
if(console) {
|
||||
console.log(request);
|
||||
console.log(_err);
|
||||
}
|
||||
};
|
||||
self.setTimeout(_i);
|
||||
}, _i*1000);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check to see if browser supports / allows desktop notifications
|
||||
*/
|
||||
notifications.prototype.check_browser_notify = function() {
|
||||
return window.webkitNotifications && window.webkitNotifications.checkPermission() == EGW_BROWSER_NOTIFY_ALLOWED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Display notifications window
|
||||
*/
|
||||
notifications.prototype.display = function() {
|
||||
var egwpopup;
|
||||
var egwpopup_message;
|
||||
var Browserwidth;
|
||||
var Browserheight;
|
||||
var egwpopup_ok_button;
|
||||
egwpopup = document.getElementById("egwpopup");
|
||||
egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup_ok_button = document.getElementById("egwpopup_ok_button");
|
||||
egwpopup.style.display = "block";
|
||||
egwpopup.style.position = "absolute";
|
||||
egwpopup.style.width = "500px";
|
||||
Browserwidth = (window.innerWidth || document.body.clientWidth || 640);
|
||||
Browserheight = (window.innerHeight || document.body.clientHeight || 480);
|
||||
egwpopup.style.left = (Browserwidth/2 - 250) + "px";
|
||||
egwpopup.style.top = (Browserheight/4) + "px";
|
||||
egwpopup_message.style.maxHeight = (Browserheight/2) + "px";
|
||||
for(var show in notifymessages) break;
|
||||
egwpopup_message.innerHTML = notifymessages[show];
|
||||
var num = 0;
|
||||
for(var id in notifymessages) ++num;
|
||||
if(num-1 > 0 ) {
|
||||
egwpopup_ok_button.value = "OK (" + (num-1) + ")";
|
||||
} else {
|
||||
egwpopup_ok_button.value = "OK";
|
||||
}
|
||||
if(window.webkitNotifications && window.webkitNotifications.checkPermission() != EGW_BROWSER_NOTIFY_ALLOWED &&
|
||||
jQuery('#desktop_perms').length == 0)
|
||||
{
|
||||
var label = 'Desktop notifications';
|
||||
try {
|
||||
if(egw) label = egw.lang(label);
|
||||
} catch(err) {}
|
||||
var desktop_button = jQuery('<button id="desktop_perms">' + label + '</button>')
|
||||
.click(function() {
|
||||
window.webkitNotifications.requestPermission();
|
||||
jQuery(this).hide();
|
||||
});
|
||||
desktop_button.appendTo(jQuery(egwpopup_ok_button).parent());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Display or hide notifcation-bell
|
||||
*
|
||||
* @param String mode "active"
|
||||
*/
|
||||
notifications.prototype.bell = function(mode) {
|
||||
var notificationbell;
|
||||
notificationbell = document.getElementById("notificationbell");
|
||||
if(mode == "active") {
|
||||
notificationbell.style.display = "inline";
|
||||
} else {
|
||||
notificationbell.style.display = "none";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for OK button: confirms message on server and hides display
|
||||
*/
|
||||
notifications.prototype.button_ok = function() {
|
||||
var egwpopup;
|
||||
var egwpopup_message;
|
||||
egwpopup = document.getElementById("egwpopup");
|
||||
egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup_message.scrollTop = 0;
|
||||
|
||||
for(var confirmed in notifymessages) break;
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", confirmed);
|
||||
delete notifymessages[confirmed];
|
||||
|
||||
for(var id in notifymessages) break;
|
||||
if (id == undefined) {
|
||||
egwpopup.style.display = "none";
|
||||
egwpopup_message.innerHTML = "";
|
||||
this.bell("inactive");
|
||||
} else {
|
||||
this.display();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for close button: close and mark all as read
|
||||
*/
|
||||
notifications.prototype.button_close = function() {
|
||||
var ids = new Array();
|
||||
for(var id in notifymessages) {
|
||||
ids.push(id);
|
||||
}
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", ids);
|
||||
|
||||
notifymessages = {};
|
||||
var egwpopup = document.getElementById("egwpopup");
|
||||
var egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup.style.display = "none";
|
||||
egwpopup_message.innerHTML = "";
|
||||
notificationbell_switch("inactive");
|
||||
} else {
|
||||
egwpopup_display();
|
||||
}
|
||||
}
|
||||
|
||||
// Close and mark all as read
|
||||
function egwpopup_button_close() {
|
||||
var ids = new Array();
|
||||
for(var id in notifymessages) {
|
||||
ids.push(id);
|
||||
}
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", ids);
|
||||
|
||||
notifymessages = {};
|
||||
var egwpopup = document.getElementById("egwpopup");
|
||||
var egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup.style.display = "none";
|
||||
egwpopup_message.innerHTML = "";
|
||||
notificationbell_switch("inactive");
|
||||
}
|
||||
|
||||
function append_notification_message(_id, _message, _browser_notify) {
|
||||
|
||||
if(!check_browser_notify() || typeof notifymessages[_id] != 'undefined')
|
||||
{
|
||||
this.bell("inactive");
|
||||
};
|
||||
|
||||
/**
|
||||
* Add message to internal display-queue
|
||||
*
|
||||
* @param _id
|
||||
* @param _message
|
||||
* @param _browser_notify
|
||||
*/
|
||||
notifications.prototype.append = function(_id, _message, _browser_notify) {
|
||||
if(!this.check_browser_notify() || typeof notifymessages[_id] != 'undefined')
|
||||
{
|
||||
notifymessages[_id] = _message;
|
||||
return;
|
||||
}
|
||||
// Prevent the same thing popping up multiple times
|
||||
notifymessages[_id] = _message;
|
||||
return;
|
||||
}
|
||||
// Prevent the same thing popping up multiple times
|
||||
notifymessages[_id] = _message;
|
||||
|
||||
// Notification API
|
||||
if(_browser_notify)
|
||||
{
|
||||
var notice;
|
||||
if(webkitNotifications.createHTMLNotification)
|
||||
|
||||
// Notification API
|
||||
if(_browser_notify)
|
||||
{
|
||||
notice = webkitNotifications.createHTMLNotification(_browser_notify);
|
||||
}
|
||||
else if (webkitNotifications.createNotification)
|
||||
{
|
||||
// Pull the subject of the messasge, if possible
|
||||
var message = /<b>(.*?)<\/b>/.exec(_message);
|
||||
if(message && message[1])
|
||||
var notice = null;
|
||||
if(webkitNotifications.createHTMLNotification)
|
||||
{
|
||||
_message = message[1];
|
||||
notice = webkitNotifications.createHTMLNotification(_browser_notify);
|
||||
}
|
||||
else
|
||||
else if (webkitNotifications.createNotification)
|
||||
{
|
||||
_message = _message.replace(/<(?:.|\n)*?>/gm, '');
|
||||
// Pull the subject of the messasge, if possible
|
||||
var message = /<b>(.*?)<\/b>/.exec(_message);
|
||||
if(message && message[1])
|
||||
{
|
||||
_message = message[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
_message = _message.replace(/<(?:.|\n)*?>/gm, '');
|
||||
}
|
||||
notice = webkitNotifications.createNotification('', "Egroupware",_message);
|
||||
|
||||
// When they click, bring up the popup for full info
|
||||
notice.onclick = function() {
|
||||
window.focus();
|
||||
window.app.notifications.display();
|
||||
this.close();
|
||||
};
|
||||
}
|
||||
notice = webkitNotifications.createNotification('', "Egroupware",_message);
|
||||
|
||||
// When they click, bring up the popup for full info
|
||||
notice.onclick = function() {
|
||||
window.focus();
|
||||
egwpopup_display();
|
||||
this.close();
|
||||
if(notice)
|
||||
{
|
||||
notice.ondisplay = function() {
|
||||
// Confirm when user gets to see it - no close needed
|
||||
// Wait a bit to let it load first, or it might not be there when requested.
|
||||
window.setTimeout( function() {
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", _id);
|
||||
}, 2000);
|
||||
};
|
||||
notice.show();
|
||||
}
|
||||
}
|
||||
if(notice)
|
||||
{
|
||||
notice.ondisplay = function() {
|
||||
// Confirm when user gets to see it - no close needed
|
||||
// Wait a bit to let it load first, or it might not be there when requested.
|
||||
window.setTimeout( function() {
|
||||
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", _id);
|
||||
}, 2000);
|
||||
};
|
||||
notice.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var lab = egw_LAB || $LAB;
|
||||
var self = notifications;
|
||||
lab.wait(function(){
|
||||
if (typeof window.app == 'undefined') window.app = {};
|
||||
window.app.notifications = new self();
|
||||
});
|
||||
})();
|
||||
|
@ -510,15 +510,8 @@ abstract class egw_framework
|
||||
*/
|
||||
protected static function _get_notification_bell()
|
||||
{
|
||||
return html::div(
|
||||
html::a_href(
|
||||
html::image('notifications','notificationbell',lang('notifications')),
|
||||
'javascript: egwpopup_display();'
|
||||
),
|
||||
'id="notificationbell"', // options
|
||||
'', // class
|
||||
'display: none' //style
|
||||
);
|
||||
return html::image('notifications', 'notificationbell', lang('notifications'),
|
||||
'id="notificationbell" style="display: none"');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user