codecombat/app/views/courses/TeacherClassesView.coffee

149 lines
6.1 KiB
CoffeeScript
Raw Normal View History

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
helper: helper
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'
'click .create-teacher-btn': 'onClickCreateTeacherButton'
'click .update-teacher-btn': 'onClickUpdateTeacherButton'
'click .view-class-btn': 'onClickViewClassButton'
2016-03-30 16:57:19 -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)
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-03-30 16:57:19 -04:00
@courseInstances = new CourseInstances()
@courseInstances.fetchByOwner(me.id)
@supermodel.trackCollection(@courseInstances)
Refactor and update teacher-dashboard This updates TeacherClassView and ActivateLicensesModal to use the new state-based rendering system, making it much snappier and less clunky feeling, and improving data consistency. Features also included in this: - Hover details for progress dots in TeacherClassView - ActivateLicensesModal has an "All Students" option and better handling when you switch classrooms in the dropdown - Unenrolled/Unassigned students are shown separately in Course Progress and can be enrolled/assigned from there. Add Back to Classes button on demo-request submitted view Delete temporary patch file Show unenrolled students separately in Course Progress (incomplete) Migrate TeacherClassView to use orchestrator-style events, add unassigned students section, replace bootstrap tabs with state-based tabs Convert missed instance variables to be in @state Fix merge errors (in progress) Convert a bunch of stuff to use state and events (removing student needs fixing) Fix up modal interactions, some bugs Switch state to be a Model, sync up course dropdowns Convert student sorting to use state model Add hover tooltips to TeacherClassView Students tab Don't keep tooltip open when you mouse into it Add dateFirstCompleted and Course Progress tooltips Course Overview progress tooltips Refactor ActivateLicensesModal Refactors: Uses state object for view state Passes back the updated users in 'redeem-users' event instead of modifying given collection Features: Add 'All Students' dropdown option Don't forget checked students if you change classroom from dropdown, but only enroll the ones visible when you click "Enroll (n) Students" Separate enrolled students; improve style Rearrange error text Disable enroll-students button when none are selected Remove console.logs Move style-flat variables to another file This prevents .style-flat from being copied in multiple times to the resulting CSS. Show Unarchive button when on the page for an archived class Move text to en.coffee Only sort students on first classroom sync Fix merge error Handle sessions missing completion date in view logic instead of migration script Listen to classroom sync more than once in case it gets unarchived
2016-04-19 16:44:48 -04:00
@progressDotTemplate = require 'templates/teachers/hovers/progress-dot-whole-course'
2016-03-30 16:57:19 -04:00
# Level Sessions loaded after onLoaded to prevent race condition in calculateDots
2016-03-30 16:57:19 -04:00
afterRender: ->
super()
$('.progress-dot').each (i, el) ->
dot = $(el)
dot.tooltip({
html: true
container: dot
})
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-03-30 16:57:19 -04:00
onClickEditClassroom: (e) ->
classroomID = $(e.target).data('classroom-id')
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) ->
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', ->
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()
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) ->
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-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: =>
window.tracker?.trackEvent 'Teachers Classes Archived Class', category: 'Teachers', ['Mixpanel']
2016-03-30 16:57:19 -04:00
@render()
}
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: =>
window.tracker?.trackEvent 'Teachers Classes Unarchived Class', category: 'Teachers', ['Mixpanel']
2016-03-30 16:57:19 -04:00
@render()
}
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