Fix join class modal (temporary hack)

This commit is contained in:
phoenixeliot 2016-06-14 17:15:48 -07:00
parent 9239d2a81b
commit e841334c86
3 changed files with 19 additions and 3 deletions

View file

@ -69,8 +69,8 @@ module.exports = class CocoRouter extends Backbone.Router
'contribute/diplomat': go('contribute/DiplomatView')
'contribute/scribe': go('contribute/ScribeView')
'courses': go('courses/CoursesView', { studentsOnly: true })
'Courses': go('courses/CoursesView', { studentsOnly: true })
'courses': go('courses/CoursesView')
'Courses': go('courses/CoursesView')
'courses/students': redirect('/courses')
'courses/teachers': redirect('/teachers/classes')
'courses/purchase': redirect('/teachers/licenses')

View file

@ -40,7 +40,7 @@ module.exports = class CoursesView extends RootView
@courseInstances = new CocoCollection([], { url: "/db/user/#{me.id}/course_instances", model: CourseInstance})
@courseInstances.comparator = (ci) -> return ci.get('classroomID') + ci.get('courseID')
@listenToOnce @courseInstances, 'sync', @onCourseInstancesLoaded
@supermodel.loadCollection(@courseInstances)
@supermodel.loadCollection(@courseInstances, { cache: false })
@classrooms = new CocoCollection([], { url: "/db/classroom", model: Classroom })
@supermodel.loadCollection(@classrooms, { data: {memberID: me.id}, cache: false })
@ownedClassrooms = new Classrooms()
@ -59,6 +59,11 @@ module.exports = class CoursesView extends RootView
@listenTo @hero, 'all', ->
@render()
window.tracker?.trackEvent 'Students Loaded', category: 'Students', ['Mixpanel']
afterInsert: ->
super()
unless me.isStudent() or (@classCodeQueryVar and not me.isTeacher())
@onClassLoadError()
onCourseInstancesLoaded: ->
map = {}
@ -135,12 +140,21 @@ module.exports = class CoursesView extends RootView
else
modal = new JoinClassModal({ @classCode })
@openModalView modal
@listenTo modal, 'error', @onClassLoadError
@listenTo modal, 'join:success', @onJoinClassroomSuccess
@listenTo modal, 'join:error', @onJoinClassroomError
@listenToOnce modal, 'hidden', ->
unless me.isStudent()
@onClassLoadError()
@listenTo modal, 'hidden', ->
@state = null
@renderSelectors '#join-class-form'
# Super hacky way to patch users being able to join class while hiding /courses from others
onClassLoadError: ->
_.defer ->
application.router.routeDirectly('courses/RestrictedToStudentsView')
onJoinClassroomError: (classroom, jqxhr, options) ->
@state = null
if jqxhr.status is 422

View file

@ -16,6 +16,8 @@ module.exports = class JoinClassModal extends ModalView
jqxhr = @supermodel.trackRequest @classroom.fetchByCode(@classCode)
unless me.get('emailVerified')
@supermodel.trackRequest $.post("/db/user/#{me.id}/request-verify-email")
@listenTo @classroom, 'error', ->
@trigger('error')
@listenTo @classroom, 'sync', ->
@render
@listenTo @classroom, 'join:success', ->