mark all read
This commit is contained in:
@@ -54,7 +54,13 @@ class Notification extends \Espo\Core\Controllers\Base
|
||||
public function actionNotReadCount()
|
||||
{
|
||||
$userId = $this->getUser()->id;
|
||||
return $this->getService('Notification')->getNotReadCount($userId);
|
||||
return $this->getService('Notification')->getNotReadCount($userId);
|
||||
}
|
||||
|
||||
public function actionMarkAllRead($params, $data, $request)
|
||||
{
|
||||
$userId = $this->getUser()->id;
|
||||
return $this->getService('Notification')->markAllRead($userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,8 @@
|
||||
"Administration": "Administration",
|
||||
"Run Import": "Run Import",
|
||||
"Duplicate": "Duplicate",
|
||||
"Notifications": "Notifications"
|
||||
"Notifications": "Notifications",
|
||||
"Mark all read": "Mark all read"
|
||||
},
|
||||
"messages": {
|
||||
"notModified": "You have not modified the record",
|
||||
|
||||
@@ -84,6 +84,14 @@ class Notification extends \Espo\Core\Services\Base
|
||||
))->count();
|
||||
}
|
||||
|
||||
public function markAllRead($userId)
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sql = "UPDATE notification SET `read` = 1 WHERE user_id = ".$pdo->quote($userId)." AND `read` = 0";
|
||||
$pdo->prepare($sql)->execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getList($userId, array $params = array())
|
||||
{
|
||||
$searchParams = array();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">{{translate 'Notifications'}}</div>
|
||||
<div class="panel-heading"><a class="pull-right" href="javascript:" data-action="markAllNotificationsRead">{{translate 'Mark all read'}}</a>{{translate 'Notifications'}}</div>
|
||||
<div class="panel-body">
|
||||
<div class="list-container">
|
||||
{{translate 'Loading...'}}
|
||||
|
||||
@@ -49,14 +49,22 @@ Espo.define('Views.Notifications.Badge', 'View', function (Dep) {
|
||||
this.checkUpdates();
|
||||
},
|
||||
|
||||
showNotRead: function (count) {
|
||||
this.$icon.addClass('warning');
|
||||
this.$badge.attr('title', this.translate('New notifications') + ': ' + count);
|
||||
},
|
||||
|
||||
hideNotRead: function () {
|
||||
this.$icon.removeClass('warning');
|
||||
this.$badge.attr('title', '');
|
||||
},
|
||||
|
||||
checkUpdates: function () {
|
||||
$.ajax('Notification/action/notReadCount').done(function (count) {
|
||||
if (count) {
|
||||
this.$icon.addClass('warning');
|
||||
this.$badge.attr('title', this.translate('New notifications') + ': ' + count);
|
||||
this.showNotRead(count);
|
||||
} else {
|
||||
this.$icon.removeClass('warning');
|
||||
this.$badge.attr('title', '');
|
||||
this.hideNotRead();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
@@ -82,6 +90,9 @@ Espo.define('Views.Notifications.Badge', 'View', function (Dep) {
|
||||
el: '#notifications-panel',
|
||||
}, function (view) {
|
||||
view.render();
|
||||
this.listenTo(view, 'all-read', function () {
|
||||
this.hideNotRead();
|
||||
}, this);
|
||||
}.bind(this));
|
||||
|
||||
$document = $(document);
|
||||
|
||||
@@ -25,6 +25,17 @@ Espo.define('Views.Notifications.Panel', 'View', function (Dep) {
|
||||
|
||||
template: 'notifications.panel',
|
||||
|
||||
events: {
|
||||
'click [data-action="markAllNotificationsRead"]': function () {
|
||||
$.ajax({
|
||||
url: 'Notification/action/markAllRead',
|
||||
type: 'POST'
|
||||
}).done(function (count) {
|
||||
this.trigger('all-read');
|
||||
}.bind(this));
|
||||
},
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
this.wait(true);
|
||||
this.getCollectionFactory().create('Notification', function (collection) {
|
||||
|
||||
Reference in New Issue
Block a user