Better username change validation messages

This commit is contained in:
Neil Lalonde 2013-02-08 16:08:33 -05:00
parent d1a04fa06a
commit d73baa23dd
2 changed files with 6 additions and 8 deletions

View File

@ -1,18 +1,18 @@
Discourse.PreferencesUsernameController = Ember.ObjectController.extend Discourse.Presence,
taken: false
invalid: false
saving: false
error: false
errorMessage: null
saveDisabled: (->
return true if @get('saving')
return true if @blank('newUsername')
return true if @get('taken')
return true if @get('invalid')
return true if @get('unchanged')
return true if @get('errorMessage')
false
).property('newUsername', 'taken', 'invalid', 'unchanged', 'saving')
).property('newUsername', 'taken', 'errorMessage', 'unchanged', 'saving')
unchanged: (->
@get('newUsername') == @get('content.username')
@ -20,12 +20,12 @@ Discourse.PreferencesUsernameController = Ember.ObjectController.extend Discours
checkTaken: (->
@set('taken', false)
@set('invalid', false)
@set('errorMessage', null)
return if @blank('newUsername')
return if @get('unchanged')
Discourse.User.checkUsername(@get('newUsername')).then (result) =>
if result.errors
@set('invalid', true)
@set('errorMessage', result.errors.join(' '))
else if result.available == false
@set('taken', true)
).observes('newUsername')

View File

@ -23,9 +23,7 @@
{{#if controller.taken}}
{{i18n user.change_username.taken}}
{{/if}}
{{#if controller.invalid}}
{{i18n user.change_username.invalid}}
{{/if}}
<span>{{ errorMessage }}</span>
</div>
</div>