Added an async name checker for the wizard settings modal.

This commit is contained in:
Scott Erickson 2014-02-27 14:42:11 -08:00
parent b31527abef
commit 7c734d6bc9
3 changed files with 9 additions and 6 deletions

View file

@ -6,7 +6,7 @@ block modal-header-content
block modal-body-content block modal-body-content
div.wizard-name-line.form-group div.wizard-name-line.form-group
label.control-label(for="name") label.control-label(for="name")
| Your Wizardly Name | Your Wizardly Name:
input#wizard-settings-name(name="name", type="text", value="#{me.get('name')||''}") input#wizard-settings-name(name="name", type="text", value="#{me.get('name')||''}")
#wizard-settings-view #wizard-settings-view

View file

@ -21,7 +21,13 @@ module.exports = class WizardSettingsModal extends View
onNameChange: -> onNameChange: ->
me.set('name', $('#wizard-settings-name').val()) me.set('name', $('#wizard-settings-name').val())
@checkNameExists()
checkNameExists: ->
forms.clearFormAlerts(@$el)
success = (id) => forms.applyErrorsToForm(@$el, {property:'name', message:'is already taken'}) if id and id isnt me.id
$.ajax("/db/user/#{me.get('name')}/nameToID", {success: success})
onWizardSettingsDone: -> onWizardSettingsDone: ->
forms.clearFormAlerts(@$el) forms.clearFormAlerts(@$el)
res = me.validate() res = me.validate()

View file

@ -131,11 +131,8 @@ UserHandler = class UserHandler extends Handler
res.end() res.end()
nameToID: (req, res, name) -> nameToID: (req, res, name) ->
# t0 = new Date().getTime() User.findOne({nameLower:name.toLowerCase()}).exec (err, otherUser) ->
# console.log 'query starts', {nameLower:name.toLowerCase()} res.send(if otherUser then otherUser._id else JSON.stringify(''))
User.findOne({nameLower:name.toLowerCase()}, {_id:1}).exec (err, otherUser) ->
# console.log 'query ends', new Date().getTime() - t0
res.send(otherUser._id.toString()) if otherUser
res.end() res.end()
post: (req, res) -> post: (req, res) ->