codecombat/app/views/play/level/modal/CourseVictoryModal.coffee

128 lines
4.5 KiB
CoffeeScript
Raw Normal View History

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'
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 or @getQueryVariable('course-instance') or @getQueryVariable('league')
2016-01-19 18:42:20 -05:00
@views = []
@session = options.session
@level = options.level
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()
@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
if not @course
@course = new Course()
@supermodel.trackRequest @course.fetchForCourseInstance(@courseInstanceID)
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()
@courseID ?= @course.id
2016-01-19 18:42:20 -05:00
@views = []
2016-02-18 11:44:40 -05: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
session: @session
2016-01-19 18:42:20 -05:00
})
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, @
progressView.once 'ladder', @onLadder, @
2016-01-19 18:42:20 -05:00
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: ->
window.tracker?.trackEvent 'Play Level Victory Modal Next Level', category: 'Students', levelSlug: @level.get('slug'), nextLevelSlug: @nextLevel.get('slug'), ['Mixpanel']
if me.isSessionless()
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}"
link += "&codeLanguage=" + @level.get('primerLanguage') if @level.get('primerLanguage')
2016-01-19 18:42:20 -05:00
application.router.navigate(link, {trigger: true})
onDone: ->
window.tracker?.trackEvent 'Play Level Victory Modal Done', category: 'Students', levelSlug: @level.get('slug'), ['Mixpanel']
if me.isSessionless()
Game dev levels (#3810) * Tweak API doc behavior and styling * Instead of moving to the left during active dialogues, just move to the top * Allow pointer events * Adjust close button * Re-enable pinning API docs for game-dev and web-dev levels * Make sidebar in PlayGameDevLevelView stretch, better layout columns * Set up content of PlayGameDevLevelView sidebar to scroll * Add rest of PlayGameDevLevelView sidebar content, rework what loading looks like * Finish PlayGameDevLevelView * Add share area below * Cover the brown background, paint it gray * Tweak PlayGameDevLevelView * Have progress bar show everything * Fix Surface resize handling * Fix PlayGameDevLevelView resizing incorrectly when playing * Add GameDevVictoryModal to PlayGameDevLevelView * Don't show missing-doctype annotation in Ace * Hook up GameDevVictoryModal copy button * Fix onChangeAnnotation runtime error * Fix onLevelLoaded runtime error * Have CourseVictoryModal link to /courses when course is done * Trim, update CourseDetailsView * Remove last vestiges of teacherMode * Remove giant navigation buttons at top * Quick switch to flat style * Add analytics for game-dev * Update Analytics events for gamedev * Prefix event names with context * Send to Mixpanel * Include more properties * Mostly set up indefinite play and autocast for game-dev levels * Set up cast buttons and shortcut for game-dev * Add rudimentary instructions when students play game-dev levels * Couple tweaks * fix a bit of code that expects frames to always stick around * have PlayGameDevLevelView render a couple frames on load * API Docs use 'game' instead of 'hero' * Move tags to head without combining * Add HTML comment-start string Fixes missing entry point arrows * Fix some whitespace
2016-07-28 16:39:58 -04:00
link = '/teachers/courses'
2016-04-08 15:59:10 -04:00
else
Game dev levels (#3810) * Tweak API doc behavior and styling * Instead of moving to the left during active dialogues, just move to the top * Allow pointer events * Adjust close button * Re-enable pinning API docs for game-dev and web-dev levels * Make sidebar in PlayGameDevLevelView stretch, better layout columns * Set up content of PlayGameDevLevelView sidebar to scroll * Add rest of PlayGameDevLevelView sidebar content, rework what loading looks like * Finish PlayGameDevLevelView * Add share area below * Cover the brown background, paint it gray * Tweak PlayGameDevLevelView * Have progress bar show everything * Fix Surface resize handling * Fix PlayGameDevLevelView resizing incorrectly when playing * Add GameDevVictoryModal to PlayGameDevLevelView * Don't show missing-doctype annotation in Ace * Hook up GameDevVictoryModal copy button * Fix onChangeAnnotation runtime error * Fix onLevelLoaded runtime error * Have CourseVictoryModal link to /courses when course is done * Trim, update CourseDetailsView * Remove last vestiges of teacherMode * Remove giant navigation buttons at top * Quick switch to flat style * Add analytics for game-dev * Update Analytics events for gamedev * Prefix event names with context * Send to Mixpanel * Include more properties * Mostly set up indefinite play and autocast for game-dev levels * Set up cast buttons and shortcut for game-dev * Add rudimentary instructions when students play game-dev levels * Couple tweaks * fix a bit of code that expects frames to always stick around * have PlayGameDevLevelView render a couple frames on load * API Docs use 'game' instead of 'hero' * Move tags to head without combining * Add HTML comment-start string Fixes missing entry point arrows * Fix some whitespace
2016-07-28 16:39:58 -04:00
link = '/courses'
2016-01-19 18:42:20 -05:00
application.router.navigate(link, {trigger: true})
onLadder: ->
# Preserve the supermodel as we navigate back to the ladder.
viewArgs = [{supermodel: if @options.hasReceivedMemoryWarning then null else @supermodel}, @level.get('slug')]
ladderURL = "/play/ladder/#{@level.get('slug') || @level.id}"
if leagueID = (@courseInstanceID or @getQueryVariable 'league')
leagueType = if @level.get('type') is 'course-ladder' then 'course' else 'clan'
viewArgs.push leagueType
viewArgs.push leagueID
ladderURL += "/#{leagueType}/#{leagueID}"
ladderURL += '#my-matches'
Backbone.Mediator.publish 'router:navigate', route: ladderURL, viewClass: 'views/ladder/LadderView', viewArgs: viewArgs