2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2014-11-29 16:47:04 -05:00
|
|
|
template = require 'templates/core/recover-modal'
|
2014-11-28 20:49:41 -05:00
|
|
|
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...)
|
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
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:
|
2014-08-27 15:24:03 -04:00
|
|
|
'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) =>
|
2014-11-26 09:58:23 -05:00
|
|
|
@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)
|
2014-09-07 23:54:25 -04:00
|
|
|
@$el.find('.modal-body:visible').text($.i18n.t('recover.recovery_sent'))
|
2014-01-03 13:32:13 -05:00
|
|
|
@$el.find('.modal-footer').remove()
|