mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Added an async name checker for the wizard settings modal.
This commit is contained in:
parent
b31527abef
commit
7c734d6bc9
3 changed files with 9 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue