Notification Overview markAsSeen fix.

This commit is contained in:
buddh4 2017-01-25 18:01:16 +01:00
parent 4da79ebe4f
commit ecd193c7c2
2 changed files with 30 additions and 20 deletions

View File

@ -60,7 +60,7 @@ humhub.module('notification', function (module, require, $) {
// Always reset the loading settings so we reload the whole dropdown.
this.lastEntryLoaded = false;
this.lastEntryId = 0;
// Since the handler will be called before the bootstrap trigger it's an open event if the dropdown is not visible yet
this.isOpen = !this.$dropdown.is(':visible');
if (this.isOpen) {
@ -164,7 +164,7 @@ humhub.module('notification', function (module, require, $) {
};
NotificationDropDown.prototype.markAsSeen = function (evt) {
client.post(evt).then(function (response) {
return client.post(evt).then(function (response) {
$('#badge-notifications').hide();
$('#mark-seen-link').hide();
updateTitle(false);
@ -172,6 +172,19 @@ humhub.module('notification', function (module, require, $) {
module.log.error(e, true);
});
};
/**
* Global action handler (used in overview page).
*
* @param {type} evt
* @returns {undefined}
*/
var markAsSeen = function(evt) {
var widget = NotificationDropDown.instance('#notification_widget');
widget.markAsSeen(evt).then(function() {
location.reload();
});
};
var updateTitle = function ($count) {
if ($count) {
@ -187,6 +200,7 @@ humhub.module('notification', function (module, require, $) {
var init = function ($pjax) {
updateTitle($('#notification_widget').data('notification-count'));
initOverviewPage();
if (!$pjax) {
$("#dropdown-notifications ul.media-list").niceScroll({
cursorwidth: "7",
@ -197,10 +211,21 @@ humhub.module('notification', function (module, require, $) {
railpadding: {top: 0, right: 3, left: 0, bottom: 0}
});
}
};
var initOverviewPage = function () {
if ($('#notification_overview_list').length) {
if (!$('#notification_overview_list li.new').length) {
$('#notification_overview_markseen').hide();
}
}
};
module.export({
init: init,
markAsSeen: markAsSeen,
sendDesktopNotifiaction: sendDesktopNotifiaction,
NotificationDropDown: NotificationDropDown
});

View File

@ -1,6 +1,8 @@
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<div class="container">
<div class="row">
@ -8,7 +10,7 @@ use yii\widgets\ActiveForm;
<div class="panel panel-default">
<div class="panel-heading">
<?= Yii::t('NotificationModule.views_overview_index', '<strong>Notification</strong> Overview'); ?>
<a id="notification_overview_markseen" href="#" class="pull-right heading-link" >
<a id="notification_overview_markseen" href="#" data-action-click="notification.markAsSeen" data-action-url="<?= Url::to(['/notification/list/mark-as-seen']); ?>" class="pull-right heading-link" >
<b><?= Yii::t('NotificationModule.views_overview_index', 'Mark all as seen'); ?></b>
</a>
</div>
@ -46,20 +48,3 @@ use yii\widgets\ActiveForm;
</div>
</div>
</div>
<script type='text/javascript'>
if (!$('#notification_overview_list li.new').length) {
$('#notification_overview_markseen').hide();
} else {
$('#notification_overview_markseen').on('click', function (evt) {
evt.preventDefault();
$.ajax({
'type': 'GET',
'url': '<?= yii\helpers\Url::to(['/notification/list/mark-as-seen', 'ajax' => 1]); ?>',
'success': function () {
location.reload();
}
});
});
}
</script>