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'
2014-06-30 22:16:26 -04:00
forms = require 'lib/forms'
2014-01-03 13:32:13 -05:00
{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
2014-06-30 22:16:26 -04:00
id: 'recover-modal'
2014-01-03 13:32:13 -05:00
template: template
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
events:
2014-06-30 22:16:26 -04:00
'click #recover-button': 'recoverAccount'
'keydown input': 'recoverAccount'
2014-01-03 13:32:13 -05:00
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
2014-06-30 22:16:26 -04:00
res = $.post '/auth/reset', {email: email}, @successfullyRecovered
2014-01-03 13:32:13 -05:00
res.fail(genericFailure)
@enableModalInProgress(@$el)
2014-06-30 22:16:26 -04:00
2014-01-03 13:32:13 -05:00
successfullyRecovered: =>
@disableModalInProgress(@$el)
@$el.find('.modal-body:visible').text('Recovery email sent.')
@$el.find('.modal-footer').remove()