From d98aa48f0d14603203ee5b1cb385d59a336d3130 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 10 Nov 2016 15:54:21 -0500 Subject: [PATCH] Remove some preferences views, add extra tests --- .../discourse/components/d-editor.js.es6 | 4 +++ .../controllers/preferences/username.js.es6 | 23 +++++++++-------- .../discourse/templates/preferences-about.hbs | 25 +++++++++++++++++++ .../username.hbs => preferences-username.hbs} | 8 +++--- .../discourse/templates/user/about.hbs | 24 ------------------ .../discourse/views/preferences-about.js.es6 | 11 -------- .../views/preferences-username.js.es6 | 21 ---------------- .../acceptance/preferences-test.js.es6 | 15 +++++++++++ 8 files changed, 61 insertions(+), 70 deletions(-) create mode 100644 app/assets/javascripts/discourse/templates/preferences-about.hbs rename app/assets/javascripts/discourse/templates/{user/username.hbs => preferences-username.hbs} (83%) delete mode 100644 app/assets/javascripts/discourse/templates/user/about.hbs delete mode 100644 app/assets/javascripts/discourse/views/preferences-about.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/preferences-username.js.es6 diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 11feda8e3f9..6e43dfde817 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -205,6 +205,10 @@ export default Ember.Component.extend({ _readyNow() { this.set('ready', true); + + if (this.get('autofocus')) { + this.$('textarea').focus(); + } }, init() { diff --git a/app/assets/javascripts/discourse/controllers/preferences/username.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/username.js.es6 index c1976a91fbc..a597df810a4 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/username.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/username.js.es6 @@ -39,18 +39,19 @@ export default Ember.Controller.extend({ }.property('saving'), actions: { - changeUsername: function() { - var self = this; - return bootbox.confirm(I18n.t("user.change_username.confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) { + changeUsername() { + if (this.get('saveDisabled')) { return; } + + return bootbox.confirm(I18n.t("user.change_username.confirm"), + I18n.t("no_value"), + I18n.t("yes_value"), result => { if (result) { - self.set('saving', true); - self.get('content').changeUsername(self.get('newUsername')).then(function() { - DiscourseURL.redirectTo("/users/" + self.get('newUsername').toLowerCase() + "/preferences"); - }, function() { - // error - self.set('error', true); - self.set('saving', false); - }); + this.set('saving', true); + this.get('content').changeUsername(this.get('newUsername')).then(() => { + DiscourseURL.redirectTo("/users/" + this.get('newUsername').toLowerCase() + "/preferences"); + }) + .catch(() => this.set('error', true)) + .finally(() => this.set('saving', false)); } }); } diff --git a/app/assets/javascripts/discourse/templates/preferences-about.hbs b/app/assets/javascripts/discourse/templates/preferences-about.hbs new file mode 100644 index 00000000000..6613c077327 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/preferences-about.hbs @@ -0,0 +1,25 @@ +
+
+ +
+
+

{{i18n 'user.change_about.title'}}

+
+
+ +
+ +
+ {{d-editor value=model.bio_raw class="raw-bio" autofocus="autofocus"}} +
+
+ +
+
+ {{#d-button action="changeAbout" class="btn btn-primary"}} + {{saveButtonText}} + {{/d-button}} +
+
+
+
diff --git a/app/assets/javascripts/discourse/templates/user/username.hbs b/app/assets/javascripts/discourse/templates/preferences-username.hbs similarity index 83% rename from app/assets/javascripts/discourse/templates/user/username.hbs rename to app/assets/javascripts/discourse/templates/preferences-username.hbs index afe66232923..ae27149d9d2 100644 --- a/app/assets/javascripts/discourse/templates/user/username.hbs +++ b/app/assets/javascripts/discourse/templates/preferences-username.hbs @@ -18,13 +18,15 @@
- {{text-field value=newUsername id="change_username" classNames="input-xxlarge" maxlength=maxLength}} + {{text-field value=newUsername id="change_username" classNames="input-xxlarge" maxlength=maxLength autofocus="autofocus" insert-newline="changeUsername"}}
-
+
+

{{#if taken}} {{i18n 'user.change_username.taken'}} {{/if}} - {{ errorMessage }} + {{errorMessage}} +

diff --git a/app/assets/javascripts/discourse/templates/user/about.hbs b/app/assets/javascripts/discourse/templates/user/about.hbs deleted file mode 100644 index 2d1e162db1e..00000000000 --- a/app/assets/javascripts/discourse/templates/user/about.hbs +++ /dev/null @@ -1,24 +0,0 @@ -
- -
-
-

{{i18n 'user.change_about.title'}}

-
-
- -
- -
- {{d-editor value=model.bio_raw}} -
-
- -
-
- {{#d-button action="changeAbout" class="btn btn-primary"}} - {{saveButtonText}} - {{/d-button}} -
-
- -
diff --git a/app/assets/javascripts/discourse/views/preferences-about.js.es6 b/app/assets/javascripts/discourse/views/preferences-about.js.es6 deleted file mode 100644 index 63d6600ebfe..00000000000 --- a/app/assets/javascripts/discourse/views/preferences-about.js.es6 +++ /dev/null @@ -1,11 +0,0 @@ -export default Ember.View.extend({ - templateName: 'user/about', - classNames: ['user-preferences'], - - _focusAbout: function() { - var self = this; - Ember.run.schedule('afterRender', function() { - self.$('textarea').focus(); - }); - }.on('didInsertElement') -}); diff --git a/app/assets/javascripts/discourse/views/preferences-username.js.es6 b/app/assets/javascripts/discourse/views/preferences-username.js.es6 deleted file mode 100644 index 14a36a5e9bb..00000000000 --- a/app/assets/javascripts/discourse/views/preferences-username.js.es6 +++ /dev/null @@ -1,21 +0,0 @@ -export default Ember.View.extend({ - templateName: 'user/username', - classNames: ['user-preferences'], - - _focusUsername: function() { - Em.run.schedule('afterRender', function() { - $('#change_username').focus(); - }); - }.on('didInsertElement'), - - keyDown: function(e) { - if (e.keyCode === 13) { - if (!this.get('controller').get('saveDisabled')) { - return this.get('controller').send('changeUsername'); - } else { - e.preventDefault(); - return false; - } - } - } -}); diff --git a/test/javascripts/acceptance/preferences-test.js.es6 b/test/javascripts/acceptance/preferences-test.js.es6 index 49ac4947139..feb69443341 100644 --- a/test/javascripts/acceptance/preferences-test.js.es6 +++ b/test/javascripts/acceptance/preferences-test.js.es6 @@ -18,3 +18,18 @@ test("update some fields", () => { ok(exists('.saved-user'), 'it displays the saved message'); }); }); + +test("about me", () => { + visit("/users/eviltrout/preferences/username"); + andThen(() => { + ok(exists("#change_username"), "it has the input element for the bio"); + }); +}); + +test("username", () => { + visit("/users/eviltrout/preferences/about-me"); + andThen(() => { + ok(exists(".raw-bio"), "it has the input element for the bio"); + }); +}); +