2015-06-29 15:15:07 -04:00
|
|
|
app = require 'core/application'
|
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/courses/mock1/course-enroll'
|
|
|
|
|
|
|
|
module.exports = class CourseEnrollView extends RootView
|
2015-09-10 13:37:32 -04:00
|
|
|
id: 'course-enroll-mock-view'
|
2015-06-29 15:15:07 -04:00
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click .btn-buy': 'onClickBuy'
|
|
|
|
'change .course-select': 'onChangeCourse'
|
2015-08-04 18:32:56 -04:00
|
|
|
'change .input-quantity': 'onQuantityChange'
|
2015-06-29 15:15:07 -04:00
|
|
|
|
2015-08-04 18:32:56 -04:00
|
|
|
constructor: (options, @courseID=0) ->
|
2015-06-29 15:15:07 -04:00
|
|
|
super options
|
|
|
|
@initData()
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
|
|
|
context.courses = @courses ? {}
|
|
|
|
context.courseID = @courseID
|
|
|
|
context.price = @price ? 0
|
|
|
|
context.quantity = @quantity
|
|
|
|
context.selectedCourseTitle = @selectedCourseTitle
|
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@$el.find('.course-select').val(@selectedCourseTitle)
|
|
|
|
|
|
|
|
initData: ->
|
|
|
|
mockData = require 'views/courses/mock1/CoursesMockData'
|
|
|
|
@courses = mockData.courses
|
|
|
|
@selectedCourseTitle = @courses[@courseID]?.title
|
|
|
|
@quantity = 20
|
|
|
|
@updatePrice()
|
|
|
|
|
|
|
|
onClickBuy: (e) ->
|
|
|
|
if @selectedCourseTitle is 'All Courses'
|
|
|
|
app.router.navigate "/courses/mock1/0"
|
|
|
|
else
|
|
|
|
for course, i in @courses when course.title is @selectedCourseTitle
|
|
|
|
app.router.navigate "/courses/mock1/#{i}"
|
|
|
|
break
|
|
|
|
window.location.reload()
|
|
|
|
|
|
|
|
onChangeCourse: (e) ->
|
|
|
|
@selectedCourseTitle = $(e.target).val()
|
|
|
|
@updatePrice()
|
|
|
|
@render?()
|
|
|
|
|
|
|
|
onQuantityChange: (e) ->
|
2015-08-04 18:32:56 -04:00
|
|
|
@quantity = $(e.target).val() ? 20
|
2015-06-29 15:15:07 -04:00
|
|
|
@updatePrice()
|
2015-07-30 16:53:15 -04:00
|
|
|
@render?()
|
2015-06-29 15:15:07 -04:00
|
|
|
|
|
|
|
updatePrice: ->
|
|
|
|
if @selectedCourseTitle is 'All Courses'
|
2015-08-04 18:32:56 -04:00
|
|
|
@price = (@courses.length - 1) * @quantity * 2
|
2015-07-29 12:51:01 -04:00
|
|
|
else if @selectedCourseTitle is 'Introduction to Computer Science'
|
|
|
|
@price = 0
|
2015-06-29 15:15:07 -04:00
|
|
|
else
|
2015-08-04 18:32:56 -04:00
|
|
|
@price = @quantity * 4
|