mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +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,37 +1,64 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs app.notifications used to poll notifications from server and display them
|
||||
*/
|
||||
(function()
|
||||
{
|
||||
var notifymessages = {};
|
||||
var EGW_BROWSER_NOTIFY_ALLOWED = 0;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function check_browser_notify() {
|
||||
notifications.prototype.check_browser_notify = function() {
|
||||
return window.webkitNotifications && window.webkitNotifications.checkPermission() == EGW_BROWSER_NOTIFY_ALLOWED;
|
||||
}
|
||||
};
|
||||
|
||||
function egwpopup_display() {
|
||||
/**
|
||||
* Display notifications window
|
||||
*/
|
||||
notifications.prototype.display = function() {
|
||||
var egwpopup;
|
||||
var egwpopup_message;
|
||||
var Browserwidth;
|
||||
@ -43,8 +70,8 @@ function egwpopup_display() {
|
||||
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)
|
||||
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";
|
||||
@ -71,9 +98,14 @@ function egwpopup_display() {
|
||||
});
|
||||
desktop_button.appendTo(jQuery(egwpopup_ok_button).parent());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function notificationbell_switch(mode) {
|
||||
/**
|
||||
* Display or hide notifcation-bell
|
||||
*
|
||||
* @param String mode "active"
|
||||
*/
|
||||
notifications.prototype.bell = function(mode) {
|
||||
var notificationbell;
|
||||
notificationbell = document.getElementById("notificationbell");
|
||||
if(mode == "active") {
|
||||
@ -81,9 +113,12 @@ function notificationbell_switch(mode) {
|
||||
} else {
|
||||
notificationbell.style.display = "none";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function egwpopup_button_ok() {
|
||||
/**
|
||||
* 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");
|
||||
@ -98,14 +133,16 @@ function egwpopup_button_ok() {
|
||||
if (id == undefined) {
|
||||
egwpopup.style.display = "none";
|
||||
egwpopup_message.innerHTML = "";
|
||||
notificationbell_switch("inactive");
|
||||
this.bell("inactive");
|
||||
} else {
|
||||
egwpopup_display();
|
||||
this.display();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Close and mark all as read
|
||||
function egwpopup_button_close() {
|
||||
/**
|
||||
* 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);
|
||||
@ -117,12 +154,18 @@ function egwpopup_button_close() {
|
||||
var egwpopup_message = document.getElementById("egwpopup_message");
|
||||
egwpopup.style.display = "none";
|
||||
egwpopup_message.innerHTML = "";
|
||||
notificationbell_switch("inactive");
|
||||
}
|
||||
this.bell("inactive");
|
||||
};
|
||||
|
||||
function append_notification_message(_id, _message, _browser_notify) {
|
||||
|
||||
if(!check_browser_notify() || typeof notifymessages[_id] != 'undefined')
|
||||
/**
|
||||
* 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;
|
||||
@ -133,7 +176,7 @@ function append_notification_message(_id, _message, _browser_notify) {
|
||||
// Notification API
|
||||
if(_browser_notify)
|
||||
{
|
||||
var notice;
|
||||
var notice = null;
|
||||
if(webkitNotifications.createHTMLNotification)
|
||||
{
|
||||
notice = webkitNotifications.createHTMLNotification(_browser_notify);
|
||||
@ -155,9 +198,9 @@ function append_notification_message(_id, _message, _browser_notify) {
|
||||
// When they click, bring up the popup for full info
|
||||
notice.onclick = function() {
|
||||
window.focus();
|
||||
egwpopup_display();
|
||||
window.app.notifications.display();
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
if(notice)
|
||||
{
|
||||
@ -171,4 +214,12 @@ function append_notification_message(_id, _message, _browser_notify) {
|
||||
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