diff --git a/cms/static/js/index.js b/cms/static/js/index.js index e6bbf124c7..26206859eb 100644 --- a/cms/static/js/index.js +++ b/cms/static/js/index.js @@ -1,5 +1,6 @@ -define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/views/utils/create_course_utils"], - function (domReady, $, _, CancelOnEscape, CreateCourseUtilsFactory) { +define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/views/utils/create_course_utils", + "js/views/utils/view_utils"], + function (domReady, $, _, CancelOnEscape, CreateCourseUtilsFactory, ViewUtils) { var CreateCourseUtils = CreateCourseUtilsFactory({ name: '.new-course-name', org: '.new-course-org', @@ -19,16 +20,6 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie error: 'error' }); - var dismissNotification = function (e) { - e.preventDefault(); - $.ajax({ - url: $(this).data('dismiss-link'), - type: 'DELETE', - success: function(result) { - window.location.reload(); - } - }); - }; var saveNewCourse = function (e) { e.preventDefault(); @@ -90,13 +81,14 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie var onReady = function () { $('.new-course-button').bind('click', addNewCourse); - $('.dismiss-button').bind('click', dismissNotification); + $('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function () { + window.location.reload(); + })); }; domReady(onReady); return { - dismissNotification: dismissNotification, onReady: onReady }; }); diff --git a/cms/static/js/views/overview.js b/cms/static/js/views/overview.js index 8ceaa40681..f83d46ee9e 100644 --- a/cms/static/js/views/overview.js +++ b/cms/static/js/views/overview.js @@ -1,21 +1,10 @@ define(["domReady", "jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notification", - "js/utils/cancel_on_escape", "js/utils/date_utils", "js/utils/module"], + "js/utils/cancel_on_escape", "js/utils/date_utils", "js/utils/module", "js/views/utils/view_utils"], function (domReady, $, ui, _, gettext, NotificationView, CancelOnEscape, - DateUtils, ModuleUtils) { + DateUtils, ModuleUtils, ViewUtils) { var modalSelector = '.edit-section-publish-settings'; - var dismissNotification = function (e) { - e.preventDefault(); - $.ajax({ - url: $('.dismiss-button').data('dismiss-link'), - type: 'GET', - success: function(result) { - $('.wrapper-alert-announcement').remove() - } - }); - }; - var toggleSections = function(e) { e.preventDefault(); @@ -233,7 +222,9 @@ define(["domReady", "jquery", "jquery.ui", "underscore", "gettext", "js/views/fe $('.toggle-button-sections').bind('click', toggleSections); $('.expand-collapse').bind('click', toggleSubmodules); - $('.dismiss-button').bind('click', dismissNotification); + $('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function () { + $('.wrapper-alert-announcement').remove(); + })); var $body = $('body'); $body.on('click', '.section-published-date .edit-release-date', editSectionPublishDate); diff --git a/cms/static/js/views/pages/course_outline.js b/cms/static/js/views/pages/course_outline.js index 87ba45309e..a812eb7b02 100644 --- a/cms/static/js/views/pages/course_outline.js +++ b/cms/static/js/views/pages/course_outline.js @@ -2,8 +2,8 @@ * This page is used to show the user an outline of the course. */ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views/utils/xblock_utils", - "js/views/course_outline"], - function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView) { + "js/views/course_outline", "js/views/utils/view_utils"], + function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView, ViewUtils) { var expandedLocators, CourseOutlinePage; CourseOutlinePage = BasePage.extend({ @@ -25,7 +25,9 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views self.outlineView.handleAddEvent(event); }); this.model.on('change', this.setCollapseExpandVisibility, this); - $('.dismiss-button').bind('click', this.dismissNotification); + $('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function () { + $('.wrapper-alert-announcement').removeClass('is-shown').addClass('is-hidden') + })); }, setCollapseExpandVisibility: function() { @@ -98,20 +100,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views } }, this); } - }, - - /** - * Dismiss the course rerun notification. - */ - dismissNotification: function (e) { - e.preventDefault(); - $.ajax({ - url: $('.dismiss-button').data('dismiss-link'), - type: 'DELETE', - success: function(result) { - $('.wrapper-alert-announcement').removeClass('is-shown').addClass('is-hidden') - } - }); } }); diff --git a/cms/static/js/views/utils/view_utils.js b/cms/static/js/views/utils/view_utils.js index 98eab24d96..9719ea9247 100644 --- a/cms/static/js/views/utils/view_utils.js +++ b/cms/static/js/views/utils/view_utils.js @@ -5,7 +5,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js function ($, _, gettext, NotificationView, PromptView) { var toggleExpandCollapse, showLoadingIndicator, hideLoadingIndicator, confirmThenRunOperation, runOperationShowingMessage, disableElementWhileRunning, getScrollOffset, setScrollOffset, - setScrollTop, redirect, hasChangedAttributes; + setScrollTop, redirect, hasChangedAttributes, deleteNotificationHandler; /** * Toggles the expanded state of the current element. @@ -94,6 +94,21 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js }); }; + /** + * Returns a handler that removes a notification, both dismissing it and deleting it from the database. + * @param callback function to call when deletion succeeds + */ + deleteNotificationHandler = function(callback) { + return function (event) { + event.preventDefault(); + $.ajax({ + url: $(this).data('dismiss-link'), + type: 'DELETE', + success: callback + }); + }; + }; + /** * Performs an animated scroll so that the window has the specified scroll top. * @param scrollTop The desired scroll top for the window. @@ -158,6 +173,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js 'confirmThenRunOperation': confirmThenRunOperation, 'runOperationShowingMessage': runOperationShowingMessage, 'disableElementWhileRunning': disableElementWhileRunning, + 'deleteNotificationHandler': deleteNotificationHandler, 'setScrollTop': setScrollTop, 'getScrollOffset': getScrollOffset, 'setScrollOffset': setScrollOffset,