2016-03-30 16:57:19 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/courses/teacher-classes-view'
|
|
|
|
Classroom = require 'models/Classroom'
|
|
|
|
Classrooms = require 'collections/Classrooms'
|
|
|
|
Courses = require 'collections/Courses'
|
|
|
|
Campaign = require 'models/Campaign'
|
|
|
|
Campaigns = require 'collections/Campaigns'
|
|
|
|
LevelSessions = require 'collections/LevelSessions'
|
|
|
|
CourseInstance = require 'models/CourseInstance'
|
|
|
|
CourseInstances = require 'collections/CourseInstances'
|
|
|
|
ClassroomSettingsModal = require 'views/courses/ClassroomSettingsModal'
|
|
|
|
InviteToClassroomModal = require 'views/courses/InviteToClassroomModal'
|
|
|
|
User = require 'models/User'
|
|
|
|
utils = require 'core/utils'
|
|
|
|
helper = require 'lib/coursesHelper'
|
|
|
|
|
|
|
|
module.exports = class TeacherClassesView extends RootView
|
|
|
|
id: 'teacher-classes-view'
|
|
|
|
template: template
|
2016-07-17 04:12:58 -04:00
|
|
|
helper: helper
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
events:
|
|
|
|
'click .edit-classroom': 'onClickEditClassroom'
|
|
|
|
'click .archive-classroom': 'onClickArchiveClassroom'
|
|
|
|
'click .unarchive-classroom': 'onClickUnarchiveClassroom'
|
|
|
|
'click .add-students-btn': 'onClickAddStudentsButton'
|
|
|
|
'click .create-classroom-btn': 'onClickCreateClassroomButton'
|
2016-06-08 09:24:59 -04:00
|
|
|
'click .create-teacher-btn': 'onClickCreateTeacherButton'
|
|
|
|
'click .update-teacher-btn': 'onClickUpdateTeacherButton'
|
|
|
|
'click .view-class-btn': 'onClickViewClassButton'
|
2016-03-30 16:57:19 -04:00
|
|
|
|
2016-05-27 12:40:46 -04:00
|
|
|
getTitle: -> return $.i18n.t('teacher.my_classes')
|
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
initialize: (options) ->
|
|
|
|
super(options)
|
|
|
|
@classrooms = new Classrooms()
|
|
|
|
@classrooms.fetchMine()
|
|
|
|
@supermodel.trackCollection(@classrooms)
|
|
|
|
@listenTo @classrooms, 'sync', ->
|
|
|
|
for classroom in @classrooms.models
|
|
|
|
classroom.sessions = new LevelSessions()
|
|
|
|
jqxhrs = classroom.sessions.fetchForAllClassroomMembers(classroom)
|
|
|
|
if jqxhrs.length > 0
|
|
|
|
@supermodel.trackCollection(classroom.sessions)
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Loaded', category: 'Teachers', ['Mixpanel']
|
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
@courses = new Courses()
|
|
|
|
@courses.fetch()
|
|
|
|
@supermodel.trackCollection(@courses)
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
@courseInstances = new CourseInstances()
|
|
|
|
@courseInstances.fetchByOwner(me.id)
|
|
|
|
@supermodel.trackCollection(@courseInstances)
|
2016-04-19 16:44:48 -04:00
|
|
|
@progressDotTemplate = require 'templates/teachers/hovers/progress-dot-whole-course'
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
# Level Sessions loaded after onLoaded to prevent race condition in calculateDots
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
$('.progress-dot').each (i, el) ->
|
|
|
|
dot = $(el)
|
|
|
|
dot.tooltip({
|
|
|
|
html: true
|
|
|
|
container: dot
|
|
|
|
})
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
onLoaded: ->
|
2016-04-13 12:54:24 -04:00
|
|
|
helper.calculateDots(@classrooms, @courses, @courseInstances)
|
2016-03-30 16:57:19 -04:00
|
|
|
super()
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
onClickEditClassroom: (e) ->
|
|
|
|
classroomID = $(e.target).data('classroom-id')
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent $(e.target).data('event-action'), category: 'Teachers', classroomID: classroomID, ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
classroom = @classrooms.get(classroomID)
|
|
|
|
modal = new ClassroomSettingsModal({ classroom: classroom })
|
|
|
|
@openModalView(modal)
|
|
|
|
@listenToOnce modal, 'hide', @render
|
|
|
|
|
|
|
|
onClickCreateClassroomButton: (e) ->
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Create New Class Started', category: 'Teachers', ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
classroom = new Classroom({ ownerID: me.id })
|
|
|
|
modal = new ClassroomSettingsModal({ classroom: classroom })
|
|
|
|
@openModalView(modal)
|
|
|
|
@listenToOnce modal.classroom, 'sync', ->
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Create New Class Finished', category: 'Teachers', ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
@classrooms.add(modal.classroom)
|
|
|
|
@addFreeCourseInstances()
|
|
|
|
@render()
|
2016-06-08 09:24:59 -04:00
|
|
|
|
|
|
|
onClickCreateTeacherButton: (e) ->
|
|
|
|
window.tracker?.trackEvent $(e.target).data('event-action'), category: 'Teachers', ['Mixpanel']
|
|
|
|
application.router.navigate("/teachers/signup", { trigger: true })
|
|
|
|
|
|
|
|
onClickUpdateTeacherButton: (e) ->
|
|
|
|
window.tracker?.trackEvent $(e.target).data('event-action'), category: 'Teachers', ['Mixpanel']
|
|
|
|
application.router.navigate("/teachers/update-account", { trigger: true })
|
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
onClickAddStudentsButton: (e) ->
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Add Students Started', category: 'Teachers', ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
|
|
classroom = @classrooms.get(classroomID)
|
|
|
|
modal = new InviteToClassroomModal({ classroom: classroom })
|
|
|
|
@openModalView(modal)
|
|
|
|
@listenToOnce modal, 'hide', @render
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
onClickArchiveClassroom: (e) ->
|
|
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
|
|
classroom = @classrooms.get(classroomID)
|
|
|
|
classroom.set('archived', true)
|
|
|
|
classroom.save {}, {
|
|
|
|
success: =>
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Archived Class', category: 'Teachers', ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
@render()
|
|
|
|
}
|
2016-06-08 09:24:59 -04:00
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
onClickUnarchiveClassroom: (e) ->
|
|
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
|
|
classroom = @classrooms.get(classroomID)
|
|
|
|
classroom.set('archived', false)
|
|
|
|
classroom.save {}, {
|
|
|
|
success: =>
|
2016-06-08 09:24:59 -04:00
|
|
|
window.tracker?.trackEvent 'Teachers Classes Unarchived Class', category: 'Teachers', ['Mixpanel']
|
2016-03-30 16:57:19 -04:00
|
|
|
@render()
|
|
|
|
}
|
2016-06-08 09:24:59 -04:00
|
|
|
|
|
|
|
onClickViewClassButton: (e) ->
|
|
|
|
classroomID = $(e.target).data('classroom-id')
|
|
|
|
window.tracker?.trackEvent $(e.target).data('event-action'), category: 'Teachers', classroomID: classroomID, ['Mixpanel']
|
|
|
|
application.router.navigate("/teachers/classes/#{classroomID}", { trigger: true })
|
|
|
|
|
2016-03-30 16:57:19 -04:00
|
|
|
addFreeCourseInstances: ->
|
|
|
|
# so that when students join the classroom, they can automatically get free courses
|
|
|
|
# non-free courses are generated when the teacher first adds a student to them
|
|
|
|
for classroom in @classrooms.models
|
|
|
|
for course in @courses.models
|
|
|
|
continue if not course.get('free')
|
|
|
|
courseInstance = @courseInstances.findWhere({classroomID: classroom.id, courseID: course.id})
|
|
|
|
if not courseInstance
|
|
|
|
courseInstance = new CourseInstance({
|
|
|
|
classroomID: classroom.id
|
|
|
|
courseID: course.id
|
|
|
|
})
|
|
|
|
# TODO: figure out a better way to get around triggering validation errors for properties
|
|
|
|
# that the server will end up filling in, like an empty members array, ownerID
|
|
|
|
courseInstance.save(null, {validate: false})
|
|
|
|
@courseInstances.add(courseInstance)
|
|
|
|
@listenToOnce courseInstance, 'sync', @addFreeCourseInstances
|
|
|
|
return
|