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

View File

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