ES6: Refactor embedded post views

This commit is contained in:
Robin Ward 2014-06-18 14:27:27 -04:00
parent 61fb0f736b
commit d919a405cb
5 changed files with 14 additions and 19 deletions

View File

@ -1,7 +1,7 @@
{{post-gap post=this postStream=controller.postStream before="true"}} {{post-gap post=this postStream=controller.postStream before="true"}}
<div class='row'> <div class='row'>
{{view Discourse.ReplyHistory contentBinding="replyHistory"}} {{view 'reply-history' content=replyHistory}}
</div> </div>
<article class='boxed' {{bind-attr id="postElementId"}} {{bind-attr data-post-id="id"}} data-user-id="{{unbound user_id}}"> <article class='boxed' {{bind-attr id="postElementId"}} {{bind-attr data-post-id="id"}} data-user-id="{{unbound user_id}}">
@ -71,9 +71,9 @@
<button {{action expandFirstPost this}} class='btn expand-post'>{{i18n post.show_full}}</button> <button {{action expandFirstPost this}} class='btn expand-post'>{{i18n post.show_full}}</button>
{{/if}} {{/if}}
{{/if}} {{/if}}
{{view 'post-menu' post=this postView=view}} {{view 'post-menu' post=this adminMenu=view.adminMenu}}
</div> </div>
{{view Discourse.RepliesView content=replies postView=view}} {{view 'replies' content=replies}}
{{discourse-action-history post=this}} {{discourse-action-history post=this}}
{{view 'topic-map-container' post=this topic=controller.model}} {{view 'topic-map-container' post=this topic=controller.model}}
</div> </div>

View File

@ -6,19 +6,17 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.EmbeddedPostView = Discourse.GroupedView.extend({ export default Discourse.GroupedView.extend({
templateName: 'embedded_post', templateName: 'embedded_post',
classNames: ['reply'], classNames: ['reply'],
didInsertElement: function() { _startTracking: function() {
var post = this.get('content'); var post = this.get('content');
Discourse.ScreenTrack.current().track(this.get('elementId'), post.get('post_number')); Discourse.ScreenTrack.current().track(this.get('elementId'), post.get('post_number'));
}, }.on('didInsertElement'),
willDestroyElement: function() { _stopTracking: function() {
Discourse.ScreenTrack.current().stopTracking(this.get('elementId')); Discourse.ScreenTrack.current().stopTracking(this.get('elementId'));
} }.on('willDestroyElement')
}); });

View File

@ -229,7 +229,7 @@ export default Discourse.View.extend({
var options = {className: 'create'}; var options = {className: 'create'};
if(!Discourse.Mobile.mobileView) { if(!Discourse.Mobile.mobileView) {
options.textLabel = 'topic.reply.title' options.textLabel = 'topic.reply.title';
} }
return new Button('reply', 'post.controls.reply', 'reply', options); return new Button('reply', 'post.controls.reply', 'reply', options);
@ -273,7 +273,7 @@ export default Discourse.View.extend({
clickAdmin: function() { clickAdmin: function() {
var $adminMenu = this.$('.post-admin-menu'); var $adminMenu = this.$('.post-admin-menu');
this.set('postView.adminMenu', $adminMenu); this.set('adminMenu', $adminMenu);
$adminMenu.show(); $adminMenu.show();
}, },

View File

@ -6,11 +6,9 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.RepliesView = Ember.CollectionView.extend({ export default Ember.CollectionView.extend({
tagName: 'section', tagName: 'section',
classNameBindings: [':embedded-posts', ':bottom', 'hidden'], classNameBindings: [':embedded-posts', ':bottom', 'hidden'],
itemViewClass: Discourse.EmbeddedPostView, itemViewClass: 'embedded-post',
hidden: Em.computed.equal('content.length', 0) hidden: Em.computed.equal('content.length', 0)
}); });

View File

@ -2,14 +2,13 @@
Lists previous posts in the history of a post. Lists previous posts in the history of a post.
@class ReplyHistory @class ReplyHistory
@extends Discourse.EmbeddedPostView
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.ReplyHistory = Em.CollectionView.extend({ export default Em.CollectionView.extend({
tagName: 'section', tagName: 'section',
classNameBindings: [':embedded-posts', ':top', ':topic-body', ':offset2', 'hidden'], classNameBindings: [':embedded-posts', ':top', ':topic-body', ':offset2', 'hidden'],
itemViewClass: Discourse.EmbeddedPostView, itemViewClass: 'embedded-post',
hidden: Em.computed.equal('content.length', 0), hidden: Em.computed.equal('content.length', 0),
previousPost: true previousPost: true
}); });