codecombat/app/views/modal/recover_modal.coffee

42 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
View = require 'views/kinds/ModalView'
template = require 'templates/modal/recover'
forms = require('lib/forms')
{genericFailure} = require 'lib/errors'
filterKeyboardEvents = (allowedEvents, func) ->
return (splat...) ->
e = splat[0]
return unless e.keyCode in allowedEvents or not e.keyCode
return func(splat...)
module.exports = class RecoverModalView extends View
id: "recover-modal"
template: template
2014-01-10 16:31:26 -05:00
2014-01-03 13:32:13 -05:00
events:
"click #recover-button": "recoverAccount"
"keydown input": "recoverAccount"
subscriptions:
'server-error': 'onServerError'
onServerError: (e) -> # TODO: work error handling into a separate forms system
@disableModalInProgress(@$el)
constructor: (options) ->
@recoverAccount = filterKeyboardEvents([13], @recoverAccount) # TODO: part of forms
super options
recoverAccount: (e) =>
forms.clearFormAlerts(@$el)
email = (forms.formToObject @$el).email
return unless email
res = $.post '/auth/reset', {email:email}, @successfullyRecovered
res.fail(genericFailure)
@enableModalInProgress(@$el)
successfullyRecovered: =>
@disableModalInProgress(@$el)
@$el.find('.modal-body:visible').text('Recovery email sent.')
@$el.find('.modal-footer').remove()