2015-06-29 15:15:07 -04:00
|
|
|
app = require 'core/application'
|
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/courses/mock1/course-details'
|
|
|
|
|
|
|
|
module.exports = class CourseDetailsView extends RootView
|
|
|
|
id: 'course-details-view'
|
|
|
|
template: template
|
|
|
|
|
2015-06-30 19:53:33 -04:00
|
|
|
events:
|
2015-07-01 18:11:40 -04:00
|
|
|
'change .expand-progress-checkbox': 'onExpandedProgressCheckbox'
|
|
|
|
'change .select-session': 'onChangeSession'
|
2015-06-30 19:53:33 -04:00
|
|
|
'click .edit-class-name-btn': 'onClickEditClassName'
|
|
|
|
'click .edit-description-btn': 'onClickEditClassDescription'
|
|
|
|
|
2015-06-29 15:15:07 -04:00
|
|
|
constructor: (options, @courseID) ->
|
|
|
|
super options
|
|
|
|
@initData()
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
|
|
|
context.course = @course ? {}
|
2015-06-30 19:53:33 -04:00
|
|
|
context.instance = @instances?[@currentInstanceIndex] ? {}
|
|
|
|
context.instances = @instances ? []
|
2015-07-01 18:11:40 -04:00
|
|
|
context.maxLastStartedIndex = @maxLastStartedIndex ? 0
|
|
|
|
context.userLevelStateMap = @userLevelStateMap ? {}
|
|
|
|
context.showExpandedProgress = @maxLastStartedIndex <= 30 or @showExpandedProgress
|
2015-06-29 15:15:07 -04:00
|
|
|
context
|
|
|
|
|
|
|
|
initData: ->
|
|
|
|
mockData = require 'views/courses/mock1/CoursesMockData'
|
|
|
|
@course = mockData.courses[@courseID]
|
2015-06-30 19:53:33 -04:00
|
|
|
@currentInstanceIndex = 0
|
|
|
|
@instances = mockData.instances
|
2015-07-01 18:36:33 -04:00
|
|
|
@updateLevelMaps()
|
2015-06-30 19:53:33 -04:00
|
|
|
|
2015-07-01 18:36:33 -04:00
|
|
|
updateLevelMaps: ->
|
2015-07-01 18:11:40 -04:00
|
|
|
@userLevelStateMap = {}
|
|
|
|
@maxLastStartedIndex = -1
|
|
|
|
for student in @instances?[@currentInstanceIndex].students
|
|
|
|
lastCompletedIndex = _.random(0, @course.levels.length)
|
|
|
|
lastStartedIndex = lastCompletedIndex + 1
|
|
|
|
@userLevelStateMap[student] =
|
|
|
|
lastCompletedIndex: lastCompletedIndex
|
|
|
|
lastStartedIndex: lastStartedIndex
|
|
|
|
@maxLastStartedIndex = lastStartedIndex if lastStartedIndex > @maxLastStartedIndex
|
|
|
|
|
2015-06-30 19:53:33 -04:00
|
|
|
onChangeSession: (e) ->
|
2015-07-01 18:36:33 -04:00
|
|
|
@showExpandedProgress = false
|
2015-06-30 19:53:33 -04:00
|
|
|
newSessionValue = $(e.target).val()
|
2015-07-01 18:36:33 -04:00
|
|
|
@currentInstanceIndex = index for val, index in @instances when val.name is newSessionValue
|
|
|
|
@updateLevelMaps()
|
2015-06-30 19:53:33 -04:00
|
|
|
@render?()
|
|
|
|
|
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-06-30 19:53:33 -04:00
|
|
|
onClickEditClassName: (e) ->
|
|
|
|
alert 'TODO: Popup for editing name for this course session'
|
|
|
|
|
|
|
|
onClickEditClassDescription: (e) ->
|
|
|
|
alert 'TODO: Popup for editing description for this course session'
|