2016-01-19 18:42:20 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
|
|
|
template = require 'templates/play/level/modal/course-victory-modal'
|
|
|
|
Level = require 'models/Level'
|
|
|
|
Course = require 'models/Course'
|
|
|
|
LevelSessions = require 'collections/LevelSessions'
|
|
|
|
ProgressView = require './ProgressView'
|
2016-04-13 12:54:24 -04:00
|
|
|
Classroom = require 'models/Classroom'
|
2016-04-13 19:32:39 -04:00
|
|
|
utils = require 'core/utils'
|
2016-01-19 18:42:20 -05:00
|
|
|
|
|
|
|
module.exports = class CourseVictoryModal extends ModalView
|
|
|
|
id: 'course-victory-modal'
|
|
|
|
template: template
|
|
|
|
closesOnClickOutside: false
|
|
|
|
|
|
|
|
initialize: (options) ->
|
|
|
|
@courseID = options.courseID
|
|
|
|
@courseInstanceID = options.courseInstanceID
|
|
|
|
@views = []
|
|
|
|
|
|
|
|
@session = options.session
|
|
|
|
@level = options.level
|
2016-07-11 19:01:34 -04:00
|
|
|
|
2016-04-27 18:36:16 -04:00
|
|
|
if @courseInstanceID
|
|
|
|
@classroom = new Classroom()
|
|
|
|
@supermodel.trackRequest(@classroom.fetchForCourseInstance(@courseInstanceID))
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
@playSound 'victory'
|
2016-04-13 12:54:24 -04:00
|
|
|
@nextLevel = new Level()
|
2016-06-26 16:51:14 -04:00
|
|
|
@nextLevelRequest = @supermodel.trackRequest(@nextLevel.fetchNextForCourse({
|
|
|
|
levelOriginalID: @level.get('original')
|
|
|
|
@courseInstanceID
|
|
|
|
@courseID
|
|
|
|
sessionID: @session.id
|
|
|
|
}))
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
@course = options.course
|
|
|
|
if @courseID and not @course
|
|
|
|
@course = new Course().setURL "/db/course/#{@courseID}"
|
2016-02-18 11:44:40 -05:00
|
|
|
@course = @supermodel.loadModel(@course).model
|
2016-01-19 18:42:20 -05:00
|
|
|
|
|
|
|
if @courseInstanceID
|
|
|
|
@levelSessions = new LevelSessions()
|
|
|
|
@levelSessions.fetchForCourseInstance(@courseInstanceID)
|
2016-02-18 11:44:40 -05:00
|
|
|
@levelSessions = @supermodel.loadCollection(@levelSessions, 'sessions', {
|
2016-01-19 18:42:20 -05:00
|
|
|
data: { project: 'state.complete level.original playtime changed' }
|
|
|
|
}).model
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Victory Modal Loaded', category: 'Students', levelSlug: @level.get('slug'), ['Mixpanel']
|
2016-01-19 18:42:20 -05:00
|
|
|
|
2016-04-13 12:54:24 -04:00
|
|
|
onResourceLoadFailed: (e) ->
|
|
|
|
if e.resource.jqxhr is @nextLevelRequest
|
|
|
|
return
|
|
|
|
super(arguments...)
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
onLoaded: ->
|
|
|
|
super()
|
|
|
|
@views = []
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-07-11 16:28:48 -04:00
|
|
|
@levelSessions?.remove(@session)
|
|
|
|
@levelSessions?.add(@session)
|
2016-01-19 18:42:20 -05:00
|
|
|
progressView = new ProgressView({
|
|
|
|
level: @level
|
|
|
|
nextLevel: @nextLevel
|
|
|
|
course: @course
|
2016-04-13 12:54:24 -04:00
|
|
|
classroom: @classroom
|
2016-01-19 18:42:20 -05:00
|
|
|
levelSessions: @levelSessions
|
|
|
|
})
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
progressView.once 'done', @onDone, @
|
|
|
|
progressView.once 'next-level', @onNextLevel, @
|
|
|
|
for view in @views
|
|
|
|
view.on 'continue', @onViewContinue, @
|
|
|
|
@views.push(progressView)
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
@showView(_.first(@views))
|
2016-02-18 11:44:40 -05:00
|
|
|
|
2016-01-19 18:42:20 -05:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@showView(@currentView)
|
|
|
|
|
|
|
|
showView: (view) ->
|
|
|
|
return unless view
|
|
|
|
view.setElement(@$('.modal-content'))
|
|
|
|
view.$el.attr('id', view.id)
|
|
|
|
view.$el.addClass(view.className)
|
|
|
|
view.render()
|
|
|
|
@currentView = view
|
|
|
|
|
|
|
|
onViewContinue: ->
|
|
|
|
index = _.indexOf(@views, @currentView)
|
|
|
|
@showView(@views[index+1])
|
|
|
|
|
|
|
|
onNextLevel: ->
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Victory Modal Next Level', category: 'Students', levelSlug: @level.get('slug'), nextLevelSlug: @nextLevel.get('slug'), ['Mixpanel']
|
2016-04-15 13:58:52 -04:00
|
|
|
if me.isSessionless()
|
2016-04-13 19:32:39 -04:00
|
|
|
link = "/play/level/#{@nextLevel.get('slug')}?course=#{@courseID}&codeLanguage=#{utils.getQueryVariable('codeLanguage', 'python')}"
|
2016-04-08 15:59:10 -04:00
|
|
|
else
|
|
|
|
link = "/play/level/#{@nextLevel.get('slug')}?course=#{@courseID}&course-instance=#{@courseInstanceID}"
|
2016-01-19 18:42:20 -05:00
|
|
|
application.router.navigate(link, {trigger: true})
|
|
|
|
|
|
|
|
onDone: ->
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Play Level Victory Modal Done', category: 'Students', levelSlug: @level.get('slug'), ['Mixpanel']
|
2016-04-15 13:58:52 -04:00
|
|
|
if me.isSessionless()
|
2016-04-08 15:59:10 -04:00
|
|
|
link = "/teachers/courses"
|
|
|
|
else
|
|
|
|
link = "/courses/#{@courseID}/#{@courseInstanceID}"
|
2016-01-19 18:42:20 -05:00
|
|
|
application.router.navigate(link, {trigger: true})
|