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
div.wizard-name-line.form-group
label.control-label(for="name")
| Your Wizardly Name
| Your Wizardly Name:
input#wizard-settings-name(name="name", type="text", value="#{me.get('name')||''}")
#wizard-settings-view

View file

@ -21,6 +21,12 @@ module.exports = class WizardSettingsModal extends View
onNameChange: ->
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: ->
forms.clearFormAlerts(@$el)

View file

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