From eeee5f4c08c8482449eba7ec5c6a2b864232cc3c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 26 Oct 2016 13:02:58 -0400 Subject: [PATCH] Use `{{outlets}}` instead of `{{render}}` in the application template --- .../discourse/helpers/user-status.js.es6 | 5 ++++- .../inject-discourse-objects.js.es6 | 4 +++- .../discourse/routes/application.js.es6 | 21 ++++++++++++------- .../discourse/templates/application.hbs | 8 +++---- .../discourse/views/hide-modal.js.es6 | 10 ++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/helpers/user-status.js.es6 b/app/assets/javascripts/discourse/helpers/user-status.js.es6 index cffd9e7acc9..9240273d109 100644 --- a/app/assets/javascripts/discourse/helpers/user-status.js.es6 +++ b/app/assets/javascripts/discourse/helpers/user-status.js.es6 @@ -6,7 +6,10 @@ export default htmlHelper((user, args) => { if (!user) { return; } const name = escapeExpression(user.get('name')); - const currentUser = args.hash.currentUser; + let currentUser = args.currentUser; + if (!currentUser && args.hash) { + currentUser = args.hash.currentUser; + } if (currentUser && user.get('admin') && currentUser.get('staff')) { return iconHTML('shield', { label: I18n.t('user.admin', { user: name }) }); diff --git a/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 b/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 index 04729de959f..f38e4b92b85 100644 --- a/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 +++ b/app/assets/javascripts/discourse/pre-initializers/inject-discourse-objects.js.es6 @@ -63,7 +63,9 @@ export default { app.register('screen-track:main', screenTrack, { instantiate: false }); inject(app, 'screenTrack', 'component', 'route'); - inject(app, 'currentUser', 'component', 'route', 'controller'); + if (currentUser) { + inject(app, 'currentUser', 'component', 'route', 'controller'); + } app.register('location:discourse-location', DiscourseLocation); diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index df074f01d3c..d506852e361 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -20,14 +20,7 @@ function unlessReadOnly(method, message) { const ApplicationRoute = Discourse.Route.extend(OpenComposer, { siteTitle: setting('title'), - _handleLogout() { - if (this.currentUser) { - this.currentUser.destroySession().then(() => logout(this.siteSettings, this.keyValueStore)); - } - }, - actions: { - toggleAnonymous() { ajax("/users/toggle-anon", {method: 'POST'}).then(() => { window.location.reload(); @@ -179,6 +172,14 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, { }); }, + renderTemplate() { + this.render('application'); + this.render('user-card', { into: 'application', outlet: 'user-card' }); + this.render('modal', { into: 'application', outlet: 'modal' }); + this.render('topic-entrance', { into: 'application', outlet: 'topic-entrance' }); + this.render('composer', { into: 'application', outlet: 'composer' }); + }, + handleShowLogin() { if (this.siteSettings.enable_sso) { const returnPath = encodeURIComponent(window.location.pathname); @@ -198,7 +199,6 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, { }, _autoLogin(modal, modalClass, notAuto) { - const methods = findAll(this.siteSettings, this.container.lookup('capabilities:main'), this.site.isMobileDevice); @@ -212,6 +212,11 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, { } }, + _handleLogout() { + if (this.currentUser) { + this.currentUser.destroySession().then(() => logout(this.siteSettings, this.keyValueStore)); + } + }, }); RSVP.EventTarget.mixin(ApplicationRoute); diff --git a/app/assets/javascripts/discourse/templates/application.hbs b/app/assets/javascripts/discourse/templates/application.hbs index bc8c9c5e341..7619a3394b0 100644 --- a/app/assets/javascripts/discourse/templates/application.hbs +++ b/app/assets/javascripts/discourse/templates/application.hbs @@ -15,7 +15,7 @@ {{create-topics-notice}} {{outlet}} - {{render "user-card"}} + {{outlet "user-card"}} {{plugin-outlet "above-footer"}} @@ -24,6 +24,6 @@ {{/if}} {{plugin-outlet "below-footer"}} -{{render "modal"}} -{{render "topic-entrance"}} -{{render "composer"}} +{{outlet "modal"}} +{{outlet "topic-entrance"}} +{{outlet "composer"}} diff --git a/app/assets/javascripts/discourse/views/hide-modal.js.es6 b/app/assets/javascripts/discourse/views/hide-modal.js.es6 index 03ebe408001..c3572eaa30d 100644 --- a/app/assets/javascripts/discourse/views/hide-modal.js.es6 +++ b/app/assets/javascripts/discourse/views/hide-modal.js.es6 @@ -1,8 +1,6 @@ -export default Em.View.extend({ - // No rendering! - render: Em.K, - - _hideModal: function() { +export default Ember.View.extend({ + didInsertElement() { + this._super(); $('#discourse-modal').modal('hide'); - }.on('didInsertElement') + } });