Use `{{outlets}}` instead of `{{render}}` in the application template

This commit is contained in:
Robin Ward 2016-10-26 13:02:58 -04:00
parent 3ff563e510
commit eeee5f4c08
5 changed files with 28 additions and 20 deletions

View File

@ -6,7 +6,10 @@ export default htmlHelper((user, args) => {
if (!user) { return; } if (!user) { return; }
const name = escapeExpression(user.get('name')); 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')) { if (currentUser && user.get('admin') && currentUser.get('staff')) {
return iconHTML('shield', { label: I18n.t('user.admin', { user: name }) }); return iconHTML('shield', { label: I18n.t('user.admin', { user: name }) });

View File

@ -63,7 +63,9 @@ export default {
app.register('screen-track:main', screenTrack, { instantiate: false }); app.register('screen-track:main', screenTrack, { instantiate: false });
inject(app, 'screenTrack', 'component', 'route'); 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); app.register('location:discourse-location', DiscourseLocation);

View File

@ -20,14 +20,7 @@ function unlessReadOnly(method, message) {
const ApplicationRoute = Discourse.Route.extend(OpenComposer, { const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
siteTitle: setting('title'), siteTitle: setting('title'),
_handleLogout() {
if (this.currentUser) {
this.currentUser.destroySession().then(() => logout(this.siteSettings, this.keyValueStore));
}
},
actions: { actions: {
toggleAnonymous() { toggleAnonymous() {
ajax("/users/toggle-anon", {method: 'POST'}).then(() => { ajax("/users/toggle-anon", {method: 'POST'}).then(() => {
window.location.reload(); 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() { handleShowLogin() {
if (this.siteSettings.enable_sso) { if (this.siteSettings.enable_sso) {
const returnPath = encodeURIComponent(window.location.pathname); const returnPath = encodeURIComponent(window.location.pathname);
@ -198,7 +199,6 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
}, },
_autoLogin(modal, modalClass, notAuto) { _autoLogin(modal, modalClass, notAuto) {
const methods = findAll(this.siteSettings, const methods = findAll(this.siteSettings,
this.container.lookup('capabilities:main'), this.container.lookup('capabilities:main'),
this.site.isMobileDevice); 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); RSVP.EventTarget.mixin(ApplicationRoute);

View File

@ -15,7 +15,7 @@
{{create-topics-notice}} {{create-topics-notice}}
</div> </div>
{{outlet}} {{outlet}}
{{render "user-card"}} {{outlet "user-card"}}
</div> </div>
{{plugin-outlet "above-footer"}} {{plugin-outlet "above-footer"}}
@ -24,6 +24,6 @@
{{/if}} {{/if}}
{{plugin-outlet "below-footer"}} {{plugin-outlet "below-footer"}}
{{render "modal"}} {{outlet "modal"}}
{{render "topic-entrance"}} {{outlet "topic-entrance"}}
{{render "composer"}} {{outlet "composer"}}

View File

@ -1,8 +1,6 @@
export default Em.View.extend({ export default Ember.View.extend({
// No rendering! didInsertElement() {
render: Em.K, this._super();
_hideModal: function() {
$('#discourse-modal').modal('hide'); $('#discourse-modal').modal('hide');
}.on('didInsertElement') }
}); });