Skip to content

Instantly share code, notes, and snippets.

@kgarfinkel
Created September 22, 2014 17:56
Show Gist options
  • Save kgarfinkel/d875cac501ce6b386061 to your computer and use it in GitHub Desktop.
Save kgarfinkel/d875cac501ce6b386061 to your computer and use it in GitHub Desktop.
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