mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Remember checkbox state in TeacherClassView
This commit is contained in:
parent
b25782f2b6
commit
6fb4cbd9ac
2 changed files with 22 additions and 19 deletions
|
@ -182,7 +182,8 @@ mixin studentsTab
|
||||||
th.checkbox-col.select-all.small.text-center
|
th.checkbox-col.select-all.small.text-center
|
||||||
span(data-i18n="teacher.select_all")
|
span(data-i18n="teacher.select_all")
|
||||||
.checkbox-flat
|
.checkbox-flat
|
||||||
input(type='checkbox' id='checkbox-all-students')
|
- var allStudentsChecked = _.all(state.get('checkboxStates'))
|
||||||
|
input(type='checkbox', id='checkbox-all-students', checked=allStudentsChecked)
|
||||||
label.checkmark(for='checkbox-all-students')
|
label.checkmark(for='checkbox-all-students')
|
||||||
th
|
th
|
||||||
+sortButtons
|
+sortButtons
|
||||||
|
@ -201,7 +202,7 @@ mixin studentRow(student)
|
||||||
tr.student-row.alternating-background
|
tr.student-row.alternating-background
|
||||||
td.checkbox-col.student-checkbox
|
td.checkbox-col.student-checkbox
|
||||||
.checkbox-flat
|
.checkbox-flat
|
||||||
input(type='checkbox' id='checkbox-student-' + student.id, data-student-id=student.id)
|
input(type='checkbox' id='checkbox-student-' + student.id, data-student-id=student.id, checked=state.get('checkboxStates')[student.id])
|
||||||
label.checkmark(for='checkbox-student-' + student.id)
|
label.checkmark(for='checkbox-student-' + student.id)
|
||||||
td.student-info-col
|
td.student-info-col
|
||||||
.student-info
|
.student-info
|
||||||
|
|
|
@ -56,6 +56,7 @@ module.exports = class TeacherClassView extends RootView
|
||||||
assigningToNobody: false
|
assigningToNobody: false
|
||||||
assigningToUnenrolled: false
|
assigningToUnenrolled: false
|
||||||
selectedCourse: undefined
|
selectedCourse: undefined
|
||||||
|
checkboxStates: {}
|
||||||
classStats:
|
classStats:
|
||||||
averagePlaytime: ""
|
averagePlaytime: ""
|
||||||
totalPlaytime: ""
|
totalPlaytime: ""
|
||||||
|
@ -145,6 +146,10 @@ module.exports = class TeacherClassView extends RootView
|
||||||
classStats = @calculateClassStats()
|
classStats = @calculateClassStats()
|
||||||
@state.set classStats: classStats if classStats
|
@state.set classStats: classStats if classStats
|
||||||
@state.set students: @students
|
@state.set students: @students
|
||||||
|
checkboxStates = {}
|
||||||
|
for student in @students.models
|
||||||
|
checkboxStates[student.id] = @state.get('checkboxStates')[student.id] or false
|
||||||
|
@state.set { checkboxStates }
|
||||||
@listenTo @students, 'sort', ->
|
@listenTo @students, 'sort', ->
|
||||||
@state.set students: @students
|
@state.set students: @students
|
||||||
@listenTo @, 'course-select:change', ({ selectedCourse }) ->
|
@listenTo @, 'course-select:change', ({ selectedCourse }) ->
|
||||||
|
@ -291,8 +296,7 @@ module.exports = class TeacherClassView extends RootView
|
||||||
@trigger 'course-select:change', { selectedCourse: @courses.get($(e.currentTarget).val()) }
|
@trigger 'course-select:change', { selectedCourse: @courses.get($(e.currentTarget).val()) }
|
||||||
|
|
||||||
getSelectedStudentIDs: ->
|
getSelectedStudentIDs: ->
|
||||||
@$('.student-row .checkbox-flat input:checked').map (index, checkbox) ->
|
Object.keys(_.pick @state.get('checkboxStates'), (checked) -> checked)
|
||||||
$(checkbox).data('student-id')
|
|
||||||
|
|
||||||
ensureInstance: (courseID) ->
|
ensureInstance: (courseID) ->
|
||||||
|
|
||||||
|
@ -304,7 +308,7 @@ module.exports = class TeacherClassView extends RootView
|
||||||
window.tracker?.trackEvent $(e.currentTarget).data('event-action'), category: 'Teachers', classroomID: @classroom.id, userID: userID, ['Mixpanel']
|
window.tracker?.trackEvent $(e.currentTarget).data('event-action'), category: 'Teachers', classroomID: @classroom.id, userID: userID, ['Mixpanel']
|
||||||
|
|
||||||
onClickBulkEnroll: ->
|
onClickBulkEnroll: ->
|
||||||
userIDs = @getSelectedStudentIDs().toArray()
|
userIDs = @getSelectedStudentIDs()
|
||||||
selectedUsers = new Users(@students.get(userID) for userID in userIDs)
|
selectedUsers = new Users(@students.get(userID) for userID in userIDs)
|
||||||
@enrollStudents(selectedUsers)
|
@enrollStudents(selectedUsers)
|
||||||
window.tracker?.trackEvent 'Teachers Class Students Enroll Selected', category: 'Teachers', classroomID: @classroom.id, ['Mixpanel']
|
window.tracker?.trackEvent 'Teachers Class Students Enroll Selected', category: 'Teachers', classroomID: @classroom.id, ['Mixpanel']
|
||||||
|
@ -385,10 +389,9 @@ module.exports = class TeacherClassView extends RootView
|
||||||
onClickBulkAssign: ->
|
onClickBulkAssign: ->
|
||||||
courseID = @$('.bulk-course-select').val()
|
courseID = @$('.bulk-course-select').val()
|
||||||
selectedIDs = @getSelectedStudentIDs()
|
selectedIDs = @getSelectedStudentIDs()
|
||||||
members = selectedIDs.filter((index, userID) =>
|
members = selectedIDs.filter (userID) =>
|
||||||
user = @students.get(userID)
|
user = @students.get(userID)
|
||||||
user.isEnrolled()
|
user.isEnrolled()
|
||||||
).toArray()
|
|
||||||
assigningToUnenrolled = _.any selectedIDs, (userID) =>
|
assigningToUnenrolled = _.any selectedIDs, (userID) =>
|
||||||
not @students.get(userID).isEnrolled()
|
not @students.get(userID).isEnrolled()
|
||||||
assigningToNobody = selectedIDs.length is 0
|
assigningToNobody = selectedIDs.length is 0
|
||||||
|
@ -417,23 +420,22 @@ module.exports = class TeacherClassView extends RootView
|
||||||
|
|
||||||
onClickSelectAll: (e) ->
|
onClickSelectAll: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
checkboxes = @$('.student-checkbox input')
|
checkboxStates = _.clone @state.get('checkboxStates')
|
||||||
if _.all(checkboxes, 'checked')
|
if _.all(checkboxStates)
|
||||||
@$('.select-all input').prop('checked', false)
|
for studentID of checkboxStates
|
||||||
checkboxes.prop('checked', false)
|
checkboxStates[studentID] = false
|
||||||
else
|
else
|
||||||
@$('.select-all input').prop('checked', true)
|
for studentID of checkboxStates
|
||||||
checkboxes.prop('checked', true)
|
checkboxStates[studentID] = true
|
||||||
null
|
@state.set { checkboxStates }
|
||||||
|
|
||||||
onClickStudentCheckbox: (e) ->
|
onClickStudentCheckbox: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
# $(e.target).$()
|
|
||||||
checkbox = $(e.currentTarget).find('input')
|
checkbox = $(e.currentTarget).find('input')
|
||||||
checkbox.prop('checked', not checkbox.prop('checked'))
|
studentID = checkbox.data('student-id')
|
||||||
# checkboxes.prop('checked', false)
|
checkboxStates = _.clone @state.get('checkboxStates')
|
||||||
checkboxes = @$('.student-checkbox input')
|
checkboxStates[studentID] = not checkboxStates[studentID]
|
||||||
@$('.select-all input').prop('checked', _.all(checkboxes, 'checked'))
|
@state.set { checkboxStates }
|
||||||
|
|
||||||
calculateClassStats: ->
|
calculateClassStats: ->
|
||||||
return {} unless @classroom.sessions?.loaded and @students.loaded
|
return {} unless @classroom.sessions?.loaded and @students.loaded
|
||||||
|
|
Loading…
Reference in a new issue