codecombat/app/views/courses/HourOfCodeView.coffee
Scott Erickson 97cb5275c3 Fixes for courses, hoc
* Handling prepaids with strings for maxRedeemers
* Add link to TeacherCoursesView from HourOfCodeView
* Show only course instances with classrooms attached in TeacherCoursesView and StudentCoursesView
* Add event tracking to HourOfCodeView
* Add not-logged-in handling to TeacherCoursesView
* Fixed a GET prepaids bug
* Have course instances created for hour of code have hourOfCode property set to true.
2015-11-09 17:58:40 -08:00

49 lines
No EOL
1.7 KiB
CoffeeScript

app = require 'core/application'
AuthModal = require 'views/core/AuthModal'
CocoCollection = require 'collections/CocoCollection'
Course = require 'models/Course'
CourseInstance = require 'models/CourseInstance'
RootView = require 'views/core/RootView'
template = require 'templates/courses/hour-of-code-view'
utils = require 'core/utils'
module.exports = class HourOfCodeView extends RootView
id: 'hour-of-code-view'
template: template
events:
'click #student-btn': 'onClickStudentButton'
constructor: (options) ->
super(options)
@setUpHourOfCode()
setUpHourOfCode: ->
# If we are coming in at /hoc, then we show the landing page.
# If we have ?hoc=true (for the step after the landing page), then we show any HoC-specific instructions.
# If we haven't tracked this player as an hourOfCode player yet, and it's a new account, we do that now.
@hocLandingPage = true
@hocMode = true
elapsed = new Date() - new Date(me.get('dateCreated'))
if not me.get('hourOfCode') and (@hocLandingPage or @hocMode) and elapsed < 5 * 60 * 1000
me.set('hourOfCode', true)
me.patch()
$('body').append($('<img src="https://code.org/api/hour/begin_codecombat.png" style="visibility: hidden;">'))
application.tracker?.trackEvent 'Hour of Code Begin'
onClickStudentButton: ->
@state = 'enrolling'
@stateMessage = undefined
@render?()
$.ajax({
method: 'POST'
url: '/db/course_instance/-/create-for-hoc'
context: @
success: (data) ->
application.tracker?.trackEvent 'Finished HoC student course creation', {courseID: data.courseID}
app.router.navigate("/courses/#{data.courseID}/#{data._id}", {
trigger: true
})
})