2016-05-11 17:39:26 -04:00
|
|
|
ModalView = require 'views/core/ModalView'
|
|
|
|
State = require 'models/State'
|
|
|
|
template = require 'templates/teachers/edit-student-modal'
|
|
|
|
auth = require 'core/auth'
|
|
|
|
|
|
|
|
module.exports = class EditStudentModal extends ModalView
|
|
|
|
id: 'edit-student-modal'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click .send-recovery-email-btn:not(.disabled)': 'onClickSendRecoveryEmail'
|
|
|
|
'click .change-password-btn:not(.disabled)': 'onClickChangePassword'
|
|
|
|
'input .new-password-input': 'onChangeNewPasswordInput'
|
|
|
|
|
2016-05-20 17:52:04 -04:00
|
|
|
initialize: ({ @user, @classroom }) ->
|
2016-05-11 17:39:26 -04:00
|
|
|
@supermodel.trackRequest @user.fetch()
|
|
|
|
@utils = require 'core/utils'
|
|
|
|
@state = new State({
|
|
|
|
emailSent: false
|
|
|
|
passwordChanged: false
|
|
|
|
newPassword: ""
|
2016-05-20 17:52:04 -04:00
|
|
|
errorMessage: ""
|
2016-05-11 17:39:26 -04:00
|
|
|
})
|
|
|
|
@listenTo @state, 'change', @render
|
2016-05-20 17:52:04 -04:00
|
|
|
@listenTo @classroom, 'save-password:success', ->
|
|
|
|
@state.set { passwordChanged: true, errorMessage: "" }
|
|
|
|
@listenTo @classroom, 'save-password:error', (error) ->
|
|
|
|
@state.set({ errorMessage: error.message })
|
|
|
|
# TODO: Show an error. (password too short)
|
2016-05-11 17:39:26 -04:00
|
|
|
|
|
|
|
onClickSendRecoveryEmail: ->
|
|
|
|
email = @user.get('email')
|
|
|
|
auth.sendRecoveryEmail(email).then =>
|
|
|
|
@state.set { emailSent: true }
|
|
|
|
|
|
|
|
onClickChangePassword: ->
|
2016-05-20 17:52:04 -04:00
|
|
|
@classroom.setStudentPassword(@user, @state.get('newPassword'))
|
2016-05-11 17:39:26 -04:00
|
|
|
|
|
|
|
onChangeNewPasswordInput: (e) ->
|
2016-05-23 13:26:34 -04:00
|
|
|
@state.set {
|
|
|
|
newPassword: $(e.currentTarget).val()
|
|
|
|
emailSent: false
|
|
|
|
passwordChanged: false
|
|
|
|
}, { silent: true }
|
|
|
|
@renderSelectors('.change-password-btn')
|