2014-11-28 20:49:41 -05:00
RootView = require ' views/core/RootView '
2014-11-29 15:46:04 -05:00
template = require ' templates/home-view '
2016-02-25 18:24:16 -05:00
CreateAccountModal = require ' views/core/CreateAccountModal '
2014-01-03 13:32:13 -05:00
2014-07-17 20:16:32 -04:00
module.exports = class HomeView extends RootView
2014-01-03 13:32:13 -05:00
id: ' home-view '
template: template
2014-03-21 20:42:13 -04:00
2014-06-19 16:42:25 -04:00
events:
2015-10-21 17:18:13 -04:00
' click # play-button ' : ' onClickPlayButton '
2016-02-03 13:10:43 -05:00
' click # close-teacher-note-link ' : ' onClickCloseTeacherNoteLink '
2014-01-03 13:32:13 -05:00
2016-01-26 19:28:29 -05:00
constructor: (options={}) ->
2014-10-21 19:49:25 -04:00
super ( )
2016-01-26 19:28:29 -05:00
@withTeacherNote = options . withTeacherNote
2015-02-27 19:07:41 -05:00
window . tracker ? . trackEvent ' Homepage Loaded ' , category: ' Homepage '
2015-11-13 13:17:05 -05:00
if @ getQueryVariable ' hour_of_code '
application . router . navigate " /hoc " , trigger: true
2015-12-04 14:04:45 -05:00
2015-12-15 15:06:44 -05:00
isHourOfCodeWeek = false # Temporary: default to /hoc flow during the main event week
2015-12-04 14:04:45 -05:00
if isHourOfCodeWeek and ( @ isNewPlayer ( ) or ( @ justPlaysCourses ( ) and me . isAnonymous ( ) ) )
# Go/return straight to playing single-player HoC course on Play click
@playURL = ' /hoc?go=true '
@alternatePlayURL = ' /play '
@alternatePlayText = ' home.play_campaign_version '
else if @ justPlaysCourses ( )
# Save players who might be in a classroom from getting into the campaign
2015-11-30 19:43:33 -05:00
@playURL = ' /courses '
@alternatePlayURL = ' /play '
@alternatePlayText = ' home.play_campaign_version '
else
@playURL = ' /play '
2014-10-21 19:49:25 -04:00
2015-10-21 17:18:13 -04:00
onClickPlayButton: (e) ->
2014-11-26 09:58:23 -05:00
@ playSound ' menu-button-click '
2015-11-30 19:43:33 -05:00
return if @ playURL isnt ' /play '
2014-09-25 18:32:33 -04:00
e . preventDefault ( )
e . stopImmediatePropagation ( )
2014-11-28 15:05:34 -05:00
window . tracker ? . trackEvent ' Click Play ' , category: ' Homepage '
2014-11-10 18:24:05 -05:00
window . open ' /play ' , ' _blank '
afterInsert: ->
super ( arguments . . . )
2016-02-25 18:24:16 -05:00
modal = new CreateAccountModal ( )
@ openModalView ( modal )
2014-11-27 12:44:08 -05:00
2015-11-30 19:43:33 -05:00
justPlaysCourses: ->
# This heuristic could be better, but currently we don't add to me.get('courseInstances') for single-player anonymous intro courses, so they have to beat a level without choosing a hero.
return me . get ( ' stats ' ) ? . gamesCompleted and not me . get ( ' heroConfig ' )
2015-12-04 14:04:45 -05:00
isNewPlayer: ->
not me . get ( ' stats ' ) ? . gamesCompleted and not me . get ( ' heroConfig ' )
2016-02-03 13:10:43 -05:00
onClickCloseTeacherNoteLink: ->
@ $ ( ' .style-flat ' ) . addClass ( ' hide ' )