codecombat/app/views/modal/RecoverModal.coffee

43 lines
1.3 KiB
CoffeeScript
Raw Normal View History

ModalView = require 'views/core/ModalView'
2014-01-03 13:32:13 -05:00
template = require 'templates/modal/recover'
forms = require 'core/forms'
{genericFailure} = require 'core/errors'
2014-01-03 13:32:13 -05:00
filterKeyboardEvents = (allowedEvents, func) ->
return (splat...) ->
e = splat[0]
return unless e.keyCode in allowedEvents or not e.keyCode
return func(splat...)
module.exports = class RecoverModal extends ModalView
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:
'errors:server-error': 'onServerError'
2014-01-03 13:32:13 -05:00
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) =>
@playSound 'menu-button-click'
2014-01-03 13:32:13 -05:00
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($.i18n.t('recover.recovery_sent'))
2014-01-03 13:32:13 -05:00
@$el.find('.modal-footer').remove()