Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions www/core/components/courses/services/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,14 @@ angular.module('mm.core.courses')
* @protected
*/
self.updateNavHandlersForCourse = function(courseId) {
var promises = [];

$mmUtil.emptyArray(coursesHandlers[courseId]);
var promises = [],
enabledForCourse = [];

angular.forEach(enabledNavHandlers, function(handler) {
// Checks if the handler is enabled for the user.
var promise = $q.when(handler.instance.isEnabledForCourse(courseId)).then(function(enabled) {
if (enabled) {
coursesHandlers[courseId].push({
controller: handler.instance.getController(courseId),
priority: handler.priority
});
enabledForCourse.push(handler);
} else {
return $q.reject();
}
Expand All @@ -202,6 +198,15 @@ angular.module('mm.core.courses')
}).catch(function() {
// Never fails.
return true;
}).finally(function() {
// Update the coursesHandlers array with the new enabled addons.
$mmUtil.emptyArray(coursesHandlers[courseId]);
angular.forEach(enabledForCourse, function(handler) {
coursesHandlers[courseId].push({
controller: handler.instance.getController(courseId),
priority: handler.priority
});
});
});
};

Expand Down