Use container for appending views in Discourse.ContainerView

This commit is contained in:
Robin Ward 2015-09-16 13:05:22 -04:00
parent 1689f436d9
commit 59c628735f
4 changed files with 44 additions and 59 deletions

View File

@ -11,11 +11,6 @@ export default DButton.extend({
top: position.top top: position.top
}; };
// TODO views/topic-footer-buttons is instantiating this via attachViewWithArgs
// attachViewWithArgs does not set this.appEvents, it is undefined
// this is a workaround but a proper fix probably depends on either deprecation
// of attachViewClass et.el or correction of the methods to hydrate the depndencies
this.appEvents = this.appEvents || this.container.lookup('app-events:main');
this.appEvents.trigger("popup-menu:open", loc); this.appEvents.trigger("popup-menu:open", loc);
this.sendAction("action"); this.sendAction("action");
} }

View File

@ -1,6 +1,11 @@
export default Ember.ContainerView.extend({ export default Ember.ContainerView.extend({
attachViewWithArgs(viewArgs, viewClass) { attachViewWithArgs(viewArgs, viewClass) {
if (typeof viewClass === "string") {
viewClass = this.container.lookupFactory("view:" + viewClass) ||
this.container.lookupFactory("component:" + viewClass);
}
if (!viewClass) { viewClass = Ember.View.extend(); } if (!viewClass) { viewClass = Ember.View.extend(); }
this.pushObject(this.createChildView(viewClass, viewArgs)); this.pushObject(this.createChildView(viewClass, viewArgs));
}, },

View File

@ -1,69 +1,24 @@
import LoginReplyButton from 'discourse/views/login-reply-button'; import ContainerView from 'discourse/views/container';
import FlagTopicButton from 'discourse/views/flag-topic-button'; import { on } from 'ember-addons/ember-computed-decorators';
import BookmarkButton from 'discourse/views/bookmark-button';
import ShareButton from 'discourse/views/share-button';
import InviteReplyButton from 'discourse/views/invite-reply-button';
import ReplyButton from 'discourse/views/reply-button';
import PinnedButton from 'discourse/components/pinned-button';
import TopicNotificationsButton from 'discourse/components/topic-notifications-button';
import DiscourseContainerView from 'discourse/views/container';
import ShowPopupButton from 'discourse/components/show-popup-button';
const MainPanel = Discourse.ContainerView.extend({ export default ContainerView.extend({
elementId: 'topic-footer-main-buttons',
topicBinding: 'controller.content',
init() {
this._super();
if (Discourse.User.currentProp('staff')) {
const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'};
this.attachViewWithArgs(viewArgs, ShowPopupButton);
}
const topic = this.get('topic');
if (!topic.get('isPrivateMessage')) {
// We hide some controls from private messages
if (this.get('topic.details.can_invite_to')) {
this.attachViewClass(InviteReplyButton);
}
this.attachViewClass(BookmarkButton);
this.attachViewClass(ShareButton);
if (this.get('topic.details.can_flag_topic')) {
this.attachViewClass(FlagTopicButton);
}
}
if (this.get('topic.details.can_create_post')) {
this.attachViewClass(ReplyButton);
}
}
});
export default DiscourseContainerView.extend({
elementId: 'topic-footer-buttons', elementId: 'topic-footer-buttons',
topicBinding: 'controller.content',
init() { @on('init')
this._super();
this.createButtons();
},
// Add the buttons below a topic
createButtons() { createButtons() {
const topic = this.get('topic'); const topic = this.get('topic');
const currentUser = this.get('controller.currentUser'); const currentUser = this.get('controller.currentUser');
if (currentUser) { if (currentUser) {
const viewArgs = {topic}; const viewArgs = { topic, currentUser };
this.attachViewWithArgs(viewArgs, MainPanel); this.attachViewWithArgs(viewArgs, 'topic-footer-main-buttons');
this.attachViewWithArgs(viewArgs, PinnedButton); this.attachViewWithArgs(viewArgs, 'pinned-button');
this.attachViewWithArgs(viewArgs, TopicNotificationsButton); this.attachViewWithArgs(viewArgs, 'topic-notifications-button');
this.trigger('additionalButtons', this); this.trigger('additionalButtons', this);
} else { } else {
// If not logged in give them a login control // If not logged in give them a login control
this.attachViewClass(LoginReplyButton); this.attachViewClass('login-reply-button');
} }
} }
}); });

View File

@ -0,0 +1,30 @@
import ContainerView from 'discourse/views/container';
import { on } from 'ember-addons/ember-computed-decorators';
export default ContainerView.extend({
elementId: 'topic-footer-main-buttons',
@on('init')
createButtons() {
if (this.currentUser.get('staff')) {
const viewArgs = {action: 'showTopicAdminMenu', title: 'topic_admin_menu', icon: 'wrench', position: 'absolute'};
this.attachViewWithArgs(viewArgs, 'show-popup-button');
}
const topic = this.get('topic');
if (!topic.get('isPrivateMessage')) {
// We hide some controls from private messages
if (this.get('topic.details.can_invite_to')) {
this.attachViewClass('invite-reply-button');
}
this.attachViewClass('bookmark-button');
this.attachViewClass('share-button');
if (this.get('topic.details.can_flag_topic')) {
this.attachViewClass('flag-topic-button');
}
}
if (this.get('topic.details.can_create_post')) {
this.attachViewClass('reply-button');
}
}
});