MDL-54701 message: rename module imports in js

This commit is contained in:
Ryan Wyllie 2016-07-21 04:46:49 +00:00 committed by Mark Nelson
parent d4555a3d03
commit 195a683b27
4 changed files with 61 additions and 37 deletions

View file

@ -26,10 +26,10 @@
* @since 3.2 * @since 3.2
*/ */
define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str', define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str',
'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller', 'core/custom_interaction_events', 'core/popover_region_controller',
'core_message/message_repository', 'core/url'], 'core_message/message_repository', 'core/url'],
function($, bootstrap, ajax, templates, str, debugNotification, customEvents, function($, bootstrap, ajax, templates, str, CustomEvents,
PopoverController, messageRepo, URL) { PopoverController, MessageRepo, URL) {
var SELECTORS = { var SELECTORS = {
MARK_ALL_READ_BUTTON: '.mark-all-read-button', MARK_ALL_READ_BUTTON: '.mark-all-read-button',
@ -167,7 +167,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method loadUnreadMessageCount * @method loadUnreadMessageCount
*/ */
MessagePopoverController.prototype.loadUnreadMessageCount = function() { MessagePopoverController.prototype.loadUnreadMessageCount = function() {
messageRepo.countUnread({useridto: this.userId}).then(function(count) { MessageRepo.countUnread({useridto: this.userId}).then(function(count) {
this.unreadCount = count; this.unreadCount = count;
this.renderUnreadCount(); this.renderUnreadCount();
this.updateButtonAriaLabel(); this.updateButtonAriaLabel();
@ -231,7 +231,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}; };
var container = this.getContent(); var container = this.getContent();
var promise = messageRepo.query(request).then(function(result) { var promise = MessageRepo.query(request).then(function(result) {
var messages = result.contacts; var messages = result.contacts;
this.loadedAll = !messages.length || messages.length < this.limit; this.loadedAll = !messages.length || messages.length < this.limit;
this.initialLoad = true; this.initialLoad = true;
@ -256,7 +256,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
MessagePopoverController.prototype.markAllAsRead = function() { MessagePopoverController.prototype.markAllAsRead = function() {
this.markAllReadButton.addClass('loading'); this.markAllReadButton.addClass('loading');
return messageRepo.markAllAsRead({useridto: this.userId}) return MessageRepo.markAllAsRead({useridto: this.userId})
.then(function() { .then(function() {
this.unreadCount = 0; this.unreadCount = 0;
this.clearUnreadNotifications(); this.clearUnreadNotifications();
@ -270,8 +270,8 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method registerEventListeners * @method registerEventListeners
*/ */
MessagePopoverController.prototype.registerEventListeners = function() { MessagePopoverController.prototype.registerEventListeners = function() {
customEvents.define(this.root, [ CustomEvents.define(this.root, [
customEvents.events.keyboardActivate, CustomEvents.events.keyboardActivate,
]); ]);
// Update the notification information when the menu is opened. // Update the notification information when the menu is opened.
@ -291,7 +291,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Load more messages when we scroll to the bottom of the open menu. // Load more messages when we scroll to the bottom of the open menu.
this.root.on(customEvents.events.scrollBottom, function() { this.root.on(CustomEvents.events.scrollBottom, function() {
this.loadMoreMessages(); this.loadMoreMessages();
}.bind(this)); }.bind(this));
@ -309,7 +309,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Follow the link URL if the user activates it. // Follow the link URL if the user activates it.
this.root.on(customEvents.events.keyboardActivate, SELECTORS.LINK_URL, function(e) { this.root.on(CustomEvents.events.keyboardActivate, SELECTORS.LINK_URL, function(e) {
var linkItem = $(e.target).closest(SELECTORS.LINK_URL); var linkItem = $(e.target).closest(SELECTORS.LINK_URL);
this.navigateToLinkURL(linkItem, false); this.navigateToLinkURL(linkItem, false);
e.stopPropagation(); e.stopPropagation();

View file

@ -14,7 +14,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Retrieves notifications from the server. * Retrieves messages from the server.
* *
* @module core_message/message_repository * @module core_message/message_repository
* @class message_repository * @class message_repository
@ -24,6 +24,12 @@
* @since 3.2 * @since 3.2
*/ */
define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notification) { define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notification) {
/**
* Retrieve a list of messages from the server.
*
* @param {object} args The request arguments:
* @return {jQuery promise}
*/
var query = function(args) { var query = function(args) {
// Normalise the arguments to use limit/offset rather than limitnum/limitfrom. // Normalise the arguments to use limit/offset rather than limitnum/limitfrom.
if (typeof args.limit === 'undefined') { if (typeof args.limit === 'undefined') {
@ -53,11 +59,11 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notificat
}; };
var countUnread = function() { var countUnread = function() {
return $.Deferred(); return $.Deferred().resolve();
}; };
var markAllAsRead = function() { var markAllAsRead = function() {
return $.Deferred(); return $.Deferred().resolve();
}; };
return { return {

View file

@ -28,8 +28,8 @@
define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str', define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str',
'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller', 'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller',
'core_message/notification_repository'], 'core_message/notification_repository'],
function($, bootstrap, ajax, templates, str, debugNotification, customEvents, function($, bootstrap, ajax, templates, str, DebugNotification, CustomEvents,
popoverController, notificationRepo) { PopoverController, NotificationRepo) {
var SELECTORS = { var SELECTORS = {
MARK_ALL_READ_BUTTON: '.mark-all-read-button', MARK_ALL_READ_BUTTON: '.mark-all-read-button',
@ -58,7 +58,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
*/ */
var NotificationPopoverController = function(element) { var NotificationPopoverController = function(element) {
// Initialise base class. // Initialise base class.
popoverController.call(this, element); PopoverController.call(this, element);
this.markAllReadButton = this.root.find(SELECTORS.MARK_ALL_READ_BUTTON); this.markAllReadButton = this.root.find(SELECTORS.MARK_ALL_READ_BUTTON);
this.unreadCount = 0; this.unreadCount = 0;
@ -89,7 +89,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
/** /**
* Clone the parent prototype. * Clone the parent prototype.
*/ */
NotificationPopoverController.prototype = Object.create(popoverController.prototype); NotificationPopoverController.prototype = Object.create(PopoverController.prototype);
/** /**
* Set the correct aria label on the menu toggle button to be read out by screen * Set the correct aria label on the menu toggle button to be read out by screen
@ -270,7 +270,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method loadUnreadNotificationCount * @method loadUnreadNotificationCount
*/ */
NotificationPopoverController.prototype.loadUnreadNotificationCount = function() { NotificationPopoverController.prototype.loadUnreadNotificationCount = function() {
notificationRepo.countUnread({useridto: this.userId}).then(function(count) { NotificationRepo.countUnread({useridto: this.userId}).then(function(count) {
this.unreadCount = count; this.unreadCount = count;
this.renderUnreadCount(); this.renderUnreadCount();
this.updateButtonAriaLabel(); this.updateButtonAriaLabel();
@ -348,7 +348,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
} }
var container = this.getContent(); var container = this.getContent();
var promise = notificationRepo.query(request).then(function(result) { var promise = NotificationRepo.query(request).then(function(result) {
var notifications = result.notifications; var notifications = result.notifications;
this.unreadCount = result.unreadcount; this.unreadCount = result.unreadcount;
this.setLoadedAllContent(!notifications.length || notifications.length < this.limit); this.setLoadedAllContent(!notifications.length || notifications.length < this.limit);
@ -374,7 +374,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
NotificationPopoverController.prototype.markAllAsRead = function() { NotificationPopoverController.prototype.markAllAsRead = function() {
this.markAllReadButton.addClass('loading'); this.markAllReadButton.addClass('loading');
return notificationRepo.markAllAsRead({useridto: this.userId}) return NotificationRepo.markAllAsRead({useridto: this.userId})
.then(function() { .then(function() {
this.unreadCount = 0; this.unreadCount = 0;
this.clearUnreadNotifications(); this.clearUnreadNotifications();
@ -590,7 +590,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
var promise = ajax.call([request])[0]; var promise = ajax.call([request])[0];
promise.fail(debugNotification.exception); promise.fail(DebugNotification.exception);
promise.always(function() { promise.always(function() {
button.removeClass('loading'); button.removeClass('loading');
}); });
@ -607,17 +607,17 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method registerEventListeners * @method registerEventListeners
*/ */
NotificationPopoverController.prototype.registerEventListeners = function() { NotificationPopoverController.prototype.registerEventListeners = function() {
customEvents.define(this.root, [ CustomEvents.define(this.root, [
customEvents.events.activate, CustomEvents.events.activate,
customEvents.events.keyboardActivate, CustomEvents.events.keyboardActivate,
customEvents.events.next, CustomEvents.events.next,
customEvents.events.previous, CustomEvents.events.previous,
customEvents.events.asterix, CustomEvents.events.asterix,
]); ]);
// Expand the content item if the user activates (click/enter/space) the show // Expand the content item if the user activates (click/enter/space) the show
// button. // button.
this.root.on(customEvents.events.activate, SELECTORS.SHOW_BUTTON, function(e, data) { this.root.on(CustomEvents.events.activate, SELECTORS.SHOW_BUTTON, function(e, data) {
var container = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER); var container = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER);
this.expandContentItem(container); this.expandContentItem(container);
@ -626,13 +626,13 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Expand the content item if the user triggers the next event (right arrow in LTR). // Expand the content item if the user triggers the next event (right arrow in LTR).
this.root.on(customEvents.events.next, SELECTORS.CONTENT_ITEM_CONTAINER, function(e) { this.root.on(CustomEvents.events.next, SELECTORS.CONTENT_ITEM_CONTAINER, function(e) {
var contentItem = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER); var contentItem = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER);
this.expandContentItem(contentItem); this.expandContentItem(contentItem);
}.bind(this)); }.bind(this));
// Collapse the content item if the user activates the hide button. // Collapse the content item if the user activates the hide button.
this.root.on(customEvents.events.activate, SELECTORS.HIDE_BUTTON, function(e, data) { this.root.on(CustomEvents.events.activate, SELECTORS.HIDE_BUTTON, function(e, data) {
var container = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER); var container = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER);
this.collapseContentItem(container); this.collapseContentItem(container);
@ -641,12 +641,12 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Collapse the content item if the user triggers the previous event (left arrow in LTR). // Collapse the content item if the user triggers the previous event (left arrow in LTR).
this.root.on(customEvents.events.previous, SELECTORS.CONTENT_ITEM_CONTAINER, function(e) { this.root.on(CustomEvents.events.previous, SELECTORS.CONTENT_ITEM_CONTAINER, function(e) {
var contentItem = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER); var contentItem = $(e.target).closest(SELECTORS.CONTENT_ITEM_CONTAINER);
this.collapseContentItem(contentItem); this.collapseContentItem(contentItem);
}.bind(this)); }.bind(this));
this.root.on(customEvents.events.activate, SELECTORS.BLOCK_BUTTON, function(e, data) { this.root.on(CustomEvents.events.activate, SELECTORS.BLOCK_BUTTON, function(e, data) {
var button = $(e.target).closest(SELECTORS.BLOCK_BUTTON); var button = $(e.target).closest(SELECTORS.BLOCK_BUTTON);
this.disableNotificationType(button); this.disableNotificationType(button);
@ -655,7 +655,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Switch between popover states (read/unread) if the user activates the toggle. // Switch between popover states (read/unread) if the user activates the toggle.
this.root.on(customEvents.events.activate, SELECTORS.MODE_TOGGLE, function(e) { this.root.on(CustomEvents.events.activate, SELECTORS.MODE_TOGGLE, function(e) {
if (this.modeToggle.hasClass('on')) { if (this.modeToggle.hasClass('on')) {
this.clearUnreadNotifications(); this.clearUnreadNotifications();
this.modeToggle.removeClass('on'); this.modeToggle.removeClass('on');
@ -696,21 +696,21 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this)); }.bind(this));
// Follow the link URL if the user activates it. // Follow the link URL if the user activates it.
this.root.on(customEvents.events.keyboardActivate, SELECTORS.LINK_URL, function(e) { this.root.on(CustomEvents.events.keyboardActivate, SELECTORS.LINK_URL, function(e) {
var linkItem = $(e.target).closest(SELECTORS.LINK_URL); var linkItem = $(e.target).closest(SELECTORS.LINK_URL);
this.navigateToLinkURL(linkItem, false); this.navigateToLinkURL(linkItem, false);
e.stopPropagation(); e.stopPropagation();
}.bind(this)); }.bind(this));
// Mark all notifications read if the user activates the mark all as read button. // Mark all notifications read if the user activates the mark all as read button.
this.root.on(customEvents.events.activate, SELECTORS.MARK_ALL_READ_BUTTON, function(e) { this.root.on(CustomEvents.events.activate, SELECTORS.MARK_ALL_READ_BUTTON, function(e) {
this.markAllAsRead(); this.markAllAsRead();
e.stopPropagation(); e.stopPropagation();
}.bind(this)); }.bind(this));
// Expand all the currently visible content items if the user hits the // Expand all the currently visible content items if the user hits the
// asterix key. // asterix key.
this.root.on(customEvents.events.asterix, function() { this.root.on(CustomEvents.events.asterix, function() {
this.expandAllContentItems(); this.expandAllContentItems();
}.bind(this)); }.bind(this));
@ -743,7 +743,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
// Load more notifications if the user has scrolled to the end of content // Load more notifications if the user has scrolled to the end of content
// item list. // item list.
this.getContentContainer().on(customEvents.events.scrollBottom, function() { this.getContentContainer().on(CustomEvents.events.scrollBottom, function() {
if (!this.isLoading && !this.hasLoadedAllContent()) { if (!this.isLoading && !this.hasLoadedAllContent()) {
this.loadMoreNotifications(); this.loadMoreNotifications();
} }

View file

@ -24,6 +24,12 @@
* @since 3.2 * @since 3.2
*/ */
define(['core/ajax', 'core/notification'], function(ajax, notification) { define(['core/ajax', 'core/notification'], function(ajax, notification) {
/**
* Retrieve a list of notifications from the server.
*
* @param {object} args The request arguments:
* @return {jQuery promise}
*/
var query = function(args) { var query = function(args) {
if (typeof args.limit === 'undefined') { if (typeof args.limit === 'undefined') {
args.limit = 20; args.limit = 20;
@ -45,6 +51,12 @@ define(['core/ajax', 'core/notification'], function(ajax, notification) {
return promise; return promise;
}; };
/**
* Get the number of unread notifications from the server.
*
* @param {object} args The request arguments:
* @return {jQuery promise}
*/
var countUnread = function(args) { var countUnread = function(args) {
var request = { var request = {
methodname: 'core_message_get_unread_notification_count', methodname: 'core_message_get_unread_notification_count',
@ -58,6 +70,12 @@ define(['core/ajax', 'core/notification'], function(ajax, notification) {
return promise; return promise;
}; };
/**
* Mark all notifications for the given user as read.
*
* @param {object} args The request arguments:
* @return {jQuery promise}
*/
var markAllAsRead = function(args) { var markAllAsRead = function(args) {
var request = { var request = {
methodname: 'core_message_mark_all_notifications_as_read', methodname: 'core_message_mark_all_notifications_as_read',