2015-06-29 15:15:07 -04:00
|
|
|
app = require 'core/application'
|
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/courses/mock1/courses'
|
|
|
|
|
|
|
|
module.exports = class CoursesView extends RootView
|
|
|
|
id: 'courses-view'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click .btn-enter': 'onClickEnter'
|
|
|
|
'click .btn-have-code': 'onClickHaveCode'
|
|
|
|
'click .btn-more-info': 'onClickMoreInfo'
|
2015-07-29 17:47:10 -04:00
|
|
|
'click .btn-redeem-code': 'onClickRedeemCode'
|
2015-06-29 15:15:07 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@initData()
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
|
|
|
context.courses = @courses ? []
|
|
|
|
context
|
|
|
|
|
|
|
|
initData: ->
|
|
|
|
mockData = require 'views/courses/mock1/CoursesMockData'
|
|
|
|
@courses = mockData.courses
|
|
|
|
for course, i in @courses
|
2015-07-29 17:47:10 -04:00
|
|
|
if _.random(0, 2) > 0
|
2015-06-29 15:15:07 -04:00
|
|
|
course.unlocked = true
|
|
|
|
else
|
|
|
|
break
|
|
|
|
|
|
|
|
onClickEnter: (e) ->
|
|
|
|
courseID = $(e.target).data('course-id')
|
|
|
|
app.router.navigate "/courses/mock1/#{courseID}"
|
|
|
|
window.location.reload()
|
|
|
|
|
|
|
|
onClickHaveCode: (e) ->
|
|
|
|
courseID = $(e.target).data('course-id')
|
2015-07-29 17:47:10 -04:00
|
|
|
courseTitle = $(e.target).data('course-title')
|
|
|
|
$('#redeemCodeModal').find('.modal-title').text(courseTitle)
|
|
|
|
$('#redeemCodeModal').find('.redeem-code-btn').data('course-id', courseID)
|
2015-06-29 15:15:07 -04:00
|
|
|
|
|
|
|
onClickMoreInfo: (e) ->
|
|
|
|
courseID = $(e.target).data('course-id')
|
|
|
|
app.router.navigate "/courses/mock1/#{courseID}/info"
|
|
|
|
window.location.reload()
|
2015-07-29 17:47:10 -04:00
|
|
|
|
|
|
|
onClickRedeemCode: (e) ->
|
|
|
|
$('#redeemCodeModal').modal('hide')
|
|
|
|
courseID = $(e.target).data('course-id')
|
|
|
|
|
|
|
|
# TODO: would just navigate instead of rendering unlock here in practice
|
|
|
|
@courses[courseID].unlocked = true
|
|
|
|
@render?()
|