Skip to content

Instantly share code, notes, and snippets.

@lunks
Created April 1, 2015 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunks/5e70e7940227622055eb to your computer and use it in GitHub Desktop.
Save lunks/5e70e7940227622055eb to your computer and use it in GitHub Desktop.
diff --git a/app/assets/javascripts/angular/apps/teachers/controllers/NotificationCtrl.js.coffee b/app/assets/javascripts/angular/apps/teachers/controllers/NotificationCtrl.js.coffee
index 0bc054e..0e616ab 100644
--- a/app/assets/javascripts/angular/apps/teachers/controllers/NotificationCtrl.js.coffee
+++ b/app/assets/javascripts/angular/apps/teachers/controllers/NotificationCtrl.js.coffee
@@ -25,10 +25,20 @@ NotificationCtrl = ($scope, $timeout, $analytics, Notification, ErrorParser)->
course = $scope.$parent.course
notification.course_id = course.uuid
notification.abbreviation = course.abbreviation
- notification.save().then(->
+ notification.save().then((response)->
$scope.reset()
$scope.setSent()
- $analytics.eventTrack('Notification Sent', courseName: course.name, courseUuid: course.uuid, message: notification.message)
+
+ # Adapted from: http://goo.gl/w4QP8W
+ if response && response.status && response.status == 200 && response.data
+ i = 0
+ while i < course.events.length
+ event = course.events[i]
+ i++
+ if event.status == 'published' && new Date(event.start_at) > new Date()
+ configuration = $analytics.config(api_token: 'ba7c28ba8ca86f15b248f7cccfffjf525', group: 'Notification')
+ $analytics.eventTrack('Notification Sent', courseName: course.name, courseUuid: course.uuid, message: notification.message, eventUuid: event.uuid, configuration: configuration)
+ configuration.$finish()
).catch((response)->
$scope.hasError = true
ErrorParser.setErrors(response.data.errors, $scope.notification_form, $scope)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment