diff --git a/app/templates/modal/wizard_settings.jade b/app/templates/modal/wizard_settings.jade index f5b3ef81a..a301884ec 100644 --- a/app/templates/modal/wizard_settings.jade +++ b/app/templates/modal/wizard_settings.jade @@ -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 diff --git a/app/views/modal/wizard_settings_modal.coffee b/app/views/modal/wizard_settings_modal.coffee index 794509521..1651ca43b 100644 --- a/app/views/modal/wizard_settings_modal.coffee +++ b/app/views/modal/wizard_settings_modal.coffee @@ -21,7 +21,13 @@ 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) res = me.validate() diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 8d246c13e..465aae27f 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -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) ->