mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-25 00:28:31 -05:00
8223122a6b
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
122 lines
4.7 KiB
CoffeeScript
122 lines
4.7 KiB
CoffeeScript
ModalView = require 'views/core/ModalView'
|
|
State = require 'models/State'
|
|
template = require 'templates/courses/activate-licenses-modal'
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
Prepaids = require 'collections/Prepaids'
|
|
Classroom = require 'models/Classroom'
|
|
Classrooms = require 'collections/Classrooms'
|
|
User = require 'models/User'
|
|
Users = require 'collections/Users'
|
|
|
|
module.exports = class ActivateLicensesModal extends ModalView
|
|
id: 'activate-licenses-modal'
|
|
template: template
|
|
|
|
events:
|
|
'change input[type="checkbox"][name="user"]': 'updateSelectedStudents'
|
|
'change select.classroom-select': 'replaceStudentList'
|
|
'submit form': 'onSubmitForm'
|
|
|
|
getInitialState: (options) ->
|
|
selectedUserModels = _.filter(options.selectedUsers.models, (user) -> not user.isEnrolled())
|
|
{
|
|
selectedUsers: new Users(selectedUserModels)
|
|
visibleSelectedUsers: new Users(selectedUserModels)
|
|
error: null
|
|
}
|
|
|
|
initialize: (options) ->
|
|
@state = new State(@getInitialState(options))
|
|
@classroom = options.classroom
|
|
@users = options.users.clone()
|
|
@users.comparator = (user) -> user.broadName().toLowerCase()
|
|
@prepaids = new Prepaids()
|
|
@prepaids.comparator = '_id'
|
|
@prepaids.fetchByCreator(me.id)
|
|
@supermodel.trackCollection(@prepaids)
|
|
@classrooms = new Classrooms()
|
|
@classrooms.fetchMine({
|
|
data: {archived: false}
|
|
success: =>
|
|
@classrooms.each (classroom) =>
|
|
classroom.users = new Users()
|
|
jqxhrs = classroom.users.fetchForClassroom(classroom, { removeDeleted: true })
|
|
@supermodel.trackRequests(jqxhrs)
|
|
})
|
|
@supermodel.trackCollection(@classrooms)
|
|
|
|
@listenTo @state, 'change', @render
|
|
@listenTo @state.get('selectedUsers'), 'change add remove reset', ->
|
|
@state.set { visibleSelectedUsers: new Users(@state.get('selectedUsers').filter (u) => @users.get(u)) }
|
|
@render()
|
|
@listenTo @users, 'change add remove reset', ->
|
|
@state.set { visibleSelectedUsers: new Users(@state.get('selectedUsers').filter (u) => @users.get(u)) }
|
|
@render()
|
|
@listenTo @prepaids, 'sync add remove', ->
|
|
@state.set {
|
|
unusedEnrollments: @prepaids.totalMaxRedeemers() - @prepaids.totalRedeemers()
|
|
}
|
|
|
|
afterRender: ->
|
|
super()
|
|
# @updateSelectedStudents() # TODO: refactor to event/state style
|
|
|
|
updateSelectedStudents: (e) ->
|
|
userID = $(e.currentTarget).data('user-id')
|
|
user = @users.get(userID)
|
|
if @state.get('selectedUsers').contains(user)
|
|
@state.get('selectedUsers').remove(user)
|
|
else
|
|
@state.get('selectedUsers').add(user)
|
|
# @render() # TODO: Have @state automatically listen to children's change events?
|
|
|
|
replaceStudentList: (e) ->
|
|
selectedClassroomID = $(e.currentTarget).val()
|
|
@classroom = @classrooms.get(selectedClassroomID)
|
|
if selectedClassroomID is 'all-students'
|
|
@classroom = new Classroom({ _id: 'all-students', name: 'All Students' }) # TODO: This is a horrible hack so the select shows the right option!
|
|
users = _.uniq _.flatten @classrooms.map (classroom) -> classroom.users.models
|
|
@users.reset(users)
|
|
@users.sort()
|
|
else
|
|
@users.reset(@classrooms.get(selectedClassroomID).users.models)
|
|
@render()
|
|
null
|
|
|
|
onSubmitForm: (e) ->
|
|
e.preventDefault()
|
|
@state.set error: null
|
|
usersToRedeem = @state.get('visibleSelectedUsers')
|
|
@redeemUsers(usersToRedeem)
|
|
|
|
redeemUsers: (usersToRedeem) ->
|
|
if not usersToRedeem.size()
|
|
@finishRedeemUsers()
|
|
@hide()
|
|
return
|
|
|
|
user = usersToRedeem.first()
|
|
prepaid = @prepaids.find((prepaid) -> prepaid.get('properties')?.endDate? and prepaid.openSpots() > 0)
|
|
prepaid = @prepaids.find((prepaid) -> prepaid.openSpots() > 0) unless prepaid
|
|
$.ajax({
|
|
method: 'POST'
|
|
url: _.result(prepaid, 'url') + '/redeemers'
|
|
data: { userID: user.id }
|
|
context: @
|
|
success: (prepaid) ->
|
|
user.set('coursePrepaidID', prepaid._id)
|
|
usersToRedeem.remove(user)
|
|
# pct = 100 * (usersToRedeem.originalSize - usersToRedeem.size() / usersToRedeem.originalSize)
|
|
# @$('#progress-area .progress-bar').css('width', "#{pct.toFixed(1)}%")
|
|
application.tracker?.trackEvent 'Enroll modal finished enroll student', category: 'Courses', userID: user.id
|
|
@redeemUsers(usersToRedeem)
|
|
error: (jqxhr, textStatus, errorThrown) ->
|
|
if jqxhr.status is 402
|
|
message = arguments[2]
|
|
else
|
|
message = "#{jqxhr.status}: #{jqxhr.responseText}"
|
|
@state.set { error: message } # TODO: Test this! ("should" never happen. Only on server responding with an error.)
|
|
})
|
|
|
|
finishRedeemUsers: ->
|
|
@trigger 'redeem-users', @state.get('selectedUsers')
|