2006-09-07 09:04:15 +02:00
|
|
|
/**
|
2013-07-22 15:29:20 +02:00
|
|
|
* EGroupware Notifications - clientside javascript
|
2014-10-09 10:21:40 +02:00
|
|
|
*
|
2006-09-07 09:04:15 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package notifications
|
|
|
|
* @subpackage ajaxpoup
|
|
|
|
* @link http://www.egroupware.org
|
2013-07-22 15:29:20 +02:00
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>, Ralf Becker <rb@stylite.de>
|
2006-09-25 12:20:46 +02:00
|
|
|
* @version $Id$
|
2006-09-07 09:04:15 +02:00
|
|
|
*/
|
|
|
|
|
2011-11-24 00:48:58 +01:00
|
|
|
/**
|
2013-07-22 15:29:20 +02:00
|
|
|
* Installs app.notifications used to poll notifications from server and display them
|
2011-11-24 00:48:58 +01:00
|
|
|
*/
|
2013-07-22 15:29:20 +02:00
|
|
|
(function()
|
2014-10-09 10:21:40 +02:00
|
|
|
{
|
2013-07-22 15:29:20 +02:00
|
|
|
var notifymessages = {};
|
2017-09-18 18:47:44 +02:00
|
|
|
|
2020-08-19 15:08:59 +02:00
|
|
|
var _currentRawData = [];
|
2017-09-18 18:47:44 +02:00
|
|
|
/**
|
|
|
|
* time range label today
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var TIME_LABEL_TODAY = 0;
|
2017-09-18 18:47:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* time range label yesterday
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var TIME_LABEL_YESTERDAY = 1;
|
2017-09-18 18:47:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* time range label this month
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var TIME_LABEL_THIS_MONTH = 2;
|
2017-09-18 18:47:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* time range label last month
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var TIME_LABEL_LAST_MONTH = 3;
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2018-06-19 16:03:10 +02:00
|
|
|
/**
|
|
|
|
* Heigh priorority action for notifing about an entry.
|
|
|
|
* Action: It pops up the entry once
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var EGW_PR_NOTIFY_HEIGH = 1;
|
2018-06-19 16:03:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Medium priority for notifing about an entry
|
|
|
|
* Action: Not defined
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var EGW_PR_NOTIFY_MEDIUM = 2;
|
2018-06-19 16:03:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Low priority for notifing about an entry
|
|
|
|
* Action: Not defined
|
|
|
|
* @type Number
|
|
|
|
*/
|
2019-03-18 15:27:12 +01:00
|
|
|
var EGW_PR_NOTIFY_LOW = 3;
|
2018-06-19 16:03:10 +02:00
|
|
|
|
2018-09-06 15:27:52 +02:00
|
|
|
/**
|
|
|
|
* Interval set by user
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
var POLL_INTERVAL = 60;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current interval set by system (gets increased by factor of 2 in case of request failure)
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
var CURRENT_INTERVAL = 60;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current timeout ID
|
|
|
|
* @type Number
|
|
|
|
*/
|
|
|
|
var TIMEOUT = 0;
|
2018-09-06 15:40:25 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* 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');
|
2018-09-06 15:27:52 +02:00
|
|
|
CURRENT_INTERVAL = POLL_INTERVAL = notification_script && notification_script.getAttribute('data-poll-interval');
|
|
|
|
TIMEOUT = this.setTimeout(POLL_INTERVAL || 60);
|
2014-10-09 10:21:40 +02:00
|
|
|
jQuery('#notificationbell').click(jQuery.proxy(this.display, this));
|
2021-03-31 16:45:48 +02:00
|
|
|
|
|
|
|
// add click handler for refreshing Notifications
|
|
|
|
let $egwpopup_header = jQuery('#egwpopup_header')
|
|
|
|
.css({cursor:'pointer'})
|
|
|
|
.attr('title', egw.lang('Refresh Notifications'))
|
|
|
|
.click(jQuery.proxy(this.run_notifications, this));
|
|
|
|
$egwpopup_header.children('.button_right_toggle').attr('title', egw.lang('close'));
|
|
|
|
|
2014-10-09 10:21:40 +02:00
|
|
|
// query notifictions now
|
2018-09-06 15:27:52 +02:00
|
|
|
this.run_notifications();
|
|
|
|
|
2020-07-27 14:44:44 +02:00
|
|
|
this.filter = '';
|
2021-03-12 10:22:09 +01:00
|
|
|
// total number of notifications
|
|
|
|
this.total = 0;
|
2018-09-06 15:27:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
notifications.prototype.run_notifications = function ()
|
|
|
|
{
|
|
|
|
var self = this;
|
2020-07-22 13:17:54 +02:00
|
|
|
this.get_notifications().then(function(_data){
|
2018-09-06 15:27:52 +02:00
|
|
|
window.clearTimeout(TIMEOUT);
|
2020-07-22 13:17:54 +02:00
|
|
|
if (_data && _data.isPushServer) return;
|
2018-09-06 15:27:52 +02:00
|
|
|
self.check_browser_notify();
|
|
|
|
TIMEOUT = self.setTimeout(POLL_INTERVAL);
|
|
|
|
},
|
|
|
|
function(){
|
|
|
|
window.clearTimeout(TIMEOUT);
|
|
|
|
CURRENT_INTERVAL *= 2;
|
|
|
|
self.setTimeout(CURRENT_INTERVAL);
|
|
|
|
});
|
2014-10-09 10:21:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Poll server for new notifications
|
|
|
|
*/
|
|
|
|
notifications.prototype.get_notifications = function()
|
|
|
|
{
|
2018-09-06 15:27:52 +02:00
|
|
|
var self = this;
|
|
|
|
return new Promise (function(_resolve, _reject){
|
|
|
|
egw.json(
|
|
|
|
"notifications.notifications_ajax.get_notifications",[],
|
2020-07-22 13:17:54 +02:00
|
|
|
function(_data){
|
|
|
|
_resolve(_data);
|
2018-09-06 15:27:52 +02:00
|
|
|
self.check_browser_notify()
|
|
|
|
}).sendRequest(true,'POST', function(_err){
|
2018-09-06 15:40:25 +02:00
|
|
|
if (_err && _err.statusText) egw.message(_err.statusText);
|
2018-09-06 15:27:52 +02:00
|
|
|
_reject();
|
|
|
|
});
|
|
|
|
});
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2011-04-14 15:43:16 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Poll server in given frequency via Ajax
|
|
|
|
* @param _i
|
|
|
|
*/
|
|
|
|
notifications.prototype.setTimeout = function(_i) {
|
|
|
|
var self = this;
|
2018-09-06 15:27:52 +02:00
|
|
|
return window.setTimeout(function(){
|
|
|
|
self.run_notifications();
|
2013-07-22 15:29:20 +02:00
|
|
|
}, _i*1000);
|
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Check to see if browser supports / allows desktop notifications
|
|
|
|
*/
|
|
|
|
notifications.prototype.check_browser_notify = function() {
|
2016-07-11 11:59:50 +02:00
|
|
|
return egw.checkNotification();
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2017-09-18 18:47:44 +02:00
|
|
|
/**
|
|
|
|
* This function gets created time and current time then finds out if
|
|
|
|
* the time range of the event.
|
|
|
|
*
|
|
|
|
* @param {type} _created
|
|
|
|
* @param {type} _current
|
|
|
|
*
|
|
|
|
* @returns {int} returns type of range
|
|
|
|
*/
|
|
|
|
notifications.prototype.getTimeLabel = function (_created, _current) {
|
|
|
|
var created = typeof _created == 'string'? new Date(_created): _created;
|
|
|
|
var current = new Date(_current.date);
|
|
|
|
var time_diff = (current - created) / 1000;
|
|
|
|
var result = '';
|
|
|
|
if (time_diff < current.getHours() * 3600)
|
|
|
|
{
|
|
|
|
result = TIME_LABEL_TODAY;
|
|
|
|
}
|
|
|
|
else if ((time_diff > current.getHours() * 3600) &&
|
|
|
|
(time_diff < (current.getHours() * 3600 + 86400)))
|
|
|
|
{
|
|
|
|
result = TIME_LABEL_YESTERDAY;
|
|
|
|
}
|
|
|
|
else if (current.getFullYear() == created.getFullYear() &&
|
|
|
|
(current.getMonth() - created.getMonth()) == 0 &&
|
|
|
|
time_diff > (current.getHours() * 3600 + 86400))
|
|
|
|
{
|
|
|
|
result = TIME_LABEL_THIS_MONTH;
|
|
|
|
}
|
|
|
|
else if (current.getFullYear() == created.getFullYear() &&
|
|
|
|
(current.getMonth() - created.getMonth()) == 1)
|
|
|
|
{
|
|
|
|
result = TIME_LABEL_LAST_MONTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Display notifications window
|
|
|
|
*/
|
|
|
|
notifications.prototype.display = function() {
|
2017-09-15 17:10:11 +02:00
|
|
|
// list container
|
2017-09-18 18:47:44 +02:00
|
|
|
var $egwpopup_list = jQuery("#egwpopup_list");
|
2017-11-17 11:56:36 +01:00
|
|
|
|
|
|
|
// Preserve already poped notifications
|
|
|
|
var poped = [];
|
|
|
|
$egwpopup_list.find('.egwpopup_expanded').each(function(index, item){
|
|
|
|
// store messages ids of poped messages
|
|
|
|
poped.push(item.id.replace('egwpopup_message_', ''));
|
|
|
|
});
|
2017-09-20 17:49:24 +02:00
|
|
|
// clear the list
|
|
|
|
$egwpopup_list.empty();
|
2017-09-18 18:47:44 +02:00
|
|
|
// define time label deviders
|
|
|
|
var $today = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_time_label')
|
|
|
|
.text(egw.lang('today'))
|
|
|
|
, $yesterday = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_time_label')
|
|
|
|
.text(egw.lang('yesterday'))
|
|
|
|
, $this_month = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_time_label')
|
2018-01-23 22:07:27 +01:00
|
|
|
.text(egw.lang('this month'))
|
2017-09-18 18:47:44 +02:00
|
|
|
, $last_month = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_time_label')
|
2018-01-23 22:07:27 +01:00
|
|
|
.text(egw.lang('last month'));
|
2017-09-18 18:47:44 +02:00
|
|
|
// reverse indexes to get the latest messages at the top
|
|
|
|
var indexes = Object.keys(notifymessages).reverse()
|
|
|
|
for(var index in indexes)
|
2017-05-15 17:34:27 +02:00
|
|
|
{
|
2017-09-18 18:47:44 +02:00
|
|
|
var id = indexes[index];
|
2018-03-06 18:33:42 +01:00
|
|
|
var $message, $mark, $delete, $inner_container, $nav_prev, $nav_next,
|
2017-09-18 18:47:44 +02:00
|
|
|
$more_info, $top_toolbar, $open_entry, $date, $collapse;
|
|
|
|
var message_id = 'egwpopup_message_'+id;
|
|
|
|
var time_label = this.getTimeLabel(notifymessages[id]['created'], notifymessages[id]['current']);
|
2017-05-16 18:03:50 +02:00
|
|
|
if (jQuery('#'+message_id,$egwpopup_list).length > 0)
|
|
|
|
{
|
2020-07-29 12:55:08 +02:00
|
|
|
this.update_message_status(id, notifymessages[id]['status'], true);
|
2017-05-16 18:03:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
2020-07-29 12:55:08 +02:00
|
|
|
if (this.filter && notifymessages[id]['data']['app'] != this.filter) continue;
|
2017-09-18 18:47:44 +02:00
|
|
|
// set the time labels on
|
|
|
|
switch (time_label)
|
|
|
|
{
|
|
|
|
case TIME_LABEL_TODAY:
|
|
|
|
if (!$egwpopup_list.has($today).length) $today.appendTo($egwpopup_list);
|
|
|
|
break;
|
|
|
|
case TIME_LABEL_YESTERDAY:
|
|
|
|
if (!$egwpopup_list.has($yesterday).length) $yesterday.appendTo($egwpopup_list);
|
|
|
|
break;
|
|
|
|
case TIME_LABEL_THIS_MONTH:
|
|
|
|
if (!$egwpopup_list.has($this_month).length) $this_month.appendTo($egwpopup_list);
|
|
|
|
break;
|
|
|
|
case TIME_LABEL_LAST_MONTH:
|
|
|
|
if (!$egwpopup_list.has($last_month).length) $last_month.appendTo($egwpopup_list);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-15 17:10:11 +02:00
|
|
|
// message container
|
2017-05-15 17:34:27 +02:00
|
|
|
$message = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_message')
|
2018-07-02 10:42:53 +02:00
|
|
|
.attr({
|
|
|
|
id:message_id,
|
|
|
|
'data-entryid': notifymessages[id]['data']['id'],
|
|
|
|
'data-appname': notifymessages[id]['data']['app'],
|
|
|
|
});
|
2017-09-15 17:10:11 +02:00
|
|
|
// wrapper for message content
|
|
|
|
$inner_container = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_message_inner_container')
|
|
|
|
.appendTo($message);
|
2017-09-18 18:47:44 +02:00
|
|
|
$inner_container[0].innerHTML = notifymessages[id]['message'];
|
2018-07-02 10:42:53 +02:00
|
|
|
if (notifymessages[id]['children'])
|
|
|
|
{
|
|
|
|
for (var c in notifymessages[id]['children'])
|
|
|
|
{
|
2020-08-19 15:08:59 +02:00
|
|
|
if (Object.keys(notifymessages[id]['children']).indexOf(c) < Object.keys(notifymessages[id]['children']).length-2) continue;
|
2018-07-02 10:42:53 +02:00
|
|
|
$inner_container[0].innerHTML += notifymessages[id]['children'][c]['message'];
|
|
|
|
}
|
|
|
|
}
|
2017-09-15 17:10:11 +02:00
|
|
|
$more_info = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_message_more_info')
|
|
|
|
.text(egw.lang('More info')+'...')
|
|
|
|
.appendTo($message);
|
|
|
|
// top toolbar NODE
|
|
|
|
$top_toolbar = jQuery(document.createElement('div'))
|
|
|
|
.addClass('egwpopup_message_top_toolbar');
|
|
|
|
// Date indicator NODE
|
|
|
|
$date = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_message_date')
|
|
|
|
.prependTo($top_toolbar)
|
2017-09-18 18:47:44 +02:00
|
|
|
.text(notifymessages[id]['created']);
|
2018-02-16 12:02:43 +01:00
|
|
|
if (notifymessages[id]['data']['id'] || notifymessages[id]['data']['url']) {
|
|
|
|
// OPEN entry button
|
|
|
|
$open_entry = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_message_open')
|
|
|
|
.attr('title',egw.lang('open notified entry'))
|
|
|
|
.click(jQuery.proxy(this.open_entry, this,[$message]))
|
|
|
|
.prependTo($top_toolbar);
|
|
|
|
}
|
2018-03-06 18:33:42 +01:00
|
|
|
// Previous button
|
|
|
|
$nav_prev = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_nav_prev')
|
2018-03-12 17:30:21 +01:00
|
|
|
.attr('title',egw.lang('previous'))
|
2018-03-06 18:33:42 +01:00
|
|
|
.click(jQuery.proxy(this.nav_button, this,[$message, "prev"]))
|
|
|
|
.prependTo($top_toolbar);
|
|
|
|
// Next button
|
|
|
|
$nav_next = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_nav_next')
|
2018-03-12 17:30:21 +01:00
|
|
|
.attr('title',egw.lang('next'))
|
2018-03-06 18:33:42 +01:00
|
|
|
.click(jQuery.proxy(this.nav_button, this,[$message, "next"]))
|
|
|
|
.prependTo($top_toolbar);
|
2017-09-15 17:10:11 +02:00
|
|
|
// Delete button
|
2017-05-17 14:04:31 +02:00
|
|
|
$delete = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_delete')
|
|
|
|
.attr('title',egw.lang('delete this message'))
|
|
|
|
.click(jQuery.proxy(this.button_delete, this,[$message]))
|
2017-09-15 17:10:11 +02:00
|
|
|
.prependTo($top_toolbar);
|
|
|
|
// Mark as read button
|
2017-05-17 14:04:31 +02:00
|
|
|
$mark = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_mark')
|
2017-09-15 17:10:11 +02:00
|
|
|
.prependTo($top_toolbar);
|
|
|
|
// Collapse button (close icon)
|
|
|
|
$collapse = jQuery(document.createElement('span'))
|
|
|
|
.addClass('egwpopup_collapse')
|
|
|
|
.click(jQuery.proxy(this.collapseMessage, this, [$message]))
|
|
|
|
.prependTo($top_toolbar);
|
|
|
|
|
2017-09-18 18:47:44 +02:00
|
|
|
if (notifymessages[id]['status'] != 'SEEN')
|
2017-05-17 14:04:31 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
$mark.click(jQuery.proxy(this.message_seen, this,[$message]))
|
|
|
|
.attr('title',egw.lang('mark as read'));
|
|
|
|
}
|
2017-09-15 17:10:11 +02:00
|
|
|
|
2017-05-15 17:34:27 +02:00
|
|
|
// Activate links
|
|
|
|
jQuery('div[data-id],div[data-url]', $message).on('click',
|
|
|
|
function() {
|
|
|
|
if(this.dataset.id)
|
|
|
|
{
|
|
|
|
egw.open(this.dataset.id,this.dataset.app);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.open_link(this.dataset.url,'_blank',this.dataset.popup);
|
|
|
|
}
|
2014-12-15 20:09:22 +01:00
|
|
|
}
|
2017-05-15 17:34:27 +02:00
|
|
|
).addClass('et2_link');
|
2018-01-24 19:02:35 +01:00
|
|
|
if (notifymessages[id]['data'] && notifymessages[id]['data']['actions'] && notifymessages[id]['data']['actions'].length > 0)
|
2017-05-23 16:54:20 +02:00
|
|
|
{
|
|
|
|
var $actions_container = jQuery(document.createElement('div')).addClass('egwpopup_actions_container');
|
2017-09-18 18:47:44 +02:00
|
|
|
for(var action in notifymessages[id].data.actions)
|
2017-05-23 16:54:20 +02:00
|
|
|
{
|
2017-09-18 18:47:44 +02:00
|
|
|
var func = new Function(notifymessages[id].data.actions[action].onExecute);
|
2017-05-23 16:54:20 +02:00
|
|
|
jQuery(document.createElement('button'))
|
|
|
|
.addClass('et2_button')
|
2017-09-18 18:47:44 +02:00
|
|
|
.css({'background-image':'url('+egw.image(notifymessages[id].data.actions[action].icon,notifymessages[id].data.app)+')'})
|
|
|
|
.text(notifymessages[id].data.actions[action].caption)
|
2019-08-14 16:30:59 +02:00
|
|
|
.click(jQuery.proxy(func, this, [$message]))
|
2017-05-23 16:54:20 +02:00
|
|
|
.prependTo($actions_container);
|
|
|
|
}
|
2017-09-15 17:10:11 +02:00
|
|
|
$actions_container.appendTo($message);
|
2017-05-23 16:54:20 +02:00
|
|
|
}
|
2017-09-15 17:10:11 +02:00
|
|
|
$top_toolbar.prependTo($message);
|
2017-05-15 17:34:27 +02:00
|
|
|
$egwpopup_list.append($message);
|
2017-05-17 14:04:31 +02:00
|
|
|
// bind click handler after the message container is attached
|
2017-09-18 18:47:44 +02:00
|
|
|
$message.click(jQuery.proxy(this.clickOnMessage, this,[$message]));
|
2020-07-29 12:55:08 +02:00
|
|
|
this.update_message_status(id, notifymessages[id]['status'], true);
|
2018-06-19 16:03:10 +02:00
|
|
|
if (notifymessages[id]['extra_data']
|
|
|
|
&& !notifymessages[id]['status']
|
|
|
|
&& notifymessages[id]['extra_data']['egw_pr_notify'])
|
|
|
|
{
|
|
|
|
switch (notifymessages[id]['extra_data']['egw_pr_notify'])
|
|
|
|
{
|
|
|
|
case EGW_PR_NOTIFY_HEIGH:
|
2020-08-21 14:57:52 +02:00
|
|
|
if (notifymessages[id]['extra_data']['videoconference'] && notifymessages[id]['extra_data']['alarm-offset'] <= 300 &&
|
|
|
|
app.status && typeof app.status.scheduled_receivedCall == 'function')
|
2020-04-07 17:16:56 +02:00
|
|
|
{
|
2020-04-08 15:14:39 +02:00
|
|
|
app.status.scheduled_receivedCall({
|
|
|
|
url: notifymessages[id]['extra_data']['videoconference'],
|
|
|
|
account_id: notifymessages[id]['extra_data']['account_id'],
|
|
|
|
avatar: 'account:'+ notifymessages[id]['extra_data']['account_id'],
|
|
|
|
title: notifymessages[id]['data']['title'],
|
|
|
|
owner: notifymessages[id]['extra_data']['name']
|
|
|
|
});
|
2020-04-07 17:16:56 +02:00
|
|
|
}
|
2020-04-07 19:03:32 +02:00
|
|
|
else {
|
2020-04-08 11:28:09 +02:00
|
|
|
this.toggle(true);
|
2020-04-07 19:03:32 +02:00
|
|
|
}
|
2020-04-08 11:28:09 +02:00
|
|
|
poped.push(id);
|
2018-06-19 16:03:10 +02:00
|
|
|
break;
|
|
|
|
case EGW_PR_NOTIFY_MEDIUM:
|
|
|
|
case EGW_PR_NOTIFY_LOW:
|
|
|
|
//Could be define with all sort of stuffs
|
|
|
|
}
|
|
|
|
}
|
2013-07-22 15:29:20 +02:00
|
|
|
}
|
2017-11-17 11:56:36 +01:00
|
|
|
|
|
|
|
if (poped.length > 0)
|
|
|
|
{
|
|
|
|
for (var key in poped)
|
|
|
|
{
|
|
|
|
// pop again those where opened before refresh
|
|
|
|
$egwpopup_list.find('#egwpopup_message_'+poped[key]).trigger('click');
|
|
|
|
}
|
|
|
|
}
|
2017-05-15 17:34:27 +02:00
|
|
|
this.counterUpdate();
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2017-09-18 18:47:44 +02:00
|
|
|
|
2017-09-15 17:10:11 +02:00
|
|
|
/**
|
|
|
|
* Opens the relavant entry from clicked message
|
|
|
|
*
|
|
|
|
* @param {jquery object} _node
|
|
|
|
* @param {object} _event
|
|
|
|
*/
|
|
|
|
notifications.prototype.open_entry = function (_node, _event){
|
2017-05-22 12:18:53 +02:00
|
|
|
_event.stopPropagation();
|
|
|
|
this.message_seen(_node, _event);
|
|
|
|
var egwpopup_message = _node[0];
|
|
|
|
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
|
|
|
if (notifymessages[id]['data'])
|
|
|
|
{
|
|
|
|
if (notifymessages[id]['data']['id'])
|
|
|
|
{
|
|
|
|
egw.open(notifymessages[id]['data']['id'], notifymessages[id]['data']['app']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.open_link(notifymessages[id]['data']['url'],'_blank',notifymessages[id]['data']['popup']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-15 17:10:11 +02:00
|
|
|
/**
|
|
|
|
* Reposition the expanded message back in the list & removes the clone node
|
|
|
|
* @param {jquery object} _node
|
|
|
|
*/
|
2017-09-18 18:47:44 +02:00
|
|
|
notifications.prototype.collapseMessage = function (_node, _event){
|
|
|
|
_event.stopPropagation();
|
2017-09-15 17:10:11 +02:00
|
|
|
var cloned = _node[0].prev();
|
|
|
|
if (cloned.length > 0 && cloned[0].id == _node[0].attr('id')+'_expanded')
|
|
|
|
cloned.remove();
|
|
|
|
_node[0].removeClass('egwpopup_expanded');
|
2017-09-18 18:47:44 +02:00
|
|
|
_node[0].css('z-index', 0);
|
2018-03-06 18:33:42 +01:00
|
|
|
this.checkNavButtonStatus();
|
2018-07-13 16:23:26 +02:00
|
|
|
egw.loading_prompt('popup_notifications', false);
|
2017-09-15 17:10:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expand a clicked message into bigger view
|
|
|
|
* @param {jquery object} _node
|
|
|
|
* @param {object} _event
|
2017-09-18 18:47:44 +02:00
|
|
|
*
|
|
|
|
* @return undefined
|
2017-09-15 17:10:11 +02:00
|
|
|
*/
|
|
|
|
notifications.prototype.clickOnMessage = function (_node, _event){
|
2017-09-18 18:47:44 +02:00
|
|
|
// Do not run the click handler if it's been already expanded
|
2018-01-24 19:02:35 +01:00
|
|
|
if (_node[0].hasClass('egwpopup_expanded') || jQuery(_event.target).hasClass('et2_button')) return;
|
2017-09-15 17:10:11 +02:00
|
|
|
this.message_seen(_node, _event);
|
|
|
|
var $node = jQuery(_node[0][0].cloneNode());
|
|
|
|
if ($node)
|
|
|
|
{
|
|
|
|
$node.attr('id', _node[0].attr('id')+'_expanded')
|
|
|
|
.addClass('egwpopup_message_clone')
|
|
|
|
.insertBefore(_node[0]);
|
|
|
|
}
|
2017-09-18 18:47:44 +02:00
|
|
|
var zindex = jQuery('.egwpopup_expanded').length;
|
|
|
|
_node[0].addClass('egwpopup_expanded').css('z-index', zindex++);
|
2018-03-06 18:33:42 +01:00
|
|
|
this.checkNavButtonStatus();
|
2018-07-23 11:45:55 +02:00
|
|
|
if (jQuery('#egwpopup').is(':visible') && !egwIsMobile()) egw.loading_prompt('popup_notifications', true);
|
2017-09-15 17:10:11 +02:00
|
|
|
};
|
|
|
|
|
2018-03-06 18:33:42 +01:00
|
|
|
notifications.prototype.nav_button = function (_params, _event){
|
|
|
|
var $expanded = jQuery('.egwpopup_expanded');
|
|
|
|
var $messages = jQuery('.egwpopup_message').not('.egwpopup_message_clone');
|
|
|
|
var self = this;
|
|
|
|
var current = 0;
|
|
|
|
$messages.each(function(i, j){if (j.id == _params[0][0].id) current = i;});
|
|
|
|
$expanded.each(function(index, item){
|
|
|
|
self.collapseMessage([jQuery(item)], _event);
|
|
|
|
});
|
|
|
|
if (_params[1] == "prev")
|
|
|
|
{
|
|
|
|
$messages[current-1].click();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$messages[current+1].click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notifications.prototype.checkNavButtonStatus = function (){
|
|
|
|
var top = 0;
|
|
|
|
var $expanded = jQuery('.egwpopup_expanded');
|
|
|
|
var $messages = jQuery('.egwpopup_message').not('.egwpopup_message_clone');
|
|
|
|
$expanded.removeClass('egwpopup_nav_disable');
|
|
|
|
$expanded.each(function(index, item){
|
|
|
|
if (item.style.getPropertyValue('z-index') > $expanded[top].style.getPropertyValue('z-index'))
|
|
|
|
{
|
|
|
|
top = index;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var $topNode = jQuery($expanded[top]);
|
|
|
|
if ($topNode[top] == $messages[0]) $topNode.find('.egwpopup_nav_prev').addClass('egwpopup_nav_disable');
|
|
|
|
if ($topNode[top] == $messages[$messages.length-1]) $topNode.find('.egwpopup_nav_next').addClass('egwpopup_nav_disable');
|
|
|
|
}
|
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Display or hide notifcation-bell
|
2014-10-09 10:21:40 +02:00
|
|
|
*
|
|
|
|
* @param {string} mode "active"
|
2013-07-22 15:29:20 +02:00
|
|
|
*/
|
|
|
|
notifications.prototype.bell = function(mode) {
|
|
|
|
var notificationbell;
|
|
|
|
notificationbell = document.getElementById("notificationbell");
|
|
|
|
if(mode == "active") {
|
|
|
|
notificationbell.style.display = "inline";
|
|
|
|
} else {
|
|
|
|
notificationbell.style.display = "none";
|
|
|
|
}
|
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Callback for OK button: confirms message on server and hides display
|
|
|
|
*/
|
2017-05-17 14:04:31 +02:00
|
|
|
notifications.prototype.message_seen = function(_node, _event) {
|
|
|
|
_event.stopPropagation();
|
|
|
|
var egwpopup_message = _node[0];
|
|
|
|
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
2017-05-22 12:18:53 +02:00
|
|
|
if (notifymessages[id]['status'] !='SEEN')
|
|
|
|
{
|
2021-03-12 10:22:09 +01:00
|
|
|
var request = egw.json("notifications.notifications_ajax.update_status", [[notifymessages[id]], "SEEN"]);
|
2017-05-22 12:18:53 +02:00
|
|
|
request.sendRequest(true);
|
|
|
|
this.update_message_status(id, "SEEN");
|
2020-04-17 13:38:27 +02:00
|
|
|
if (notifymessages[id]['extra_data']['onSeenAction'])
|
|
|
|
{
|
|
|
|
var func = new Function(notifymessages[id]['extra_data']['onSeenAction']);
|
|
|
|
func.apply(this,[notifymessages[id]['extra_data']]);
|
|
|
|
}
|
2017-05-22 12:18:53 +02:00
|
|
|
}
|
2017-05-16 18:03:50 +02:00
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2017-05-16 18:03:50 +02:00
|
|
|
notifications.prototype.mark_all_seen = function()
|
|
|
|
{
|
|
|
|
if (!notifymessages || Object.keys(notifymessages).length == 0) return false;
|
2021-03-12 10:22:09 +01:00
|
|
|
egw.json("notifications.notifications_ajax.update_status", [notifymessages, "SEEN"]).sendRequest(true);
|
2017-05-16 18:03:50 +02:00
|
|
|
for (var id in notifymessages)
|
|
|
|
{
|
|
|
|
this.update_message_status(id, "SEEN");
|
|
|
|
}
|
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2020-07-29 12:55:08 +02:00
|
|
|
notifications.prototype.update_message_status = function (_id, _status, _noCounterUpdate)
|
2017-05-16 18:03:50 +02:00
|
|
|
{
|
|
|
|
var $egwpopup_message = jQuery('#egwpopup_message_'+_id);
|
|
|
|
notifymessages[_id]['status'] = _status;
|
|
|
|
if ($egwpopup_message.length>0)
|
|
|
|
{
|
|
|
|
switch (_status)
|
|
|
|
{
|
|
|
|
case 'SEEN':
|
|
|
|
$egwpopup_message.addClass('egwpopup_message_seen');
|
|
|
|
break;
|
|
|
|
case 'UNSEEN':
|
|
|
|
case 'DISPLAYED':
|
|
|
|
$egwpopup_message.removeClass('egwpopup_message_seen');
|
|
|
|
break;
|
|
|
|
}
|
2013-07-22 15:29:20 +02:00
|
|
|
}
|
2020-07-29 12:55:08 +02:00
|
|
|
if (!_noCounterUpdate) this.counterUpdate();
|
2017-05-16 18:03:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
notifications.prototype.delete_all = function () {
|
|
|
|
if (!notifymessages || Object.entries(notifymessages).length == 0) return false;
|
2021-03-12 10:22:09 +01:00
|
|
|
var self = this;
|
|
|
|
egw.json("notifications.notifications_ajax.delete_message", [notifymessages], function(_data){
|
|
|
|
if (_data && _data['deleted']) self.total -= Object.keys(_data['deleted']).length;
|
|
|
|
self.counterUpdate();
|
|
|
|
}).sendRequest(true);
|
2017-10-26 10:25:57 +02:00
|
|
|
notifymessages = {};
|
2017-05-16 18:03:50 +02:00
|
|
|
jQuery("#egwpopup_list").empty();
|
2018-07-13 16:23:26 +02:00
|
|
|
egw.loading_prompt('popup_notifications', false);
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Callback for close button: close and mark all as read
|
|
|
|
*/
|
2017-05-17 14:04:31 +02:00
|
|
|
notifications.prototype.button_delete = function(_node, _event) {
|
2017-05-16 18:03:50 +02:00
|
|
|
_event.stopPropagation();
|
2017-05-17 14:04:31 +02:00
|
|
|
var egwpopup_message = _node[0];
|
|
|
|
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
2021-03-12 10:22:09 +01:00
|
|
|
var self = this;
|
|
|
|
var request = egw.json("notifications.notifications_ajax.delete_message", [[notifymessages[id]]],function(_data){
|
|
|
|
if (_data && _data['deleted']) self.total -= Object.keys(_data['deleted']).length;
|
|
|
|
self.counterUpdate();
|
|
|
|
});
|
2017-05-16 18:03:50 +02:00
|
|
|
request.sendRequest(true);
|
2018-07-02 10:42:53 +02:00
|
|
|
var nextNode = egwpopup_message.next();
|
2018-07-13 16:23:26 +02:00
|
|
|
var keepLoadingPrompt = false;
|
2017-05-15 17:34:27 +02:00
|
|
|
delete (notifymessages[id]);
|
2018-07-03 17:09:48 +02:00
|
|
|
if (nextNode.length > 0 && nextNode[0].id.match(/egwpopup_message_/ig) && egwpopup_message.hasClass('egwpopup_expanded'))
|
|
|
|
{
|
|
|
|
nextNode.trigger('click');
|
2018-07-13 16:23:26 +02:00
|
|
|
keepLoadingPrompt = true;
|
2018-07-03 17:09:48 +02:00
|
|
|
}
|
2017-09-18 18:47:44 +02:00
|
|
|
// try to close the dialog if expanded before hidding it
|
|
|
|
this.collapseMessage(_node, _event);
|
2018-07-23 11:45:55 +02:00
|
|
|
if (keepLoadingPrompt && !egwIsMobile()) egw.loading_prompt('popup_notifications', true);
|
2018-03-12 17:30:21 +01:00
|
|
|
egwpopup_message.remove();
|
2013-07-22 15:29:20 +02:00
|
|
|
this.bell("inactive");
|
2018-07-02 10:42:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all children ids from notifications
|
|
|
|
* @returns {Array} returns ids of all children from all parents
|
|
|
|
*/
|
|
|
|
notifications.prototype.findAllChildrenIds = function ()
|
|
|
|
{
|
|
|
|
var map = [];
|
|
|
|
for (var i in notifymessages)
|
|
|
|
{
|
|
|
|
map = map.concat(this.findChildrenIds(notifymessages[i]));
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find children of a parent
|
|
|
|
* @param {object} _notification parent object
|
|
|
|
* @returns {Array} return ids of children
|
|
|
|
*/
|
|
|
|
notifications.prototype.findChildrenIds = function (_notification)
|
|
|
|
{
|
|
|
|
if(_notification.children)
|
|
|
|
{
|
|
|
|
return Object.keys(_notification.children);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds potential parent
|
|
|
|
*
|
|
|
|
* @param {type} _id
|
|
|
|
* @param {type} _app
|
|
|
|
* @returns {int} return id of notification
|
|
|
|
*/
|
|
|
|
notifications.prototype.findParent = function (_id, _app)
|
|
|
|
{
|
|
|
|
if (!_id && !_app) return null;
|
|
|
|
for(var i in notifymessages)
|
|
|
|
{
|
|
|
|
if (notifymessages[i]['data']['id'] == _id && notifymessages[i]['data']['app'] == _app)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
/**
|
|
|
|
* Add message to internal display-queue
|
2014-10-09 10:21:40 +02:00
|
|
|
*
|
2018-06-19 14:58:32 +02:00
|
|
|
* @param _rowData
|
2013-07-22 15:29:20 +02:00
|
|
|
* @param _browser_notify
|
|
|
|
*/
|
2021-03-12 10:22:09 +01:00
|
|
|
notifications.prototype.append = function(_rawData, _browser_notify, _total) {
|
2018-06-19 14:58:32 +02:00
|
|
|
|
|
|
|
var hasUnseen = [];
|
2021-03-12 10:22:09 +01:00
|
|
|
_rawData = _rawData || [];
|
2020-08-19 15:08:59 +02:00
|
|
|
// Dont process the data if they're the same as it could get very expensive to
|
|
|
|
// proccess html their content.
|
|
|
|
if (_currentRawData.length>0 && _currentRawData.length == _rawData.length) return;
|
2021-03-12 10:22:09 +01:00
|
|
|
_currentRawData = _rawData || [];
|
|
|
|
var old_notifymessages = notifymessages;
|
2018-07-02 10:42:53 +02:00
|
|
|
notifymessages = {};
|
2020-07-21 15:46:38 +02:00
|
|
|
var browser_notify = _browser_notify || this.check_browser_notify();
|
2021-03-12 10:22:09 +01:00
|
|
|
this.total = _total || 0;
|
2018-06-19 14:58:32 +02:00
|
|
|
for (var i=0; i < _rawData.length; i++)
|
2012-11-05 19:32:54 +01:00
|
|
|
{
|
2018-07-23 16:24:47 +02:00
|
|
|
var data = this.getData(_rawData[i]['message'], _rawData[i]['extra_data']);
|
2018-07-02 10:42:53 +02:00
|
|
|
var parent;
|
|
|
|
if ((parent = this.findParent(data['id'], data['app']))
|
2018-07-23 16:24:47 +02:00
|
|
|
&& typeof _rawData[i]['extra_data']['egw_pr_notify'] == 'undefined')
|
2018-07-02 10:42:53 +02:00
|
|
|
{
|
|
|
|
if (parent == _rawData[i]['id']) continue;
|
|
|
|
if (!notifymessages[parent]['children']) notifymessages[parent] = jQuery.extend(notifymessages[parent], {children:{}});
|
|
|
|
notifymessages[parent]['children'][_rawData[i]['id']] = {
|
|
|
|
message:_rawData[i]['message'],
|
|
|
|
data: data,
|
|
|
|
status: _rawData[i]['status'],
|
|
|
|
created: _rawData[i]['created'],
|
|
|
|
current: _rawData[i]['current'],
|
|
|
|
extra_data: _rawData[i]['extra_data']
|
|
|
|
};
|
2018-07-23 16:24:47 +02:00
|
|
|
if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[parent]['children'][_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
|
2018-07-02 10:42:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-19 14:58:32 +02:00
|
|
|
// Prevent the same thing popping up multiple times
|
|
|
|
notifymessages[_rawData[i]['id']] = {
|
|
|
|
message:_rawData[i]['message'],
|
|
|
|
data: data,
|
|
|
|
status: _rawData[i]['status'],
|
|
|
|
created: _rawData[i]['created'],
|
2018-06-19 16:03:10 +02:00
|
|
|
current: _rawData[i]['current'],
|
2021-03-12 10:22:09 +01:00
|
|
|
extra_data: _rawData[i]['extra_data'],
|
|
|
|
id: _rawData[i]['id']
|
2018-06-19 14:58:32 +02:00
|
|
|
};
|
|
|
|
if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
|
|
|
|
// Notification API
|
2020-07-21 15:46:38 +02:00
|
|
|
if(browser_notify && !_rawData[i]['status'])
|
2018-06-19 14:58:32 +02:00
|
|
|
{
|
|
|
|
egw.notification(data.title, {
|
|
|
|
tag: data.app+":"+_rawData[i]['id'],
|
|
|
|
body: data.message,
|
|
|
|
icon: data.icon,
|
2020-04-07 18:13:38 +02:00
|
|
|
requireInteraction: true,
|
2018-06-19 14:58:32 +02:00
|
|
|
onclose:function(e){
|
|
|
|
// notification id
|
|
|
|
var id = this.tag.split(":");
|
|
|
|
// delete the message
|
2021-03-12 10:22:09 +01:00
|
|
|
var request = egw.json("notifications.notifications_ajax.update_status", [[id[1]], 'DISPLAYED']);
|
2018-06-19 14:58:32 +02:00
|
|
|
request.sendRequest();
|
|
|
|
},
|
|
|
|
onclick:function(e){
|
|
|
|
// notification id
|
|
|
|
var id = this.tag.split(":");
|
|
|
|
|
|
|
|
// get the right data from messages object
|
|
|
|
var notify = notifymessages[id[1]];
|
|
|
|
|
|
|
|
if (!notifymessages[id[1]]) this.close();
|
|
|
|
|
|
|
|
if (notify && notify.data && notify.data.id)
|
|
|
|
{
|
|
|
|
egw.open(notify.data.id, notify.data.app);
|
|
|
|
}
|
|
|
|
else if (notify && notify.data)
|
|
|
|
{
|
|
|
|
egw.open_link(notify.data.url,'_blank',notify.data.popup);
|
|
|
|
}
|
|
|
|
this.close();
|
2016-07-11 11:59:50 +02:00
|
|
|
}
|
2018-06-19 14:58:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!_rawData[i]['status'])
|
|
|
|
{
|
2021-03-12 10:22:09 +01:00
|
|
|
egw.json("notifications.notifications_ajax.update_status", [[_rawData[i]['id']], 'DISPLAYED']);
|
2018-06-19 14:58:32 +02:00
|
|
|
hasUnseen.push(_rawData[i]['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-03-12 10:22:09 +01:00
|
|
|
var egwpopup = document.getElementById('egwpopup');
|
2018-06-19 14:58:32 +02:00
|
|
|
switch(egw.preference('egwpopup_verbosity', 'notifications'))
|
|
|
|
{
|
|
|
|
case 'low':
|
|
|
|
this.bell('active');
|
|
|
|
break;
|
|
|
|
case 'high':
|
|
|
|
if (hasUnseen.length > 0)
|
|
|
|
{
|
|
|
|
alert(egw.lang('EGroupware has notifications for you'));
|
|
|
|
egw.json("notifications.notifications_ajax.update_status", [hasUnseen, 'DISPLAYED']).sendRequest();
|
2016-07-11 11:59:50 +02:00
|
|
|
}
|
2020-08-19 15:08:59 +02:00
|
|
|
if (egwpopup.style.display != 'none') this.display();
|
2018-06-19 14:58:32 +02:00
|
|
|
break;
|
|
|
|
case 'medium':
|
2020-08-19 15:08:59 +02:00
|
|
|
if (egwpopup.style.display != 'none' && Object.keys(old_notifymessages).length != Object.keys(notifymessages).length)
|
|
|
|
{
|
|
|
|
this.display();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.counterUpdate();
|
|
|
|
}
|
2018-06-19 14:58:32 +02:00
|
|
|
|
2012-11-05 19:32:54 +01:00
|
|
|
}
|
2013-07-22 15:29:20 +02:00
|
|
|
};
|
2014-10-09 10:21:40 +02:00
|
|
|
|
2016-07-11 11:59:50 +02:00
|
|
|
/**
|
|
|
|
* Extract useful data out of HTML message
|
|
|
|
*
|
|
|
|
* @param {type} _message
|
|
|
|
* @returns {notificationajaxpopup_L15.notifications.prototype.getData.data}
|
|
|
|
*/
|
2018-07-23 16:24:47 +02:00
|
|
|
notifications.prototype.getData = function (_message, _extra_data) {
|
2020-08-19 15:08:59 +02:00
|
|
|
var parser = new DOMParser();
|
|
|
|
var dom = jQuery(parser.parseFromString(_message, 'text/html'));
|
|
|
|
|
2018-07-23 16:24:47 +02:00
|
|
|
var extra_data = _extra_data || {};
|
2016-07-11 11:59:50 +02:00
|
|
|
var link = dom.find('div[data-id],div[data-url]');
|
|
|
|
var data = {
|
|
|
|
message: dom.text(),
|
|
|
|
title: link.text(),
|
|
|
|
icon: link.find('img').attr('src')
|
|
|
|
};
|
2018-07-23 16:24:47 +02:00
|
|
|
jQuery.extend(data,link.data(), extra_data);
|
2016-07-11 11:59:50 +02:00
|
|
|
return typeof data == 'object'? data: {};
|
|
|
|
};
|
|
|
|
|
2020-07-27 14:44:44 +02:00
|
|
|
|
|
|
|
notifications.prototype.tabToggle = function (_appname)
|
|
|
|
{
|
|
|
|
for (var i in notifymessages)
|
|
|
|
{
|
|
|
|
if (notifymessages[i]['extra_data']['app'] == _appname)
|
|
|
|
{
|
|
|
|
this.filter = _appname;
|
|
|
|
this.toggle();
|
2020-07-29 12:55:08 +02:00
|
|
|
this.display();
|
2020-07-27 14:44:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-05-15 17:34:27 +02:00
|
|
|
/**
|
|
|
|
* toggle notifications container
|
2018-06-19 16:03:10 +02:00
|
|
|
* @param boolean _stat true keeps the popup on
|
2017-05-15 17:34:27 +02:00
|
|
|
*/
|
2018-06-19 16:03:10 +02:00
|
|
|
notifications.prototype.toggle = function (_stat)
|
2017-05-15 17:34:27 +02:00
|
|
|
{
|
2018-01-10 12:42:42 +01:00
|
|
|
var $egwpopup = jQuery('#egwpopup');
|
|
|
|
var $body = jQuery('body');
|
2019-05-27 17:12:30 +02:00
|
|
|
var $counter = jQuery('#topmenu_info_notifications');
|
2020-07-29 12:55:08 +02:00
|
|
|
if (!_stat) this.display();
|
2020-07-27 14:44:44 +02:00
|
|
|
var self = this;
|
2018-01-10 12:42:42 +01:00
|
|
|
if (!$egwpopup.is(":visible"))
|
|
|
|
{
|
|
|
|
$body.on('click', function(e){
|
2019-12-02 17:36:30 +01:00
|
|
|
if (!$counter.is(e.target) && $counter.find(e.target).length == 0 &&
|
2018-01-10 12:42:42 +01:00
|
|
|
!$egwpopup.is(e.target) && $egwpopup.has(e.target).length == 0)
|
|
|
|
{
|
|
|
|
jQuery(this).off(e);
|
2020-07-27 14:44:44 +02:00
|
|
|
self.filter = '';
|
2018-07-13 16:23:26 +02:00
|
|
|
$egwpopup.toggle('slide');
|
|
|
|
egw.loading_prompt('popup_notifications', false);
|
2018-01-10 12:42:42 +01:00
|
|
|
}
|
|
|
|
});
|
2018-07-13 16:23:26 +02:00
|
|
|
egw.loading_prompt('popup_notifications', jQuery("#egwpopup_list").find('.egwpopup_expanded').length>0);
|
2018-01-10 12:42:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-27 14:44:44 +02:00
|
|
|
this.filter = '';
|
2018-07-13 16:23:26 +02:00
|
|
|
egw.loading_prompt('popup_notifications', false);
|
2018-06-19 16:03:10 +02:00
|
|
|
if (_stat) return;
|
2018-01-10 12:42:42 +01:00
|
|
|
$body.off('click');
|
|
|
|
}
|
2017-05-29 15:07:33 +02:00
|
|
|
|
2018-07-13 16:23:26 +02:00
|
|
|
if ($egwpopup.length>0) $egwpopup.toggle('slide');
|
2017-05-15 17:34:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set new state of notifications counter
|
|
|
|
*/
|
|
|
|
notifications.prototype.counterUpdate = function ()
|
|
|
|
{
|
2019-05-27 17:12:30 +02:00
|
|
|
var $topmenu_info_notifications = jQuery('#topmenu_info_notifications');
|
2017-05-16 18:03:50 +02:00
|
|
|
var counter = 0;
|
2020-07-29 12:55:08 +02:00
|
|
|
var apps = {};
|
2020-07-23 17:39:39 +02:00
|
|
|
|
2021-03-12 10:22:09 +01:00
|
|
|
// set total number
|
|
|
|
document.getElementById("egwpopup_header").childNodes[0].textContent = (egw.lang("Notifications")+" ("+this.total+")");
|
|
|
|
document.getElementById('topmenu_info_notifications').title = egw.lang('total')+":"+this.total;
|
|
|
|
|
2017-05-16 18:03:50 +02:00
|
|
|
for (var id in notifymessages)
|
|
|
|
{
|
2020-07-29 12:55:08 +02:00
|
|
|
if (typeof apps[notifymessages[id]['extra_data']['app']] == 'undefined')
|
|
|
|
{
|
|
|
|
apps[notifymessages[id]['extra_data']['app']] = 0;
|
|
|
|
}
|
2020-07-23 15:50:15 +02:00
|
|
|
if (notifymessages[id]['status'] != 'SEEN')
|
|
|
|
{
|
|
|
|
counter++;
|
2020-07-29 12:55:08 +02:00
|
|
|
if (typeof apps[notifymessages[id]['extra_data']['app']] != 'undefined')
|
|
|
|
{
|
|
|
|
apps[notifymessages[id]['extra_data']['app']] +=1;
|
|
|
|
}
|
2020-07-23 15:50:15 +02:00
|
|
|
}
|
2017-05-16 18:03:50 +02:00
|
|
|
}
|
|
|
|
if (counter > 0)
|
2017-05-15 17:34:27 +02:00
|
|
|
{
|
2020-07-29 12:55:08 +02:00
|
|
|
for (var app in apps)
|
|
|
|
{
|
2020-08-03 15:21:11 +02:00
|
|
|
if (framework.notifyAppTab) framework.notifyAppTab(app, apps[app]);
|
2020-07-29 12:55:08 +02:00
|
|
|
}
|
|
|
|
|
2019-05-27 17:12:30 +02:00
|
|
|
$topmenu_info_notifications.addClass('egwpopup_notify');
|
2019-12-02 14:09:45 +01:00
|
|
|
framework.topmenu_info_notify('notifications', true, counter,egw.lang('You have %1 unread notifications', counter));
|
2017-05-15 17:34:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-02 14:09:45 +01:00
|
|
|
framework.topmenu_info_notify('notifications', false);
|
2017-05-15 17:34:27 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-22 15:29:20 +02:00
|
|
|
var lab = egw_LAB || $LAB;
|
|
|
|
var self = notifications;
|
|
|
|
lab.wait(function(){
|
2018-01-11 17:23:58 +01:00
|
|
|
var langRequire = jQuery('#notifications_script_id').attr('data-langRequire');
|
|
|
|
egw.langRequire(window, [JSON.parse(langRequire)], function()
|
|
|
|
{
|
2019-05-27 17:12:30 +02:00
|
|
|
var $egwpopup_fw = jQuery('#topmenu_info_notifications');
|
2018-01-25 17:31:15 +01:00
|
|
|
switch (egw.preference('notification_chain','notifications'))
|
|
|
|
{
|
|
|
|
case 'popup_only':
|
|
|
|
case 'popup_and_email':
|
|
|
|
case 'popup_or_email':
|
|
|
|
case 'all':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$egwpopup_fw.hide();
|
|
|
|
return;
|
|
|
|
}
|
2018-01-11 17:23:58 +01:00
|
|
|
if (typeof window.app == 'undefined') window.app = {};
|
2018-02-19 17:17:24 +01:00
|
|
|
|
|
|
|
window.onbeforeunload = function()
|
|
|
|
{
|
|
|
|
if (typeof egw.killAliveNotifications =='function') egw.killAliveNotifications();
|
|
|
|
};
|
2018-01-11 17:23:58 +01:00
|
|
|
window.app.notifications = new self();
|
|
|
|
// toggle notifications bar
|
2018-06-06 11:05:19 +02:00
|
|
|
jQuery('.button_right_toggle', '#egwpopup').click(function(){window.app.notifications.toggle();});
|
2018-01-25 17:31:15 +01:00
|
|
|
$egwpopup_fw.click(function(){window.app.notifications.toggle();});
|
2018-01-11 17:23:58 +01:00
|
|
|
jQuery(".egwpopup_deleteall", '#egwpopup').click(function(){
|
|
|
|
et2_dialog.show_dialog( function(_button){
|
|
|
|
if (_button == 2) window.app.notifications.delete_all();
|
|
|
|
},
|
|
|
|
egw.lang('Are you sure you want to delete all notifications?'),
|
|
|
|
egw.lang('Delete notifications'),
|
|
|
|
null, et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw
|
|
|
|
);
|
|
|
|
});
|
|
|
|
jQuery(".egwpopup_seenall", '#egwpopup').click(function(){window.app.notifications.mark_all_seen()});
|
|
|
|
}, this);
|
2013-07-22 15:29:20 +02:00
|
|
|
});
|
|
|
|
})();
|