Vulcan/client/components/postList/posts_list.js

77 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-03-31 10:04:41 +09:00
// ----------------------------------- Post List -----------------------------------//
Template[getTemplate('posts_list')].created = function() {
Session.set('listPopulatedAt', new Date());
};
2014-07-05 11:24:28 +09:00
Template[getTemplate('posts_list')].helpers({
postsLayout: function () {
return getSetting('postsLayout', 'posts-list');
},
description: function () {
var controller = Iron.controller();
if (typeof controller.getDescription === 'function')
return Iron.controller().getDescription();
},
before_post_item: function () {
return getTemplate('before_post_item');
},
2014-07-05 11:42:28 +09:00
post_item: function () {
return getTemplate('post_item');
},
after_post_item: function () {
return getTemplate('after_post_item');
},
postsCursor : function () {
2015-01-10 12:46:44 +09:00
if (this.postsCursor) { // not sure why this should ever be undefined, but it can apparently
var posts = this.postsCursor.map(function (post, index, cursor) {
post.rank = index;
return post;
});
return posts;
} else {
console.log('postsCursor not defined')
}
2013-10-29 16:55:59 +09:00
},
2014-08-28 10:16:17 +09:00
postsLoadMore: function () {
return getTemplate('postsLoadMore');
},
postsListIncoming: function () {
return getTemplate('postsListIncoming');
2015-03-22 09:42:58 +09:00
},
postsListSort: function () {
return getTemplate('postsListSort');
}
2015-03-31 10:04:41 +09:00
});
// ----------------------------------- Incoming -----------------------------------//
Template[getTemplate('postsListIncoming')].events({
'click .show-new': function(e, instance) {
Session.set('listPopulatedAt', new Date());
}
});
// ----------------------------------- Load More -----------------------------------//
Template[getTemplate('postsLoadMore')].helpers({
postsReady: function () {
return this.postsReady;
},
hasPosts: function () {
return !!this.postsCursor.count();
}
});
Template[getTemplate('postsLoadMore')].events({
'click .more-button': function (event, instance) {
event.preventDefault();
if (this.controllerInstance) {
// controller is a template
this.loadMoreHandler(this.controllerInstance);
} else {
// controller is router
this.loadMoreHandler();
}
}
});