Username change: check length in js, we don't need the server to do it

This commit is contained in:
Neil Lalonde 2013-03-18 15:28:12 -04:00
parent b6224b014c
commit c24f6d3d51

View File

@ -26,18 +26,22 @@ Discourse.PreferencesUsernameController = Discourse.ObjectController.extend({
}).property('newUsername', 'content.username'), }).property('newUsername', 'content.username'),
checkTaken: (function() { checkTaken: (function() {
var _this = this; if( this.get('newUsername') && this.get('newUsername').length < 3 ) {
this.set('taken', false); this.set('errorMessage', Em.String.i18n('user.name.too_short'));
this.set('errorMessage', null); } else {
if (this.blank('newUsername')) return; var _this = this;
if (this.get('unchanged')) return; this.set('taken', false);
Discourse.User.checkUsername(this.get('newUsername')).then(function(result) { this.set('errorMessage', null);
if (result.errors) { if (this.blank('newUsername')) return;
return _this.set('errorMessage', result.errors.join(' ')); if (this.get('unchanged')) return;
} else if (result.available === false) { Discourse.User.checkUsername(this.get('newUsername')).then(function(result) {
return _this.set('taken', true); if (result.errors) {
} return _this.set('errorMessage', result.errors.join(' '));
}); } else if (result.available === false) {
return _this.set('taken', true);
}
});
}
}).observes('newUsername'), }).observes('newUsername'),
saveButtonText: (function() { saveButtonText: (function() {