2006-09-07 09:04:15 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare - Notifications
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package notifications
|
|
|
|
* @subpackage ajaxpoup
|
|
|
|
* @link http://www.egroupware.org
|
2009-04-03 22:17:22 +02:00
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>
|
2006-09-25 12:20:46 +02:00
|
|
|
* @version $Id$
|
2006-09-07 09:04:15 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-14 15:43:16 +02:00
|
|
|
var notifymessages = {};
|
2011-11-28 18:42:35 +01:00
|
|
|
var EGW_BROWSER_NOTIFY_ALLOWED = 0;
|
2008-06-02 19:48:31 +02:00
|
|
|
|
2009-04-06 23:46:11 +02:00
|
|
|
function egwpopup_init(_i) {
|
|
|
|
window.setTimeout("egwpopup_refresh(" + _i + ");", 1000);
|
2006-09-07 09:04:15 +02:00
|
|
|
}
|
|
|
|
|
2009-04-06 23:46:11 +02:00
|
|
|
function egwpopup_setTimeout(_i) {
|
|
|
|
window.setTimeout("egwpopup_refresh(" + _i + ");", _i*1000);
|
2006-09-07 09:04:15 +02:00
|
|
|
}
|
2009-04-06 23:46:11 +02:00
|
|
|
function egwpopup_refresh(_i) {
|
2011-11-28 18:42:35 +01:00
|
|
|
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)}};
|
2009-04-06 23:46:11 +02:00
|
|
|
egwpopup_setTimeout(_i);
|
2006-09-07 09:04:15 +02:00
|
|
|
}
|
|
|
|
|
2011-11-28 18:42:35 +01:00
|
|
|
/**
|
|
|
|
* Check to see if browser supports / allows desktop notifications
|
|
|
|
*/
|
|
|
|
function check_browser_notify() {
|
|
|
|
return window.webkitNotifications && window.webkitNotifications.checkPermission() == EGW_BROWSER_NOTIFY_ALLOWED;
|
|
|
|
}
|
|
|
|
|
2009-02-23 21:45:31 +01:00
|
|
|
function egwpopup_display() {
|
|
|
|
var egwpopup;
|
|
|
|
var egwpopup_message;
|
2008-06-02 19:48:31 +02:00
|
|
|
var Browserwidth;
|
|
|
|
var Browserheight;
|
2009-02-23 21:45:31 +01:00
|
|
|
var egwpopup_ok_button;
|
|
|
|
egwpopup = document.getElementById("egwpopup");
|
|
|
|
egwpopup_message = document.getElementById("egwpopup_message");
|
2009-03-04 21:50:06 +01:00
|
|
|
egwpopup_ok_button = document.getElementById("egwpopup_ok_button");
|
|
|
|
egwpopup.style.display = "block";
|
2009-02-23 21:45:31 +01:00
|
|
|
egwpopup.style.position = "absolute";
|
|
|
|
egwpopup.style.width = "500px";
|
2008-06-02 19:48:31 +02:00
|
|
|
Browserwidth = (window.innerWidth || document.body.clientWidth || 640)
|
|
|
|
Browserheight = (window.innerHeight || document.body.clientHeight || 480)
|
2009-02-23 21:45:31 +01:00
|
|
|
egwpopup.style.left = (Browserwidth/2 - 250) + "px";
|
|
|
|
egwpopup.style.top = (Browserheight/4) + "px";
|
|
|
|
egwpopup_message.style.maxHeight = (Browserheight/2) + "px";
|
2011-04-14 15:43:16 +02:00
|
|
|
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) + ")";
|
2007-11-22 09:29:16 +01:00
|
|
|
} else {
|
2009-02-23 21:45:31 +01:00
|
|
|
egwpopup_ok_button.value = "OK";
|
2007-11-22 09:29:16 +01:00
|
|
|
}
|
2011-11-28 18:42:35 +01:00
|
|
|
if(window.webkitNotifications && window.webkitNotifications.checkPermission() != EGW_BROWSER_NOTIFY_ALLOWED &&
|
|
|
|
jQuery('#desktop_perms').length == 0)
|
|
|
|
{
|
2011-11-30 20:50:25 +01:00
|
|
|
var label = 'Desktop notifications';
|
|
|
|
try {
|
|
|
|
if(egw) label = egw.lang(label);
|
|
|
|
} catch(err) {}
|
|
|
|
var desktop_button = jQuery('<button id="desktop_perms">' + label + '</button>')
|
2011-11-28 18:42:35 +01:00
|
|
|
.click(function() {
|
|
|
|
window.webkitNotifications.requestPermission();
|
|
|
|
jQuery(this).hide();
|
|
|
|
});
|
|
|
|
desktop_button.appendTo(jQuery(egwpopup_ok_button).parent());
|
|
|
|
}
|
2007-11-22 09:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function notificationbell_switch(mode) {
|
|
|
|
var notificationbell;
|
|
|
|
notificationbell = document.getElementById("notificationbell");
|
|
|
|
if(mode == "active") {
|
|
|
|
notificationbell.style.display = "inline";
|
|
|
|
} else {
|
|
|
|
notificationbell.style.display = "none";
|
|
|
|
}
|
2006-09-07 09:04:15 +02:00
|
|
|
}
|
|
|
|
|
2009-02-23 21:45:31 +01:00
|
|
|
function egwpopup_button_ok() {
|
|
|
|
var egwpopup;
|
|
|
|
var egwpopup_message;
|
|
|
|
egwpopup = document.getElementById("egwpopup");
|
|
|
|
egwpopup_message = document.getElementById("egwpopup_message");
|
2009-03-04 21:50:06 +01:00
|
|
|
egwpopup_message.scrollTop = 0;
|
2011-04-14 15:43:16 +02:00
|
|
|
|
|
|
|
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) {
|
2009-02-23 21:45:31 +01:00
|
|
|
egwpopup.style.display = "none";
|
|
|
|
egwpopup_message.innerHTML = "";
|
2007-11-22 09:29:16 +01:00
|
|
|
notificationbell_switch("inactive");
|
2011-04-14 15:43:16 +02:00
|
|
|
} else {
|
|
|
|
egwpopup_display();
|
2007-11-22 09:29:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:51:02 +02:00
|
|
|
// Close and mark all as read
|
|
|
|
function egwpopup_button_close() {
|
2011-04-14 15:43:16 +02:00
|
|
|
var ids = new Array();
|
|
|
|
for(var id in notifymessages) {
|
|
|
|
ids.push(id);
|
2011-04-13 19:51:02 +02:00
|
|
|
}
|
2011-04-14 15:43:16 +02:00
|
|
|
xajax_doXMLHTTP("notifications.notifications_ajax.confirm_message", ids);
|
|
|
|
|
|
|
|
notifymessages = {};
|
2011-04-13 19:51:02 +02:00
|
|
|
var egwpopup = document.getElementById("egwpopup");
|
|
|
|
var egwpopup_message = document.getElementById("egwpopup_message");
|
|
|
|
egwpopup.style.display = "none";
|
|
|
|
egwpopup_message.innerHTML = "";
|
|
|
|
notificationbell_switch("inactive");
|
|
|
|
}
|
|
|
|
|
2011-11-28 18:42:35 +01:00
|
|
|
function append_notification_message(_id, _message, _browser_notify) {
|
|
|
|
|
|
|
|
if(!check_browser_notify() || typeof notifymessages[_id] != 'undefined')
|
|
|
|
{
|
|
|
|
notifymessages[_id] = _message;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Prevent the same thing popping up multiple times
|
2011-04-14 15:43:16 +02:00
|
|
|
notifymessages[_id] = _message;
|
2011-11-28 18:42:35 +01:00
|
|
|
|
|
|
|
// Notification API
|
2011-12-05 16:37:50 +01:00
|
|
|
if(_browser_notify)
|
|
|
|
{
|
2012-11-14 00:07:13 +01:00
|
|
|
var notice;
|
|
|
|
if(webkitNotifications.createHTMLNotification)
|
|
|
|
{
|
|
|
|
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])
|
|
|
|
{
|
|
|
|
_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();
|
|
|
|
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();
|
|
|
|
}
|
2011-12-05 16:37:50 +01:00
|
|
|
}
|
2011-04-13 19:51:02 +02:00
|
|
|
}
|