Created
September 22, 2014 17:56
-
-
Save kgarfinkel/d875cac501ce6b386061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define [ | |
'cdn.jquery' | |
'cdn.backbone' | |
'scripts/helpers/common' | |
'scripts/mediator' | |
'site/models/notification' | |
'site/collections/notifications' | |
'site/views/notification_collection' | |
], ($, Backbone, commonHelper, mediator, Notification, Notifications, NotificationCollectionView) -> | |
alerts = [] | |
cloneCatalogCourse: (courseId, courseTitle, target) -> | |
requestUrl = window.bootstrap.siteUrl + '/courses' | |
toggleSpinnerCloneIcon = -> | |
$(target).removeClass 'hide' | |
$(target).next().empty() | |
showAlert = -> | |
alertMessage = { | |
message: 'There was an error in cloning ' + courseTitle + ', please try again.' | |
isDismissable: true | |
errorIcon: true | |
} | |
if !alerts.length | |
alerts = new Notifications [alertMessage] | |
ncv = new NotificationCollectionView collection: alerts | |
$('.js-global-alerts').replaceWith ncv.render().$el | |
else | |
alerts.push alertMessage | |
$.ajax | |
url: requestUrl | |
type: 'post' | |
data: | |
cloneOf: courseId | |
error: () -> | |
showAlert() | |
toggleSpinnerCloneIcon() | |
success: () -> | |
window.location.href = '/profile' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment