diff --git a/lms/djangoapps/teams/static/teams/js/spec/teams_tab_factory_spec.js b/lms/djangoapps/teams/static/teams/js/spec/teams_tab_factory_spec.js index d41cfce9d5..de6b4e104b 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/teams_tab_factory_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/teams_tab_factory_spec.js @@ -1,6 +1,6 @@ -define(['jquery', 'backbone', 'teams/js/teams_tab_factory', +define(['jquery', 'backbone', 'teams/js/teams_tab_factory', 'teams/js/views/teams_tab', 'common/js/spec_helpers/page_helpers', 'teams/js/spec_helpers/team_spec_helpers'], - function($, Backbone, TeamsTabFactory, PageHelpers, TeamSpecHelpers) { + function($, Backbone, TeamsTabFactory, TeamsTabView, PageHelpers, TeamSpecHelpers) { 'use strict'; describe("Teams Tab Factory", function() { @@ -15,6 +15,7 @@ define(['jquery', 'backbone', 'teams/js/teams_tab_factory', afterEach(function() { Backbone.history.stop(); + $(document).off('ajaxError', TeamsTabView.prototype.errorHandler); }); it('can render the "Teams" tab', function() { diff --git a/lms/djangoapps/teams/static/teams/js/spec/views/teams_tab_spec.js b/lms/djangoapps/teams/static/teams/js/spec/views/teams_tab_spec.js index e9f58659dd..2f236433e1 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/views/teams_tab_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/views/teams_tab_spec.js @@ -56,7 +56,11 @@ define([ spyOn(Logger, 'log'); }); - afterEach(Backbone.history.stop); + afterEach(function() { + Backbone.history.stop(); + $(document).off('ajaxError', TeamsTabView.prototype.errorHandler); + } + ); describe('Navigation', function () { it('does not render breadcrumbs for the top level tabs', function() { diff --git a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js index 7aadb4fed2..69e5241213 100644 --- a/lms/djangoapps/teams/static/teams/js/views/teams_tab.js +++ b/lms/djangoapps/teams/static/teams/js/views/teams_tab.js @@ -159,14 +159,7 @@ start: function() { Backbone.history.start(); - $(document).ajaxError(function (event, xhr) { - if (xhr.status === 401) { - TeamUtils.showMessage(gettext("Your request could not be completed. Reload the page and try again.")); - } - else if (xhr.status === 500) { - TeamUtils.showMessage(gettext("Your request could not be completed due to a server problem. Reload the page and try again. If the issue persists, click the Help tab to report the problem.")); - } - }); + $(document).ajaxError(this.errorHandler); // Navigate to the default page if there is no history: // 1. If the user belongs to at least one team, jump to the "My Teams" page @@ -180,6 +173,20 @@ } }, + errorHandler: function(event, xhr) { + if (xhr.status === 401) { + TeamUtils.showMessage(gettext( + "Your request could not be completed. Reload the page and try again." + )); + } + else if (xhr.status === 500) { + TeamUtils.showMessage(gettext( + "Your request could not be completed due to a server problem. Reload the page" + + " and try again. If the issue persists, click the Help tab to report the problem." + )); + } + }, + render: function() { this.mainView.setElement(this.$el).render(); TeamUtils.hideMessage();