2015-06-29 15:15:07 -04:00
|
|
|
app = require 'core/application'
|
2015-08-23 16:48:52 -04:00
|
|
|
utils = require 'core/utils'
|
2015-06-29 15:15:07 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/courses/mock1/course-details'
|
2015-07-09 20:53:32 -04:00
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
|
|
Campaign = require 'models/Campaign'
|
2015-06-29 15:15:07 -04:00
|
|
|
|
|
|
|
module.exports = class CourseDetailsView extends RootView
|
2015-09-10 13:37:32 -04:00
|
|
|
id: 'course-details-mock-view'
|
2015-06-29 15:15:07 -04:00
|
|
|
template: template
|
|
|
|
|
2015-06-30 19:53:33 -04:00
|
|
|
events:
|
2015-07-01 18:11:40 -04:00
|
|
|
'change .expand-progress-checkbox': 'onExpandedProgressCheckbox'
|
2015-07-10 13:37:41 -04:00
|
|
|
'change .student-mode-checkbox': 'onChangeStudent'
|
2015-07-10 20:10:46 -04:00
|
|
|
'click .btn-play-level': 'onClickPlayLevel'
|
2015-08-05 12:35:18 -04:00
|
|
|
'click .btn-save-settings': 'onClickSaveSettings'
|
2015-07-10 20:10:46 -04:00
|
|
|
'click .member-header': 'onClickMemberHeader'
|
|
|
|
'click .progress-header': 'onClickProgressHeader'
|
2015-07-30 19:04:13 -04:00
|
|
|
'mouseenter .progress-level-cell': 'onMouseEnterPoint'
|
|
|
|
'mouseleave .progress-level-cell': 'onMouseLeavePoint'
|
2015-06-30 19:53:33 -04:00
|
|
|
|
2015-08-04 17:52:23 -04:00
|
|
|
constructor: (options, @courseID=0, @instanceID=0) ->
|
2015-06-29 15:15:07 -04:00
|
|
|
super options
|
2015-08-23 16:48:52 -04:00
|
|
|
@studentMode = utils.getQueryVariable('student', false) or options.studentMode
|
2015-06-29 15:15:07 -04:00
|
|
|
@initData()
|
|
|
|
|
2015-07-09 20:53:32 -04:00
|
|
|
destroy: ->
|
|
|
|
@stopListening?()
|
|
|
|
|
2015-06-29 15:15:07 -04:00
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
2015-07-09 20:53:32 -04:00
|
|
|
context.conceptsProgression = @conceptsProgression ? []
|
2015-06-29 15:15:07 -04:00
|
|
|
context.course = @course ? {}
|
2015-07-09 20:53:32 -04:00
|
|
|
context.courseConcepts = @courseConcepts ? []
|
2015-06-30 19:53:33 -04:00
|
|
|
context.instance = @instances?[@currentInstanceIndex] ? {}
|
|
|
|
context.instances = @instances ? []
|
2015-07-09 20:53:32 -04:00
|
|
|
context.levelConceptsMap = @levelConceptsMap ? {}
|
2015-07-01 18:11:40 -04:00
|
|
|
context.maxLastStartedIndex = @maxLastStartedIndex ? 0
|
2015-07-10 20:10:46 -04:00
|
|
|
context.memberSort = @memberSort
|
2015-07-09 20:53:32 -04:00
|
|
|
context.userConceptsMap = @userConceptsMap ? {}
|
2015-07-01 18:11:40 -04:00
|
|
|
context.userLevelStateMap = @userLevelStateMap ? {}
|
2015-08-21 20:00:44 -04:00
|
|
|
context.showExpandedProgress = @showExpandedProgress
|
|
|
|
context.stats = @stats
|
2015-08-23 16:48:52 -04:00
|
|
|
context.studentMode = @studentMode ? false
|
2015-07-30 18:30:36 -04:00
|
|
|
|
|
|
|
conceptsCompleted = {}
|
|
|
|
for user of context.userConceptsMap
|
|
|
|
for concept of context.userConceptsMap[user]
|
|
|
|
conceptsCompleted[concept] ?= 0
|
|
|
|
conceptsCompleted[concept]++
|
|
|
|
context.conceptsCompleted = conceptsCompleted
|
2015-06-29 15:15:07 -04:00
|
|
|
context
|
|
|
|
|
|
|
|
initData: ->
|
2015-07-10 20:10:46 -04:00
|
|
|
@memberSort = 'nameAsc'
|
2015-06-29 15:15:07 -04:00
|
|
|
mockData = require 'views/courses/mock1/CoursesMockData'
|
|
|
|
@course = mockData.courses[@courseID]
|
2015-08-04 17:52:23 -04:00
|
|
|
@currentInstanceIndex = @instanceID
|
2015-06-30 19:53:33 -04:00
|
|
|
@instances = mockData.instances
|
2015-07-01 18:36:33 -04:00
|
|
|
@updateLevelMaps()
|
2015-06-30 19:53:33 -04:00
|
|
|
|
2015-07-09 20:53:32 -04:00
|
|
|
@campaigns = new CocoCollection([], { url: "/db/campaign", model: Campaign, comparator:'_id' })
|
|
|
|
@listenTo @campaigns, 'sync', @onCampaignSync
|
|
|
|
@supermodel.loadModel @campaigns, 'clan', cache: false
|
|
|
|
|
2015-07-01 18:36:33 -04:00
|
|
|
updateLevelMaps: ->
|
2015-07-09 20:53:32 -04:00
|
|
|
@levelMap = {}
|
|
|
|
@levelMap[level] = true for level in @course.levels
|
2015-07-01 18:11:40 -04:00
|
|
|
@userLevelStateMap = {}
|
2015-08-21 20:00:44 -04:00
|
|
|
@stats =
|
|
|
|
averageLevelPlaytime: _.random(30, 240)
|
|
|
|
averageLevelsCompleted: _.random(1, @course.levels.length)
|
|
|
|
students: {}
|
2015-07-01 18:11:40 -04:00
|
|
|
@maxLastStartedIndex = -1
|
|
|
|
for student in @instances?[@currentInstanceIndex].students
|
2015-07-09 20:53:32 -04:00
|
|
|
@userLevelStateMap[student] = {}
|
2015-07-29 12:51:01 -04:00
|
|
|
lastCompletedIndex = _.random(-1, @course.levels.length)
|
2015-07-09 20:53:32 -04:00
|
|
|
for i in [0..lastCompletedIndex]
|
|
|
|
@userLevelStateMap[student][@course.levels[i]] = 'complete'
|
2015-07-01 18:11:40 -04:00
|
|
|
lastStartedIndex = lastCompletedIndex + 1
|
2015-07-09 20:53:32 -04:00
|
|
|
@userLevelStateMap[student][@course.levels[lastStartedIndex]] = 'started'
|
2015-07-01 18:11:40 -04:00
|
|
|
@maxLastStartedIndex = lastStartedIndex if lastStartedIndex > @maxLastStartedIndex
|
2015-08-21 20:00:44 -04:00
|
|
|
|
|
|
|
@stats[student] ?= {}
|
|
|
|
@stats[student].levelsCompleted = 0
|
|
|
|
@stats[student].levelsCompleted++ for level in @course.levels when @userLevelStateMap[student][level] is 'complete'
|
|
|
|
@stats[student].secondsPlayed = Math.round(Math.random() * 1000 * (@stats[student].levelsCompleted + 1))
|
|
|
|
@stats[student].secondsLastPlayed = Math.round(Math.random() * 100000)
|
2015-07-10 20:10:46 -04:00
|
|
|
@sortMembers()
|
2015-08-21 20:00:44 -04:00
|
|
|
@stats.totalPlayTime = @instances?[@currentInstanceIndex].students?.length * @stats.averageLevelPlaytime ? 0
|
|
|
|
@stats.totalLevelsCompleted = @instances?[@currentInstanceIndex].students?.length * @stats.averageLevelsCompleted ? 0
|
|
|
|
@stats.totalPlayTime = @instances?[@currentInstanceIndex].students?.length * @stats.averageLevelPlaytime ? 0
|
|
|
|
@stats.lastLevelCompleted = @course.levels[0] ? @course.levels[@course.levels.length - 1]
|
2015-07-10 20:10:46 -04:00
|
|
|
|
|
|
|
sortMembers: ->
|
|
|
|
# Progress sort precedence: most completed concepts, most started concepts, most levels, name sort
|
|
|
|
instance = @instances?[@currentInstanceIndex] ? {}
|
|
|
|
return if _.isEmpty(instance)
|
|
|
|
switch @memberSort
|
|
|
|
when "nameDesc"
|
|
|
|
instance.students.sort (a, b) -> b.localeCompare(a)
|
|
|
|
when "progressAsc"
|
|
|
|
instance.students.sort (a, b) =>
|
|
|
|
for level in @course.levels
|
|
|
|
if @userLevelStateMap[a][level] isnt 'complete' and @userLevelStateMap[b][level] is 'complete'
|
|
|
|
return -1
|
|
|
|
else if @userLevelStateMap[a][level] is 'complete' and @userLevelStateMap[b][level] isnt 'complete'
|
|
|
|
return 1
|
|
|
|
0
|
|
|
|
when "progressDesc"
|
|
|
|
instance.students.sort (a, b) =>
|
|
|
|
for level in @course.levels
|
|
|
|
if @userLevelStateMap[a][level] isnt 'complete' and @userLevelStateMap[b][level] is 'complete'
|
|
|
|
return 1
|
|
|
|
else if @userLevelStateMap[a][level] is 'complete' and @userLevelStateMap[b][level] isnt 'complete'
|
|
|
|
return -1
|
|
|
|
0
|
|
|
|
else
|
|
|
|
instance.students.sort (a, b) -> a.localeCompare(b)
|
2015-07-01 18:11:40 -04:00
|
|
|
|
2015-07-09 20:53:32 -04:00
|
|
|
onCampaignSync: ->
|
|
|
|
return unless @campaigns.loaded
|
|
|
|
@conceptsProgression = []
|
|
|
|
@courseConcepts = []
|
|
|
|
@levelConceptsMap = {}
|
|
|
|
@levelNameSlugMap = {}
|
|
|
|
@userConceptsMap = {}
|
2015-07-29 12:51:01 -04:00
|
|
|
# Update course levels if course has a specific campaign
|
|
|
|
for campaign in @campaigns.models when campaign.get('slug') is @course.campaign
|
|
|
|
@course.levels = []
|
|
|
|
for levelID, level of campaign.get('levels')
|
|
|
|
if campaign.get('slug') is @course.campaign
|
|
|
|
@course.levels.push level.name
|
|
|
|
@updateLevelMaps()
|
|
|
|
|
2015-07-09 20:53:32 -04:00
|
|
|
for campaign in @campaigns.models
|
|
|
|
continue if campaign.get('slug') is 'auditions'
|
|
|
|
for levelID, level of campaign.get('levels')
|
|
|
|
@levelNameSlugMap[level.name] = level.slug
|
|
|
|
if level.concepts?
|
|
|
|
for concept in level.concepts
|
|
|
|
@conceptsProgression.push concept unless concept in @conceptsProgression
|
|
|
|
continue unless @levelMap[level.name]
|
|
|
|
@courseConcepts.push concept unless concept in @courseConcepts
|
|
|
|
@levelConceptsMap[level.name] ?= {}
|
|
|
|
@levelConceptsMap[level.name][concept] = true
|
|
|
|
for student in @instances?[@currentInstanceIndex].students
|
|
|
|
@userConceptsMap[student] ?= {}
|
|
|
|
if @userLevelStateMap[student][level.name] is 'complete'
|
|
|
|
@userConceptsMap[student][concept] = 'complete'
|
|
|
|
else if @userLevelStateMap[student][level.name] is 'started'
|
|
|
|
@userConceptsMap[student][concept] ?= 'started'
|
|
|
|
@courseConcepts.sort (a, b) => if @conceptsProgression.indexOf(a) < @conceptsProgression.indexOf(b) then -1 else 1
|
|
|
|
@render?()
|
|
|
|
|
2015-07-10 13:37:41 -04:00
|
|
|
onChangeStudent: (e) ->
|
2015-08-23 16:48:52 -04:00
|
|
|
@studentMode = $('.student-mode-checkbox').prop('checked')
|
2015-07-10 13:37:41 -04:00
|
|
|
@render?()
|
2015-08-23 16:48:52 -04:00
|
|
|
$('.student-mode-checkbox').attr('checked', @studentMode)
|
2015-07-09 20:53:32 -04:00
|
|
|
|
2015-07-01 18:11:40 -04:00
|
|
|
onExpandedProgressCheckbox: (e) ->
|
|
|
|
@showExpandedProgress = $('.expand-progress-checkbox').prop('checked')
|
|
|
|
# TODO: why does render reset the checkbox to be unchecked?
|
|
|
|
@render?()
|
|
|
|
$('.expand-progress-checkbox').attr('checked', @showExpandedProgress)
|
|
|
|
|
2015-07-10 20:10:46 -04:00
|
|
|
onClickMemberHeader: (e) ->
|
|
|
|
@memberSort = if @memberSort is 'nameAsc' then 'nameDesc' else 'nameAsc'
|
|
|
|
@sortMembers()
|
|
|
|
@render?()
|
|
|
|
|
|
|
|
onClickProgressHeader: (e) ->
|
|
|
|
@memberSort = if @memberSort is 'progressAsc' then 'progressDesc' else 'progressAsc'
|
|
|
|
@sortMembers()
|
|
|
|
@render?()
|
|
|
|
|
2015-07-09 20:53:32 -04:00
|
|
|
onClickPlayLevel: (e) ->
|
|
|
|
levelName = $(e.target).data('level')
|
|
|
|
levelSlug = @levelNameSlugMap[levelName]
|
|
|
|
Backbone.Mediator.publish 'router:navigate', {
|
|
|
|
route: "/play/level/#{levelSlug}"
|
|
|
|
viewClass: 'views/play/level/PlayLevelView'
|
|
|
|
viewArgs: [{}, levelSlug]
|
|
|
|
}
|
2015-07-29 18:38:57 -04:00
|
|
|
|
2015-08-05 12:35:18 -04:00
|
|
|
onClickSaveSettings: (e) ->
|
2015-07-29 18:38:57 -04:00
|
|
|
if name = $('.edit-name-input').val()
|
|
|
|
@instances[@currentInstanceIndex].name = name
|
2015-08-05 12:35:18 -04:00
|
|
|
description = $('.edit-description-input').val()
|
|
|
|
@instances[@currentInstanceIndex].description = description
|
|
|
|
$('#editSettingsModal').modal('hide')
|
2015-07-29 18:38:57 -04:00
|
|
|
@render?()
|
2015-07-30 19:04:13 -04:00
|
|
|
|
|
|
|
onMouseEnterPoint: (e) ->
|
|
|
|
$('.level-popup-container').hide()
|
|
|
|
container = $(e.target).find('.level-popup-container').show()
|
|
|
|
margin = 20
|
|
|
|
offset = $(e.target).offset()
|
2015-08-21 20:00:44 -04:00
|
|
|
scrollTop = $('#page-container').scrollTop()
|
2015-07-30 19:04:13 -04:00
|
|
|
height = container.outerHeight()
|
|
|
|
container.css('left', offset.left + e.offsetX)
|
|
|
|
container.css('top', offset.top + scrollTop - height - margin)
|
|
|
|
|
|
|
|
onMouseLeavePoint: (e) ->
|
|
|
|
$(e.target).find('.level-popup-container').hide()
|