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
*/
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'],
function($, bootstrap, ajax, templates, str, debugNotification, customEvents,
PopoverController, messageRepo, URL) {
function($, bootstrap, ajax, templates, str, CustomEvents,
PopoverController, MessageRepo, URL) {
var SELECTORS = {
MARK_ALL_READ_BUTTON: '.mark-all-read-button',
@ -167,7 +167,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method loadUnreadMessageCount
*/
MessagePopoverController.prototype.loadUnreadMessageCount = function() {
messageRepo.countUnread({useridto: this.userId}).then(function(count) {
MessageRepo.countUnread({useridto: this.userId}).then(function(count) {
this.unreadCount = count;
this.renderUnreadCount();
this.updateButtonAriaLabel();
@ -231,7 +231,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
};
var container = this.getContent();
var promise = messageRepo.query(request).then(function(result) {
var promise = MessageRepo.query(request).then(function(result) {
var messages = result.contacts;
this.loadedAll = !messages.length || messages.length < this.limit;
this.initialLoad = true;
@ -256,7 +256,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
MessagePopoverController.prototype.markAllAsRead = function() {
this.markAllReadButton.addClass('loading');
return messageRepo.markAllAsRead({useridto: this.userId})
return MessageRepo.markAllAsRead({useridto: this.userId})
.then(function() {
this.unreadCount = 0;
this.clearUnreadNotifications();
@ -270,8 +270,8 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method registerEventListeners
*/
MessagePopoverController.prototype.registerEventListeners = function() {
customEvents.define(this.root, [
customEvents.events.keyboardActivate,
CustomEvents.define(this.root, [
CustomEvents.events.keyboardActivate,
]);
// Update the notification information when the menu is opened.
@ -291,7 +291,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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();
}.bind(this));
@ -309,7 +309,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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);
this.navigateToLinkURL(linkItem, false);
e.stopPropagation();

View File

@ -14,7 +14,7 @@
// 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
* @class message_repository
@ -24,6 +24,12 @@
* @since 3.2
*/
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) {
// Normalise the arguments to use limit/offset rather than limitnum/limitfrom.
if (typeof args.limit === 'undefined') {
@ -53,11 +59,11 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, ajax, notificat
};
var countUnread = function() {
return $.Deferred();
return $.Deferred().resolve();
};
var markAllAsRead = function() {
return $.Deferred();
return $.Deferred().resolve();
};
return {

View File

@ -28,8 +28,8 @@
define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates', 'core/str',
'core/notification', 'core/custom_interaction_events', 'core/popover_region_controller',
'core_message/notification_repository'],
function($, bootstrap, ajax, templates, str, debugNotification, customEvents,
popoverController, notificationRepo) {
function($, bootstrap, ajax, templates, str, DebugNotification, CustomEvents,
PopoverController, NotificationRepo) {
var SELECTORS = {
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) {
// Initialise base class.
popoverController.call(this, element);
PopoverController.call(this, element);
this.markAllReadButton = this.root.find(SELECTORS.MARK_ALL_READ_BUTTON);
this.unreadCount = 0;
@ -89,7 +89,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
/**
* 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
@ -270,7 +270,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method loadUnreadNotificationCount
*/
NotificationPopoverController.prototype.loadUnreadNotificationCount = function() {
notificationRepo.countUnread({useridto: this.userId}).then(function(count) {
NotificationRepo.countUnread({useridto: this.userId}).then(function(count) {
this.unreadCount = count;
this.renderUnreadCount();
this.updateButtonAriaLabel();
@ -348,7 +348,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}
var container = this.getContent();
var promise = notificationRepo.query(request).then(function(result) {
var promise = NotificationRepo.query(request).then(function(result) {
var notifications = result.notifications;
this.unreadCount = result.unreadcount;
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() {
this.markAllReadButton.addClass('loading');
return notificationRepo.markAllAsRead({useridto: this.userId})
return NotificationRepo.markAllAsRead({useridto: this.userId})
.then(function() {
this.unreadCount = 0;
this.clearUnreadNotifications();
@ -590,7 +590,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
var promise = ajax.call([request])[0];
promise.fail(debugNotification.exception);
promise.fail(DebugNotification.exception);
promise.always(function() {
button.removeClass('loading');
});
@ -607,17 +607,17 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
* @method registerEventListeners
*/
NotificationPopoverController.prototype.registerEventListeners = function() {
customEvents.define(this.root, [
customEvents.events.activate,
customEvents.events.keyboardActivate,
customEvents.events.next,
customEvents.events.previous,
customEvents.events.asterix,
CustomEvents.define(this.root, [
CustomEvents.events.activate,
CustomEvents.events.keyboardActivate,
CustomEvents.events.next,
CustomEvents.events.previous,
CustomEvents.events.asterix,
]);
// Expand the content item if the user activates (click/enter/space) the show
// 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);
this.expandContentItem(container);
@ -626,13 +626,13 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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);
this.expandContentItem(contentItem);
}.bind(this));
// 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);
this.collapseContentItem(container);
@ -641,12 +641,12 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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);
this.collapseContentItem(contentItem);
}.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);
this.disableNotificationType(button);
@ -655,7 +655,7 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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')) {
this.clearUnreadNotifications();
this.modeToggle.removeClass('on');
@ -696,21 +696,21 @@ define(['jquery', 'theme_bootstrapbase/bootstrap', 'core/ajax', 'core/templates'
}.bind(this));
// 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);
this.navigateToLinkURL(linkItem, false);
e.stopPropagation();
}.bind(this));
// 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();
e.stopPropagation();
}.bind(this));
// Expand all the currently visible content items if the user hits the
// asterix key.
this.root.on(customEvents.events.asterix, function() {
this.root.on(CustomEvents.events.asterix, function() {
this.expandAllContentItems();
}.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
// item list.
this.getContentContainer().on(customEvents.events.scrollBottom, function() {
this.getContentContainer().on(CustomEvents.events.scrollBottom, function() {
if (!this.isLoading && !this.hasLoadedAllContent()) {
this.loadMoreNotifications();
}

View File

@ -24,6 +24,12 @@
* @since 3.2
*/
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) {
if (typeof args.limit === 'undefined') {
args.limit = 20;
@ -45,6 +51,12 @@ define(['core/ajax', 'core/notification'], function(ajax, notification) {
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 request = {
methodname: 'core_message_get_unread_notification_count',
@ -58,6 +70,12 @@ define(['core/ajax', 'core/notification'], function(ajax, notification) {
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 request = {
methodname: 'core_message_mark_all_notifications_as_read',