define('home/views/PostActivityCollectionView',[
'underscore',
'backbone-marionette',
'home/views/PostView',
'home/views/ReplyActivityView',
], function (
_,
Marionette,
PostView,
ReplyActivityView
) {
'use strict';
/**
* A view that shows a collection of activities that are all post or reply activities.
* Shows the appropriate view per activity depending on the type of activity.
*/
var PostActivityCollectionView = Marionette.CollectionView.extend({
initialize: function (options) {
// Posts should be collapsed by default, collapsePosts should only
// be false if an option was given explicitly setting it to false
this.collapsePosts = !options || options.collapsePosts !== false;
},
getItemView: function (activity) {
return activity.get('verb') === 'reply' ? ReplyActivityView : PostView;
},
itemViewOptions: function (activity, index) {
var model = activity;
if (activity.get('verb') === 'post') {
// The PostView expects a Post as its model. Pull the Post
// out of the given activity.
model = activity.object;
}
var existingClassName = this.getItemView(activity).prototype.className;
existingClassName = _.isFunction(existingClassName) ?
existingClassName.call({ model: activity }) :
existingClassName || '';
var className = existingClassName;
if (index > 0)
className += ' collapsible';
return {
model: model,
className: className,
shouldCollapse: this.collapsePosts,
};
},
});
return PostActivityCollectionView;
});