Vulcan/client/app.js

121 lines
2.8 KiB
JavaScript
Raw Normal View History

// ** Client-side helpers **
2012-10-09 12:02:37 +09:00
sessionSetObject=function(name, value){
Session.set(name, JSON.stringify(value));
}
sessionGetObject=function(name){
return JSON.parse(Session.get(name));
}
$.fn.exists = function () {
return this.length !== 0;
}
// ** 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
window.settingsLoaded=true;
if((proxinoKey=getSetting('proxinoKey'))){
Proxino.key = proxinoKey;
Proxino.track_errors();
}
// window.Router = new SimpleRouter();
window.Backbone.history.start({pushState: true});
});
// ** Users **
Meteor.subscribe('users');
2012-09-06 15:28:58 +09:00
// ** Notifications **
// Only load if user is logged in
if(Meteor.user()){
Notifications = new Meteor.Collection('notifications');
Meteor.subscribe('notifications');
}
// ** Posts **
// Collection depends on postsView object
2012-08-22 21:27:22 -04:00
Posts = new Meteor.Collection('posts');
2012-10-09 12:02:37 +09:00
var postsView={
find: {},
sort: {submitted: -1},
skip:0,
postsPerPage:10,
2012-10-09 14:24:06 +09:00
limit:1
2012-10-09 12:02:37 +09:00
}
sessionSetObject('postsView', postsView);
2012-10-08 16:12:47 +02:00
Meteor.autosubscribe(function() {
2012-10-09 12:02:37 +09:00
var view=sessionGetObject('postsView');
2012-10-09 15:34:00 +09:00
Meteor.subscribe('posts', view, function() {
// collectionArray=Posts.find().fetch();
// console.log('--------- Publishing ----------');
// console.log('postsView: ', view);
// for(i=0;i<collectionArray.length;i++){
// console.log('- '+collectionArray[i].headline);
// }
// console.log('found '+collectionArray.length+' posts');
2012-10-08 16:12:47 +02:00
});
});
2012-08-22 21:27:22 -04:00
2012-08-23 00:15:48 -04:00
// ** 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 session variable
2012-10-08 16:49:01 +09:00
Session.set('selectedPostId', null);
Comments = new Meteor.Collection('comments');
Meteor.autosubscribe(function() {
Meteor.subscribe('comments', Session.get('selectedPostId'), function() {
//
});
2012-09-24 15:36:37 +09:00
});
2012-09-06 19:42:11 +09:00
2012-10-01 14:52:32 +09:00
// ** Handlebars helpers **
2012-10-05 22:09:13 +09:00
Handlebars.registerHelper('canView', function(action) {
2012-10-08 16:49:01 +09:00
var action=(typeof action !== 'string') ? null : action;
return canView(Meteor.user(), action);
2012-10-05 22:09:13 +09:00
});
Handlebars.registerHelper('canPost', function(action) {
2012-10-08 16:49:01 +09:00
var action=(typeof action !== 'string') ? null : action;
return canPost(Meteor.user(), action);
2012-10-05 22:09:13 +09:00
});
Handlebars.registerHelper('canComment', function(action) {
2012-10-08 16:49:01 +09:00
var action=(typeof action !== 'string') ? null : action;
return canComment(Meteor.user(), action);
2012-10-05 22:09:13 +09:00
});
Handlebars.registerHelper('canUpvote', function(collection, action) {
2012-10-08 16:49:01 +09:00
var action=(typeof action !== 'string') ? null : action;
return canUpvote(Meteor.user()), collection, action;
2012-10-05 22:09:13 +09:00
});
Handlebars.registerHelper('canDownvote', function(collection, action) {
2012-10-08 16:49:01 +09:00
var action=(typeof action !== 'string') ? null : action;
return canDownvote(Meteor.user(), collection, action);
2012-10-04 14:54:26 +09:00
});