2016-05-11 17:39:26 -04:00
|
|
|
ModalView = require 'views/core/ModalView'
|
|
|
|
template = require 'templates/courses/join-class-modal'
|
|
|
|
Classroom = require 'models/Classroom'
|
|
|
|
User = require 'models/User'
|
|
|
|
|
|
|
|
module.exports = class JoinClassModal extends ModalView
|
|
|
|
id: 'join-class-modal'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click .join-class-btn': 'onClickJoinClassButton'
|
|
|
|
|
2016-08-01 19:40:48 -04:00
|
|
|
initialize: ({ @classCode } = {}) ->
|
2016-05-11 17:39:26 -04:00
|
|
|
@classroom = new Classroom()
|
|
|
|
@teacher = new User()
|
|
|
|
jqxhr = @supermodel.trackRequest @classroom.fetchByCode(@classCode)
|
|
|
|
unless me.get('emailVerified')
|
|
|
|
@supermodel.trackRequest $.post("/db/user/#{me.id}/request-verify-email")
|
2016-06-14 20:15:48 -04:00
|
|
|
@listenTo @classroom, 'error', ->
|
|
|
|
@trigger('error')
|
2016-05-11 17:39:26 -04:00
|
|
|
@listenTo @classroom, 'sync', ->
|
|
|
|
@render
|
|
|
|
@listenTo @classroom, 'join:success', ->
|
|
|
|
@trigger('join:success', @classroom)
|
|
|
|
@listenTo @classroom, 'join:error', ->
|
|
|
|
@trigger('join:error', @classroom, jqxhr)
|
|
|
|
# @close()
|
|
|
|
|
|
|
|
onClickJoinClassButton: ->
|
|
|
|
@classroom.joinWithCode(@classCode)
|