Merge branch 'MDL-56498-34' of git://github.com/mickhawkins/moodle into MOODLE_34_STABLE

This commit is contained in:
Jun Pataleta
2018-05-29 09:37:05 +08:00
3 changed files with 60 additions and 22 deletions
File diff suppressed because one or more lines are too long
@@ -237,6 +237,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url',
offset: offset,
});
// Link to mark read page before loading the actual link.
notification.contexturl = URL.relativeUrl('message/output/popup/mark_notification_read.php', {
redirecturl: notification.contexturl,
notificationid: notification.id,
});
var promise = Templates.render('message_popup/notification_content_item', notification)
.then(function(html, js) {
return {html: html, js: js};
@@ -321,26 +327,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url',
}.bind(this));
};
/**
* Send a request to the server to mark a single notification as read and update
* the unread count and unread notification elements appropriately.
*
* @param {jQuery} element
* @return {Promise|boolean}
* @method markAllAsRead
*/
NotificationPopoverController.prototype.markNotificationAsRead = function(element) {
if (!element.hasClass('unread')) {
return false;
}
return NotificationRepo.markAsRead(element.attr('data-id'))
.then(function() {
this.unreadCount--;
element.removeClass('unread');
}.bind(this));
};
/**
* Add all of the required event listeners for this notification popover.
*
@@ -361,7 +347,12 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url',
// Mark individual notification read if the user activates it.
this.root.on(CustomEvents.events.activate, SELECTORS.NOTIFICATION_LINK, function(e) {
var element = $(e.target).closest(SELECTORS.NOTIFICATION);
this.markNotificationAsRead(element);
if (element.hasClass('unread')) {
this.unreadCount--;
element.removeClass('unread');
}
e.stopPropagation();
}.bind(this));
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Mark a notification read and redirect to the relevant content.
*
* @package message_popup
* @copyright 2018 Michael Hawkins
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_login(null, false);
if (isguestuser()) {
redirect($CFG->wwwroot);
}
$notificationid = required_param('notificationid', PARAM_INT);
$redirecturl = optional_param('redirecturl', $CFG->wwwroot, PARAM_LOCALURL);
$notification = $DB->get_record('message', array('id' => $notificationid, 'notification' => 1));
// If found, is unread, so mark read if belongs to this user.
if ($notification) {
if ($USER->id == $notification->useridto) {
message_mark_message_read($notification, time());
} else {
$redirecturl = $CFG->wwwroot;
}
}
redirect($redirecturl);