Vulcan/client/app.js

110 lines
2.9 KiB
JavaScript
Raw Normal View History

2012-12-11 10:47:11 +09:00
Session.set('initialLoad', true);
// HELPERS
2012-10-24 11:04:42 +09:00
getSetting = function(setting){
var settings=Settings.find().fetch()[0];
if(settings){
return settings[setting];
}
return '';
}
2012-11-19 12:03:06 +09:00
clearSeenErrors = function(){
Errors.update({seen:true}, {$set: {show:false}}, {multi:true});
}
// SUBSCRIPTIONS
// ** Errors **
// Local (client-only) collection
2012-10-09 12:02:37 +09:00
2012-10-08 10:44:13 +09:00
Errors = new Meteor.Collection(null);
// ** Settings **
Settings = new Meteor.Collection('settings');
Meteor.subscribe('settings', function(){
// runs once on site load
2012-12-11 10:47:11 +09:00
analyticsInit();
2012-11-21 14:31:58 +09:00
Session.set('settingsLoaded',true);
});
2012-11-17 13:24:19 +09:00
// ** Users **
Meteor.subscribe('currentUser');
Meteor.subscribe('allUsers');
// ** Notifications **
// Only load if user is logged in
var Notifications = new Meteor.Collection('notifications');
if(Meteor.user()){
Meteor.subscribe('notifications');
}
// ** Posts **
// We have a few subscriptions here, for the various ways we load posts
//
// The advantage is that
// a) we can change pages a lot quicker
// XXX: and we can animate between them (todo)
// b) we know when an individual page is ready
2012-08-22 21:27:22 -04:00
Posts = new Meteor.Collection('posts');
2012-10-09 12:02:37 +09:00
2012-10-24 11:04:42 +09:00
STATUS_PENDING=1;
STATUS_APPROVED=2;
STATUS_REJECTED=3;
FIND_APPROVED={$or: [{status: {$exists : false}}, {status: STATUS_APPROVED}]};
DIGEST_PAGE_PER_PAGE = 5;
var postListSubscription = function(find, options, per_page) {
var handle = paginatedSubscription(per_page, 'paginatedPosts', find, options);
handle.fetch = function() {
return limitDocuments(Posts.find(find, options), handle.loaded());
}
return handle;
2012-10-09 12:02:37 +09:00
}
var topPostsHandle = postListSubscription(FIND_APPROVED, {sort: {score: -1}}, 10);
var newPostsHandle = postListSubscription(FIND_APPROVED, {sort: {submitted: -1}}, 10);
var bestPostsHandle = postListSubscription(FIND_APPROVED, {sort: {baseScore: -1}}, 10);
var pendingPostsHandle = postListSubscription(
{$or: [{status: STATUS_PENDING}, {status: STATUS_REJECTED}]},
{sort: {score: -1}},
10
);
// setupPostSubscription('digestPosts', {
// find: function() {
// var mDate = moment(Session.get('currentDate'));
// var find = {
// submitted: {
// $gte: mDate.startOf('day').valueOf(),
// $lt: mDate.endOf('day').valueOf()
// }
// };
// find=_.extend(find, FIND_APPROVED);
// return find;
// },
// sort: {score: -1}
// ,perPage: DIGEST_PAGE_PER_PAGE
// });
// ** Categories **
2012-08-30 21:35:48 -04:00
Categories = new Meteor.Collection('categories');
Meteor.subscribe('categories');
2012-10-01 12:23:35 +09:00
// ** Comments **
// Collection depends on selectedPostId and selectedCommentId session variable
2012-10-08 16:49:01 +09:00
Session.set('selectedPostId', null);
Comments = new Meteor.Collection('comments');
Meteor.autosubscribe(function() {
var query = { $or : [ { post : Session.get('selectedPostId') } , { _id : Session.get('selectedCommentId') } ] };
Meteor.subscribe('comments', query, function() {
Session.set('commentReady', true);
});
2012-10-04 14:54:26 +09:00
});