forked from extern/egroupware
Set indicators for displaying total number of notifications
This commit is contained in:
parent
558b41f11a
commit
c6e964036e
@ -158,6 +158,7 @@ class notifications_ajax {
|
|||||||
'notify_type' => self::_type
|
'notify_type' => self::_type
|
||||||
),__LINE__,__FILE__,self::_appname);
|
),__LINE__,__FILE__,self::_appname);
|
||||||
}
|
}
|
||||||
|
$this->response->data(['deleted'=>$notify_ids]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,38 +251,10 @@ class notifications_ajax {
|
|||||||
*
|
*
|
||||||
* @return boolean true or false
|
* @return boolean true or false
|
||||||
*/
|
*/
|
||||||
private function get_egwpopup($browserNotify = false) {
|
private function get_egwpopup($browserNotify = false)
|
||||||
$rs = $this->db->select(self::_notification_table, '*', array(
|
{
|
||||||
'account_id' => $this->recipient->account_id,
|
$entries = notifications_popup::read($this->recipient->account_id);
|
||||||
'notify_type' => self::_type
|
$this->response->apply('app.notifications.append', array($entries['rows'], $browserNotify, $entries['total']));
|
||||||
),
|
|
||||||
__LINE__,__FILE__,0 ,'ORDER BY notify_id DESC',self::_appname, 100);
|
|
||||||
$result = array();
|
|
||||||
if ($rs->NumRows() > 0) {
|
|
||||||
foreach ($rs as $notification) {
|
|
||||||
$actions = null;
|
|
||||||
$data = json_decode($notification['notify_data'], true);
|
|
||||||
if ($data['appname'] && $data['data'])
|
|
||||||
{
|
|
||||||
$_actions = Api\Hooks::process (array(
|
|
||||||
'location' => 'notifications_actions',
|
|
||||||
'data' => $data['data']
|
|
||||||
), $data['appname'], true);
|
|
||||||
$actions = $_actions[$data['appname']];
|
|
||||||
}
|
|
||||||
$result[] = array(
|
|
||||||
'id' => $notification['notify_id'],
|
|
||||||
'message' => $notification['notify_message'],
|
|
||||||
'status' => $notification['notify_status'],
|
|
||||||
'created' => Api\DateTime::server2user($notification['notify_created']),
|
|
||||||
'current' => new Api\DateTime('now'),
|
|
||||||
'actions' => is_array($actions)?$actions:NULL,
|
|
||||||
'extra_data' => ($data['data'] ? $data['data'] : array())
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
$this->response->apply('app.notifications.append', array($result, $browserNotify));
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,21 +130,31 @@ class notifications_popup implements notifications_iface {
|
|||||||
), false,__LINE__,__FILE__,self::_appname);
|
), false,__LINE__,__FILE__,self::_appname);
|
||||||
if ($result === false) throw new Exception("Can't save notification into SQL table");
|
if ($result === false) throw new Exception("Can't save notification into SQL table");
|
||||||
$push = new Api\Json\Push($this->recipient->account_id);
|
$push = new Api\Json\Push($this->recipient->account_id);
|
||||||
$push->call('app.notifications.append', $this->read());
|
$entries = self::read($this->recipient->account_id);
|
||||||
|
$push->call('app.notifications.append', [$entries['rows'], null, $entries['total']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read all notification messages for current recipient
|
* read all notification messages for given recipient
|
||||||
* @return type
|
* @param $_account_id
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function read()
|
public static function read($_account_id)
|
||||||
{
|
{
|
||||||
$rs = $this->db->select(self::_notification_table, '*', array(
|
if (!$_account_id) return [];
|
||||||
'account_id' => $this->recipient->account_id,
|
|
||||||
|
$rs = $GLOBALS['egw']->db->select(self::_notification_table, '*', array(
|
||||||
|
'account_id' => $_account_id,
|
||||||
'notify_type' => self::_type
|
'notify_type' => self::_type
|
||||||
),
|
),
|
||||||
__LINE__,__FILE__,0 ,'ORDER BY notify_id DESC',self::_appname, 100);
|
__LINE__,__FILE__,0 ,'ORDER BY notify_id DESC',self::_appname, 100);
|
||||||
|
// Fetch the total
|
||||||
|
$total = $GLOBALS['egw']->db->select(self::_notification_table, 'COUNT(*)', array(
|
||||||
|
'account_id' => $_account_id,
|
||||||
|
'notify_type' => self::_type
|
||||||
|
),
|
||||||
|
__LINE__,__FILE__,0 ,'',self::_appname)->fetchColumn();
|
||||||
$result = array();
|
$result = array();
|
||||||
if ($rs->NumRows() > 0) {
|
if ($rs->NumRows() > 0) {
|
||||||
foreach ($rs as $notification) {
|
foreach ($rs as $notification) {
|
||||||
@ -169,7 +179,7 @@ class notifications_popup implements notifications_iface {
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
return $result;
|
return ['rows' => $result, 'total'=> $total];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,8 @@
|
|||||||
this.run_notifications();
|
this.run_notifications();
|
||||||
|
|
||||||
this.filter = '';
|
this.filter = '';
|
||||||
|
// total number of notifications
|
||||||
|
this.total = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
notifications.prototype.run_notifications = function ()
|
notifications.prototype.run_notifications = function ()
|
||||||
@ -561,10 +562,13 @@
|
|||||||
|
|
||||||
notifications.prototype.delete_all = function () {
|
notifications.prototype.delete_all = function () {
|
||||||
if (!notifymessages || Object.entries(notifymessages).length == 0) return false;
|
if (!notifymessages || Object.entries(notifymessages).length == 0) return false;
|
||||||
egw.json("notifications.notifications_ajax.delete_message", [notifymessages]).sendRequest(true);
|
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);
|
||||||
notifymessages = {};
|
notifymessages = {};
|
||||||
jQuery("#egwpopup_list").empty();
|
jQuery("#egwpopup_list").empty();
|
||||||
this.counterUpdate();
|
|
||||||
egw.loading_prompt('popup_notifications', false);
|
egw.loading_prompt('popup_notifications', false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -575,7 +579,11 @@
|
|||||||
_event.stopPropagation();
|
_event.stopPropagation();
|
||||||
var egwpopup_message = _node[0];
|
var egwpopup_message = _node[0];
|
||||||
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
||||||
var request = egw.json("notifications.notifications_ajax.delete_message", [[notifymessages[id]]]);
|
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();
|
||||||
|
});
|
||||||
request.sendRequest(true);
|
request.sendRequest(true);
|
||||||
var nextNode = egwpopup_message.next();
|
var nextNode = egwpopup_message.next();
|
||||||
var keepLoadingPrompt = false;
|
var keepLoadingPrompt = false;
|
||||||
@ -590,8 +598,6 @@
|
|||||||
if (keepLoadingPrompt && !egwIsMobile()) egw.loading_prompt('popup_notifications', true);
|
if (keepLoadingPrompt && !egwIsMobile()) egw.loading_prompt('popup_notifications', true);
|
||||||
egwpopup_message.remove();
|
egwpopup_message.remove();
|
||||||
this.bell("inactive");
|
this.bell("inactive");
|
||||||
this.counterUpdate();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -647,7 +653,7 @@
|
|||||||
* @param _rowData
|
* @param _rowData
|
||||||
* @param _browser_notify
|
* @param _browser_notify
|
||||||
*/
|
*/
|
||||||
notifications.prototype.append = function(_rawData, _browser_notify) {
|
notifications.prototype.append = function(_rawData, _browser_notify, _total) {
|
||||||
|
|
||||||
var hasUnseen = [];
|
var hasUnseen = [];
|
||||||
// Dont process the data if they're the same as it could get very expensive to
|
// Dont process the data if they're the same as it could get very expensive to
|
||||||
@ -657,6 +663,7 @@
|
|||||||
var old_notifymessages = notifymessages;
|
var old_notifymessages = notifymessages;
|
||||||
notifymessages = {};
|
notifymessages = {};
|
||||||
var browser_notify = _browser_notify || this.check_browser_notify();
|
var browser_notify = _browser_notify || this.check_browser_notify();
|
||||||
|
this.total = _total || 0;
|
||||||
for (var i=0; i < _rawData.length; i++)
|
for (var i=0; i < _rawData.length; i++)
|
||||||
{
|
{
|
||||||
var data = this.getData(_rawData[i]['message'], _rawData[i]['extra_data']);
|
var data = this.getData(_rawData[i]['message'], _rawData[i]['extra_data']);
|
||||||
@ -841,6 +848,10 @@
|
|||||||
var counter = 0;
|
var counter = 0;
|
||||||
var apps = {};
|
var apps = {};
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
for (var id in notifymessages)
|
for (var id in notifymessages)
|
||||||
{
|
{
|
||||||
if (typeof apps[notifymessages[id]['extra_data']['app']] == 'undefined')
|
if (typeof apps[notifymessages[id]['extra_data']['app']] == 'undefined')
|
||||||
|
Loading…
Reference in New Issue
Block a user