codecombat/app/views/courses/ClassroomSettingsModal.coffee
phoenixeliot e2d08fa7cf Stuff
Partially fix ActivateLicensesModal.spec

[IN PROGRESS] Don't display deleted users

Move userID to classroom.deletedMembers on user delete (not retroactive)

Fix PDF links for course guides, remove old PDFs from repo

Remove deprecated SalesView

Remove underline for not-yet-linked student names

Only show class select when there's more than one

Ignore case when sorting student names

Use student.broadName instead of name for display and sorting

Fix initial load not showing progress after joining a course (hacky)

Fix text entry for enrollment number input

Fix enrollment statistics

Fix enrollment stats completely (and add back in per-class unenrolled count)

Add deletedMembers to classroom schema

More fixes to enrollment stats (don't count nonmember prepaids)

Don't use 0 as implicit false for openSpots

Update suggested number of credit to buy automatically

Fix classroom edit form ignoring cleared values

Add alert text when more users selected than enrollments available

Alert user when trying to assign course to unenrolled students

Alert user when assigning course to nobody

Add some tests for TeacherClassView bulk assign alerts

Fix TeacherClassView tests failing without demos

Use model/collection.fakeRequests :D

Remove unused comment

Fix handling of improperly sorted deleted users on clientside

Add test for moving deleted users to deletedMembers

Add script for moving all deleted classroom members to classroom.deletedMembers

Completely rewrite tallying up enrollment statistics

Fix some tests to not be dependent on logged-in user

Address PR comments

Fix default number of enrollments to buy

Fix i18n for not enough enrollments

Use custom error message for classroom name length
2016-04-19 12:32:20 -07:00

55 lines
1.9 KiB
CoffeeScript

Classroom = require 'models/Classroom'
ModalView = require 'views/core/ModalView'
template = require 'templates/courses/classroom-settings-modal'
forms = require 'core/forms'
errors = require 'core/errors'
module.exports = class ClassroomSettingsModal extends ModalView
id: 'classroom-settings-modal'
template: template
events:
'click #save-settings-btn': 'onSubmitForm'
'submit form': 'onSubmitForm'
initialize: (options={}) ->
@classroom = options.classroom or new Classroom()
if @classroom.isNew()
application.tracker?.trackEvent 'Create new class', category: 'Courses'
else
application.tracker?.trackEvent 'Classroom started edit settings', category: 'Courses', classroomID: @classroom.id
afterRender: ->
super()
forms.updateSelects(@$('form'))
onSubmitForm: (e) ->
@classroom.notyErrors = false
e.preventDefault()
form = @$('form')
forms.clearFormAlerts(form)
attrs = forms.formToObject(form, ignoreEmptyString: false)
if attrs.language
attrs.aceConfig = { language: attrs.language }
delete attrs.language
else
forms.setErrorToProperty(form, 'language', $.i18n.t('common.required_field'))
return
@classroom.set(attrs)
schemaErrors = @classroom.getValidationErrors()
if schemaErrors
for error in schemaErrors
if error.schemaPath is "/properties/name/minLength"
error.message = 'Please enter a class name.'
forms.applyErrorsToForm(form, schemaErrors)
return
button = @$('#save-settings-btn')
@oldButtonText = button.text()
button.text($.i18n.t('common.saving')).attr('disabled', true)
@classroom.save()
@listenToOnce @classroom, 'error', (model, jqxhr) ->
@stopListening @classroom, 'sync', @hide
button.text(@oldButtonText).attr('disabled', false)
errors.showNotyNetworkError(jqxhr)
@listenToOnce @classroom, 'sync', @hide