From 3368e23fe4f74e28700c749ad056fc7151eb1608 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 15 Jul 2014 12:36:44 -0400 Subject: [PATCH] ES6: Preferences views --- .../discourse/mixins/scroll_top.js | 1 - .../discourse/views/preferences-about.js.es6 | 11 ++++++++ .../discourse/views/preferences-email.js.es6 | 9 +++++++ ...me_view.js => preferences-username.js.es6} | 21 +++++---------- ...preferences_view.js => preferences.js.es6} | 2 +- .../discourse/views/user-invited.js.es6 | 3 +++ .../javascripts/discourse/views/user.js.es6 | 11 ++++++++ .../views/user/preferences_about_view.js | 18 ------------- .../views/user/preferences_email_view.js | 17 ------------ .../discourse/views/user/user_invited_view.js | 13 --------- .../discourse/views/user/user_view.js | 27 ------------------- 11 files changed, 41 insertions(+), 92 deletions(-) create mode 100644 app/assets/javascripts/discourse/views/preferences-about.js.es6 create mode 100644 app/assets/javascripts/discourse/views/preferences-email.js.es6 rename app/assets/javascripts/discourse/views/{user/preferences_username_view.js => preferences-username.js.es6} (50%) rename app/assets/javascripts/discourse/views/{user/preferences_view.js => preferences.js.es6} (59%) create mode 100644 app/assets/javascripts/discourse/views/user-invited.js.es6 create mode 100644 app/assets/javascripts/discourse/views/user.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user/preferences_about_view.js delete mode 100644 app/assets/javascripts/discourse/views/user/preferences_email_view.js delete mode 100644 app/assets/javascripts/discourse/views/user/user_invited_view.js delete mode 100644 app/assets/javascripts/discourse/views/user/user_view.js diff --git a/app/assets/javascripts/discourse/mixins/scroll_top.js b/app/assets/javascripts/discourse/mixins/scroll_top.js index da92d81bf04..9ec896ccc2a 100644 --- a/app/assets/javascripts/discourse/mixins/scroll_top.js +++ b/app/assets/javascripts/discourse/mixins/scroll_top.js @@ -7,7 +7,6 @@ @module Discourse **/ Discourse.ScrollTop = Em.Mixin.create({ - _scrollTop: function() { Em.run.schedule('afterRender', function() { $(document).scrollTop(0); diff --git a/app/assets/javascripts/discourse/views/preferences-about.js.es6 b/app/assets/javascripts/discourse/views/preferences-about.js.es6 new file mode 100644 index 00000000000..63d6600ebfe --- /dev/null +++ b/app/assets/javascripts/discourse/views/preferences-about.js.es6 @@ -0,0 +1,11 @@ +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-email.js.es6 b/app/assets/javascripts/discourse/views/preferences-email.js.es6 new file mode 100644 index 00000000000..766a8c90abe --- /dev/null +++ b/app/assets/javascripts/discourse/views/preferences-email.js.es6 @@ -0,0 +1,9 @@ +export default Em.View.extend({ + templateName: 'user/email', + classNames: ['user-preferences'], + _focusField: function() { + Em.run.schedule('afterRender', function() { + $('#change_email').focus(); + }); + }.on('didInsertElement') +}); diff --git a/app/assets/javascripts/discourse/views/user/preferences_username_view.js b/app/assets/javascripts/discourse/views/preferences-username.js.es6 similarity index 50% rename from app/assets/javascripts/discourse/views/user/preferences_username_view.js rename to app/assets/javascripts/discourse/views/preferences-username.js.es6 index c553fa8c09f..e28961e6e5d 100644 --- a/app/assets/javascripts/discourse/views/user/preferences_username_view.js +++ b/app/assets/javascripts/discourse/views/preferences-username.js.es6 @@ -1,18 +1,12 @@ -/** - This view handles rendering of a user's username preferences - - @class PreferencesUsernameView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.PreferencesUsernameView = Discourse.View.extend({ +export default Ember.View.extend({ templateName: 'user/username', classNames: ['user-preferences'], - didInsertElement: function() { - return $('#change_username').focus(); - }, + _focusUsername: function() { + Em.run.schedule('afterRender', function() { + $('#change_username').focus(); + }); + }.on('didInsertElement'), keyDown: function(e) { if (e.keyCode === 13) { @@ -24,7 +18,4 @@ Discourse.PreferencesUsernameView = Discourse.View.extend({ } } } - }); - - diff --git a/app/assets/javascripts/discourse/views/user/preferences_view.js b/app/assets/javascripts/discourse/views/preferences.js.es6 similarity index 59% rename from app/assets/javascripts/discourse/views/user/preferences_view.js rename to app/assets/javascripts/discourse/views/preferences.js.es6 index de34a7cbf75..597f88fd778 100644 --- a/app/assets/javascripts/discourse/views/user/preferences_view.js +++ b/app/assets/javascripts/discourse/views/preferences.js.es6 @@ -1,4 +1,4 @@ -Discourse.PreferencesView = Discourse.View.extend({ +export default Ember.View.extend({ templateName: 'user/preferences', classNames: ['user-preferences'] }); diff --git a/app/assets/javascripts/discourse/views/user-invited.js.es6 b/app/assets/javascripts/discourse/views/user-invited.js.es6 new file mode 100644 index 00000000000..dc4f8dc4017 --- /dev/null +++ b/app/assets/javascripts/discourse/views/user-invited.js.es6 @@ -0,0 +1,3 @@ +export default Ember.View.extend({ + templateName: 'user/invited' +}); diff --git a/app/assets/javascripts/discourse/views/user.js.es6 b/app/assets/javascripts/discourse/views/user.js.es6 new file mode 100644 index 00000000000..25413955b9a --- /dev/null +++ b/app/assets/javascripts/discourse/views/user.js.es6 @@ -0,0 +1,11 @@ +export default Ember.View.extend(Discourse.ScrollTop, { + templateName: 'user/user', + userBinding: 'controller.content', + + updateTitle: function() { + var username = this.get('user.username'); + if (username) { + Discourse.set('title', "" + (I18n.t("user.profile")) + " - " + username); + } + }.observes('user.loaded', 'user.username') +}); diff --git a/app/assets/javascripts/discourse/views/user/preferences_about_view.js b/app/assets/javascripts/discourse/views/user/preferences_about_view.js deleted file mode 100644 index 258e64bb6ae..00000000000 --- a/app/assets/javascripts/discourse/views/user/preferences_about_view.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - This view handles rendering of a user's bio editor - - @class PreferencesAboutView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.PreferencesAboutView = Discourse.View.extend({ - templateName: 'user/about', - classNames: ['user-preferences'], - - didInsertElement: function() { - this.$('textarea').focus(); - } -}); - - diff --git a/app/assets/javascripts/discourse/views/user/preferences_email_view.js b/app/assets/javascripts/discourse/views/user/preferences_email_view.js deleted file mode 100644 index 63031a769ea..00000000000 --- a/app/assets/javascripts/discourse/views/user/preferences_email_view.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - This view handles rendering of a user's email preferences - - @class PreferencesEmailView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.PreferencesEmailView = Discourse.View.extend({ - templateName: 'user/email', - classNames: ['user-preferences'], - didInsertElement: function() { - return $('#change_email').focus(); - } -}); - - diff --git a/app/assets/javascripts/discourse/views/user/user_invited_view.js b/app/assets/javascripts/discourse/views/user/user_invited_view.js deleted file mode 100644 index 37849ef0fc6..00000000000 --- a/app/assets/javascripts/discourse/views/user/user_invited_view.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - This view handles rendering of a user's invited list - - @class UserInvitedView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.UserInvitedView = Discourse.View.extend({ - templateName: 'user/invited' -}); - - diff --git a/app/assets/javascripts/discourse/views/user/user_view.js b/app/assets/javascripts/discourse/views/user/user_view.js deleted file mode 100644 index 86c8a5ff585..00000000000 --- a/app/assets/javascripts/discourse/views/user/user_view.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - This view handles rendering of a user including the navigational menu - - @class UserView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.UserView = Discourse.View.extend({ - templateName: 'user/user', - userBinding: 'controller.content', - - updateTitle: function() { - var username; - username = this.get('user.username'); - if (username) { - return Discourse.set('title', "" + (I18n.t("user.profile")) + " - " + username); - } - }.observes('user.loaded', 'user.username'), - - didInsertElement: function() { - window.scrollTo(0, 0); - } - -}); - -