FIX: Remove `grouped-each` helper. GroupedView is deprecated in Ember
1.9
This commit is contained in:
parent
873277ae5f
commit
824c0b0f87
|
@ -1,143 +0,0 @@
|
|||
var DiscourseGroupedEach = function(context, path, options) {
|
||||
var self = this,
|
||||
normalized = Ember.Handlebars.normalizePath(context, path, options.data);
|
||||
|
||||
this.context = context;
|
||||
this.path = path;
|
||||
this.options = options;
|
||||
this.template = options.fn;
|
||||
this.containingView = options.data.view;
|
||||
this.normalizedRoot = normalized.root;
|
||||
this.normalizedPath = normalized.path;
|
||||
this.content = this.lookupContent();
|
||||
this.destroyed = false;
|
||||
|
||||
this.addContentObservers();
|
||||
this.addArrayObservers();
|
||||
|
||||
this.containingView.on('willClearRender', function() {
|
||||
self.destroy();
|
||||
});
|
||||
};
|
||||
|
||||
DiscourseGroupedEach.prototype = {
|
||||
contentWillChange: function() {
|
||||
this.removeArrayObservers();
|
||||
},
|
||||
|
||||
contentDidChange: function() {
|
||||
this.content = this.lookupContent();
|
||||
this.addArrayObservers();
|
||||
this.rerenderContainingView();
|
||||
},
|
||||
|
||||
contentArrayWillChange: Ember.K,
|
||||
|
||||
contentArrayDidChange: function() {
|
||||
this.rerenderContainingView();
|
||||
},
|
||||
|
||||
lookupContent: function() {
|
||||
return Ember.Handlebars.get(this.normalizedRoot, this.normalizedPath, this.options);
|
||||
},
|
||||
|
||||
addArrayObservers: function() {
|
||||
if (!this.content) { return; }
|
||||
|
||||
this.content.addArrayObserver(this, {
|
||||
willChange: 'contentArrayWillChange',
|
||||
didChange: 'contentArrayDidChange'
|
||||
});
|
||||
},
|
||||
|
||||
removeArrayObservers: function() {
|
||||
if (!this.content) { return; }
|
||||
|
||||
this.content.removeArrayObserver(this, {
|
||||
willChange: 'contentArrayWillChange',
|
||||
didChange: 'contentArrayDidChange'
|
||||
});
|
||||
},
|
||||
|
||||
addContentObservers: function() {
|
||||
Ember.addBeforeObserver(this.normalizedRoot, this.normalizedPath, this, this.contentWillChange);
|
||||
Ember.addObserver(this.normalizedRoot, this.normalizedPath, this, this.contentDidChange);
|
||||
},
|
||||
|
||||
removeContentObservers: function() {
|
||||
Ember.removeBeforeObserver(this.normalizedRoot, this.normalizedPath, this.contentWillChange);
|
||||
Ember.removeObserver(this.normalizedRoot, this.normalizedPath, this.contentDidChange);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
if (!this.content) { return; }
|
||||
|
||||
var content = this.content,
|
||||
contentLength = Em.get(content, 'length'),
|
||||
data = this.options.data,
|
||||
template = this.template,
|
||||
keyword = this.options.hash.keyword;
|
||||
|
||||
data.insideEach = true;
|
||||
for (var i = 0; i < contentLength; i++) {
|
||||
var row = content.objectAt(i);
|
||||
var keywords = Em.get(data, 'keywords');
|
||||
if (!keywords) {
|
||||
keywords = {};
|
||||
Em.set(data, 'keywords', keywords);
|
||||
}
|
||||
if (keyword) {
|
||||
Em.set(keywords, keyword, row);
|
||||
}
|
||||
template(row, { data: data });
|
||||
}
|
||||
},
|
||||
|
||||
rerenderContainingView: function() {
|
||||
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();
|
||||
if (this.content) {
|
||||
this.removeArrayObservers();
|
||||
}
|
||||
this.destroyed = true;
|
||||
}
|
||||
};
|
||||
|
||||
function groupedEachHelper(path, options) {
|
||||
if (arguments.length === 4) {
|
||||
Ember.assert("If you pass more than one argument to the groupedEach helper, it must be in the form #groupedEach foo in bar", arguments[1] === "in");
|
||||
|
||||
var keywordName = arguments[0];
|
||||
|
||||
options = arguments[3];
|
||||
path = arguments[2];
|
||||
if (path === '') { path = "this"; }
|
||||
|
||||
options.hash.keyword = keywordName;
|
||||
}
|
||||
|
||||
if (arguments.length === 1) {
|
||||
options = path;
|
||||
path = 'this';
|
||||
}
|
||||
|
||||
options.hash.dataSourceBinding = path;
|
||||
options.data.insideGroup = true;
|
||||
new DiscourseGroupedEach(this, path, options).render();
|
||||
}
|
||||
|
||||
Ember.Handlebars.registerHelper('groupedEach', function() {
|
||||
Em.warn("The `groupedEach` helper is deprecated. Use `grouped-each` instead.");
|
||||
return groupedEachHelper.apply(this, Array.prototype.slice.apply(arguments));
|
||||
});
|
||||
|
||||
Ember.Handlebars.registerHelper('grouped-each', groupedEachHelper);
|
|
@ -1,16 +1,17 @@
|
|||
{{#if loaded}}
|
||||
{{#if topics}}
|
||||
<table class="topic-list">
|
||||
{{#grouped-each topic in topics}}
|
||||
<tbody>
|
||||
{{#each topics}}
|
||||
<tr {{bind-attr class="archived"}}>
|
||||
<td>
|
||||
<div class='main-link clearfix'>
|
||||
{{topic-status topic=this}}
|
||||
{{topic-link this}}
|
||||
{{topic-post-badges unread=unread
|
||||
newPosts=topic.new_posts
|
||||
unseen=topic.unseen
|
||||
url=topic.lastUnreadUrl}}
|
||||
newPosts=new_posts
|
||||
unseen=unseen
|
||||
url=lastUnreadUrl}}
|
||||
|
||||
{{#if hasExcerpt}}
|
||||
<div class="topic-excerpt">
|
||||
|
@ -26,8 +27,8 @@
|
|||
</div>
|
||||
<div class="topic-item-stats clearfix">
|
||||
<div class="pull-right">
|
||||
{{posts-count-column topic=topic tagName="div" class="num posts" action="clickedPosts"}}
|
||||
{{raw "list/activity-column" topic=topic tagName="div" class="num activity last"}}
|
||||
{{posts-count-column topic=this tagName="div" class="num posts" action="clickedPosts"}}
|
||||
{{raw "list/activity-column" topic=this tagName="div" class="num activity last"}}
|
||||
</div>
|
||||
{{#unless controller.hideCategory}}
|
||||
<div class='category'>
|
||||
|
@ -36,7 +37,7 @@
|
|||
{{/unless}}
|
||||
{{#if controller.showParticipants}}
|
||||
<div class='participants'>
|
||||
{{#each topic.participants}}
|
||||
{{#each participants}}
|
||||
<a href="{{user.path}}" class="{{extras}}">{{avatar this usernamePath="user.username" imageSize="small"}}</a>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
@ -45,7 +46,7 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{/grouped-each}}
|
||||
{{/each}}
|
||||
</table>
|
||||
{{else}}
|
||||
<div class='alert alert-info'>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{{#grouped-each model.content}}
|
||||
{{#each model.content}}
|
||||
<div {{bind-attr class=":item hidden deleted moderator_action"}}>
|
||||
<div class='clearfix info'>
|
||||
<a href="{{unbound userUrl}}" data-user-card="{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
|
@ -9,10 +9,10 @@
|
|||
<span class="category">{{category-link category}}</span>
|
||||
</div>
|
||||
<p class='excerpt'>{{{unbound excerpt}}}</p>
|
||||
{{#grouped-each children}}
|
||||
{{#each children}}
|
||||
<div class='child-actions'>
|
||||
<i class="icon {{unbound icon}}"></i>
|
||||
{{#grouped-each items}}
|
||||
{{#each items}}
|
||||
{{#if removableBookmark}}
|
||||
<button class="btn btn-default remove-bookmark" {{action "removeBookmark" this}}>
|
||||
{{fa-icon 'times'}} {{i18n "bookmarks.remove"}}
|
||||
|
@ -20,8 +20,8 @@
|
|||
{{/if}}
|
||||
<a href="{{unbound userUrl}}" data-user-card="{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a>
|
||||
{{#if edit_reason}} — <span class="edit-reason">{{unbound edit_reason}}</span>{{/if}}
|
||||
{{/grouped-each}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/grouped-each}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/grouped-each}}
|
||||
{{/each}}
|
||||
|
|
Loading…
Reference in New Issue