Fixes to {{#groupedEach}}

This commit is contained in:
Robin Ward 2013-08-02 15:14:24 -04:00
parent 9db0ac16a9
commit 701843552a
8 changed files with 68 additions and 53 deletions

View File

@ -10,6 +10,7 @@ var DiscourseGroupedEach = function(context, path, options) {
this.normalizedRoot = normalized.root;
this.normalizedPath = normalized.path;
this.content = this.lookupContent();
this.destroyed = false;
this.addContentObservers();
this.addArrayObservers();
@ -41,6 +42,8 @@ DiscourseGroupedEach.prototype = {
},
addArrayObservers: function() {
if (!this.content) { return; }
this.content.addArrayObserver(this, {
willChange: 'contentArrayWillChange',
didChange: 'contentArrayDidChange'
@ -48,6 +51,8 @@ DiscourseGroupedEach.prototype = {
},
removeArrayObservers: function() {
if (!this.content) { return; }
this.content.removeArrayObserver(this, {
willChange: 'contentArrayWillChange',
didChange: 'contentArrayDidChange'
@ -65,6 +70,8 @@ DiscourseGroupedEach.prototype = {
},
render: function() {
if (!this.content) { return; }
var content = this.content,
contentLength = Em.get(content, 'length'),
data = this.options.data,
@ -72,18 +79,28 @@ DiscourseGroupedEach.prototype = {
data.insideEach = true;
data.insideGroup = true;
for (var i = 0; i < contentLength; i++) {
template(content.objectAt(i), { data: data });
}
},
rerenderContainingView: function() {
Ember.run.scheduleOnce('render', this.containingView, 'rerender');
var self = this;
Ember.run.scheduleOnce('render', this, function() {
// It's possible it's been destroyed after we enqueued a re-render call.
if (!self.destroyed) {
self.containingView.rerender();
}
});
},
destroy: function() {
this.removeContentObservers();
this.removeArrayObservers();
if (this.content) {
this.removeArrayObservers();
}
this.destroyed = true;
}
};

View File

@ -10,7 +10,6 @@
{{/if}}
</nav>
{{#if summaryCollapsed}}
<section class='summary collapsed'>
<ul class="clearfix">
@ -42,7 +41,7 @@
</li>
{{#if details.fewParticipants}}
<li class='avatars'>
{{#each details.fewParticipants}}{{participant participant=this}}{{/each}}
{{#groupedEach details.fewParticipants}}{{participant participant=this}}{{/groupedEach}}
</li>
{{/if}}
</ul>
@ -74,20 +73,22 @@
{{#if details.participants}}
<section class='avatars clearfix'>
{{#each details.participants}}{{participant participant=this}}{{/each}}
{{#groupedEach details.participants}}{{participant participant=this}}{{/groupedEach}}
</section>
{{/if}}
{{#if view.parentView.infoLinks}}
<section class='links'>
<ul class='topic-links'>
{{#collection contentBinding="view.parentView.infoLinks" itemTagName="li"}}
<span class='badge badge-notification clicks' title='{{i18n topic_summary.clicks}}'>{{clicks}}</span>
<a href="{{unbound url}}" target="_blank" class='topic-link track-link' data-user-id="{{unbound user_id}}" data-ignore-post-id="true" title="{{unbound url}}">
{{#if title}}{{shorten title}}{{else}}{{shortenUrl url}}{{/if}}
{{#if internal}}<i class='icon-arrow-right' title='{{i18n topic_summary.topic_link}}'></i>{{/if}}
</a>
{{/collection}}
{{#groupedEach view.parentView.infoLinks}}
<li>
<span class='badge badge-notification clicks' title='{{i18n topic_summary.clicks}}'>{{clicks}}</span>
<a href="{{unbound url}}" target="_blank" class='topic-link track-link' data-user-id="{{unbound user_id}}" data-ignore-post-id="true" title="{{unbound url}}">
{{#if title}}{{shorten title}}{{else}}{{shortenUrl url}}{{/if}}
{{#if internal}}<i class='icon-arrow-right' title='{{i18n topic_summary.topic_link}}'></i>{{/if}}
</a>
</li>
{{/groupedEach}}
</ul>
{{#if view.parentView.showAllLinksControls}}

View File

@ -1,11 +1,11 @@
<h3><i class='icon icon-envelope'></i> {{i18n private_message_info.title}}</h3>
<div class='participants clearfix'>
{{#each details.allowed_groups}}
{{#groupedEach details.allowed_groups}}
<div class='user group'>
#{{unbound name}}
</div>
{{/each}}
{{#each details.allowed_users}}
{{/groupedEach}}
{{#groupedEach details.allowed_users}}
<div class='user'>
<a href='/users/{{lower username}}'>
{{avatar this imageSize="small"}}
@ -17,7 +17,7 @@
<a class='remove-invited' {{action removeAllowedUser username}}><i class="icon-remove"></i></a>
{{/if}}
</div>
{{/each}}
{{/groupedEach}}
</div>
{{#if details.can_invite_to}}
<div class='controls'>

View File

@ -0,0 +1,23 @@
{{#groupedEach model.content}}
<div {{bindAttr class=":item hidden deleted moderator_action"}}>
<div class='clearfix info'>
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
<span class="title">
<a href="{{unbound postUrl}}">{{unbound title}}</a>
</span>
<span class="type">{{unbound descriptionHtml}}</span>
</div>
<p class='excerpt'>
{{{unbound excerpt}}}
</p>
{{#groupedEach children}}
<div class='child-actions'>
<i class="icon {{unbound icon}}"></i>
{{#groupedEach items}}
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a>
{{/groupedEach}}
</div>
{{/groupedEach}}
</div>
{{/groupedEach}}

View File

@ -1,21 +0,0 @@
<div {{bindAttr class=":item hidden deleted moderator_action"}}>
<div class='clearfix info'>
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span>
<span class="title">
<a href="{{unbound postUrl}}">{{unbound title}}</a>
</span>
<span class="type">{{unbound descriptionHtml}}</span>
</div>
<p class='excerpt'>
{{{unbound excerpt}}}
</p>
{{#each children}}
<div class='child-actions'>
<i class="icon {{unbound icon}}"></i>
{{#each items}}
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a>
{{/each}}
</div>
{{/each}}
</div>

View File

@ -12,7 +12,7 @@ Discourse.RepliesView = Ember.CollectionView.extend({
classNames: ['replies-list', 'embedded-posts', 'bottom'],
itemViewClass: Discourse.EmbeddedPostView,
repliesShown: (function() {
repliesShownChanged: function() {
var $this = this.$();
if (this.get('parentView.repliesShown')) {
Em.run.schedule('afterRender', function() {
@ -23,7 +23,7 @@ Discourse.RepliesView = Ember.CollectionView.extend({
$this.slideUp();
});
}
}).observes('parentView.repliesShown')
}.observes('parentView.repliesShown')
});

View File

@ -41,9 +41,8 @@ Discourse.TopicSummaryView = Discourse.ContainerView.extend({
this.attachViewWithArgs({
templateName: 'topic_summary/info',
topic: this.get('topic'),
summaryView: this
});
content: this.get('controller')
}, Discourse.GroupedView);
this.trigger('appendSummaryInformation', this);
},
@ -59,8 +58,9 @@ Discourse.TopicSummaryView = Discourse.ContainerView.extend({
container.attachViewWithArgs({
templateName: 'topic_summary/best_of_toggle',
tagName: 'section',
classNames: ['information']
});
classNames: ['information'],
content: this.get('controller')
}, Discourse.GroupedView);
}
// If we have a private message
@ -68,8 +68,9 @@ Discourse.TopicSummaryView = Discourse.ContainerView.extend({
container.attachViewWithArgs({
templateName: 'topic_summary/private_message',
tagName: 'section',
classNames: ['information']
});
classNames: ['information'],
content: this.get('controller')
}, Discourse.GroupedView);
}
}
});

View File

@ -7,14 +7,11 @@
@uses Discourse.LoadMore
@module Discourse
**/
Discourse.UserStreamView = Ember.CollectionView.extend(Discourse.LoadMore, {
Discourse.UserStreamView = Discourse.View.extend(Discourse.LoadMore, {
loading: false,
content: Em.computed.alias('controller.model.content'),
eyelineSelector: '#user-activity .user-stream .item',
classNames: ['user-stream'],
itemViewClass: Discourse.GroupedView.extend({ templateName: 'user/stream_item' }),
loadMore: function() {
var userStreamView = this;
if (userStreamView.get('loading')) { return; }
@ -26,6 +23,3 @@ Discourse.UserStreamView = Ember.CollectionView.extend(Discourse.LoadMore, {
});
}
});
Discourse.View.registerHelper('userStream', Discourse.UserStreamView);