Commit 1778c157 by Ben McMorran

Refactor dismissNotification uses into shared logic in view_utils

parent d1ffecf3
define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/views/utils/create_course_utils"], define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/views/utils/create_course_utils",
function (domReady, $, _, CancelOnEscape, CreateCourseUtilsFactory) { "js/views/utils/view_utils"],
function (domReady, $, _, CancelOnEscape, CreateCourseUtilsFactory, ViewUtils) {
var CreateCourseUtils = CreateCourseUtilsFactory({ var CreateCourseUtils = CreateCourseUtilsFactory({
name: '.new-course-name', name: '.new-course-name',
org: '.new-course-org', org: '.new-course-org',
...@@ -19,16 +20,6 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie ...@@ -19,16 +20,6 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie
error: 'error' 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) { var saveNewCourse = function (e) {
e.preventDefault(); e.preventDefault();
...@@ -90,13 +81,14 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie ...@@ -90,13 +81,14 @@ define(["domReady", "jquery", "underscore", "js/utils/cancel_on_escape", "js/vie
var onReady = function () { var onReady = function () {
$('.new-course-button').bind('click', addNewCourse); $('.new-course-button').bind('click', addNewCourse);
$('.dismiss-button').bind('click', dismissNotification); $('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function () {
window.location.reload();
}));
}; };
domReady(onReady); domReady(onReady);
return { return {
dismissNotification: dismissNotification,
onReady: onReady onReady: onReady
}; };
}); });
define(["domReady", "jquery", "jquery.ui", "underscore", "gettext", "js/views/feedback_notification", 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, function (domReady, $, ui, _, gettext, NotificationView, CancelOnEscape,
DateUtils, ModuleUtils) { DateUtils, ModuleUtils, ViewUtils) {
var modalSelector = '.edit-section-publish-settings'; 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) { var toggleSections = function(e) {
e.preventDefault(); e.preventDefault();
...@@ -233,7 +222,9 @@ define(["domReady", "jquery", "jquery.ui", "underscore", "gettext", "js/views/fe ...@@ -233,7 +222,9 @@ define(["domReady", "jquery", "jquery.ui", "underscore", "gettext", "js/views/fe
$('.toggle-button-sections').bind('click', toggleSections); $('.toggle-button-sections').bind('click', toggleSections);
$('.expand-collapse').bind('click', toggleSubmodules); $('.expand-collapse').bind('click', toggleSubmodules);
$('.dismiss-button').bind('click', dismissNotification); $('.dismiss-button').bind('click', ViewUtils.deleteNotificationHandler(function () {
$('.wrapper-alert-announcement').remove();
}));
var $body = $('body'); var $body = $('body');
$body.on('click', '.section-published-date .edit-release-date', editSectionPublishDate); $body.on('click', '.section-published-date .edit-release-date', editSectionPublishDate);
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* This page is used to show the user an outline of the course. * 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", define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views/utils/xblock_utils",
"js/views/course_outline"], "js/views/course_outline", "js/views/utils/view_utils"],
function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView) { function ($, _, gettext, BasePage, XBlockViewUtils, CourseOutlineView, ViewUtils) {
var expandedLocators, CourseOutlinePage; var expandedLocators, CourseOutlinePage;
CourseOutlinePage = BasePage.extend({ CourseOutlinePage = BasePage.extend({
...@@ -25,7 +25,9 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -25,7 +25,9 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
self.outlineView.handleAddEvent(event); self.outlineView.handleAddEvent(event);
}); });
this.model.on('change', this.setCollapseExpandVisibility, this); 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() { setCollapseExpandVisibility: function() {
...@@ -98,20 +100,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -98,20 +100,6 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
} }
}, this); }, 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')
}
});
} }
}); });
......
...@@ -5,7 +5,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js ...@@ -5,7 +5,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js
function ($, _, gettext, NotificationView, PromptView) { function ($, _, gettext, NotificationView, PromptView) {
var toggleExpandCollapse, showLoadingIndicator, hideLoadingIndicator, confirmThenRunOperation, var toggleExpandCollapse, showLoadingIndicator, hideLoadingIndicator, confirmThenRunOperation,
runOperationShowingMessage, disableElementWhileRunning, getScrollOffset, setScrollOffset, runOperationShowingMessage, disableElementWhileRunning, getScrollOffset, setScrollOffset,
setScrollTop, redirect, hasChangedAttributes; setScrollTop, redirect, hasChangedAttributes, deleteNotificationHandler;
/** /**
* Toggles the expanded state of the current element. * Toggles the expanded state of the current element.
...@@ -95,6 +95,21 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js ...@@ -95,6 +95,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. * Performs an animated scroll so that the window has the specified scroll top.
* @param scrollTop The desired scroll top for the window. * @param scrollTop The desired scroll top for the window.
*/ */
...@@ -158,6 +173,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js ...@@ -158,6 +173,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js
'confirmThenRunOperation': confirmThenRunOperation, 'confirmThenRunOperation': confirmThenRunOperation,
'runOperationShowingMessage': runOperationShowingMessage, 'runOperationShowingMessage': runOperationShowingMessage,
'disableElementWhileRunning': disableElementWhileRunning, 'disableElementWhileRunning': disableElementWhileRunning,
'deleteNotificationHandler': deleteNotificationHandler,
'setScrollTop': setScrollTop, 'setScrollTop': setScrollTop,
'getScrollOffset': getScrollOffset, 'getScrollOffset': getScrollOffset,
'setScrollOffset': setScrollOffset, 'setScrollOffset': setScrollOffset,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment