mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -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
|
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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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) ->
|
||||||
|
|
Loading…
Reference in a new issue