2012-10-19 19:20:14 +09:00
|
|
|
// ** Handlebars helpers **
|
|
|
|
|
2013-10-28 16:04:55 +09:00
|
|
|
Handlebars.registerHelper('eachWithRank', function(items, options) {
|
2013-10-29 16:05:55 +09:00
|
|
|
// not used, forces multiple renders
|
2013-10-28 16:04:55 +09:00
|
|
|
// note: cannot use this because it would delete and recreate all nodes
|
|
|
|
items.rewind()
|
2013-10-28 13:35:20 +09:00
|
|
|
var out = '';
|
|
|
|
items.forEach(function(item, i){
|
|
|
|
var key = 'Branch-' + i;
|
|
|
|
out = out + Spark.labelBranch(key,function(){
|
2013-10-28 17:07:18 +11:00
|
|
|
return options.fn(_.extend(item, {rank: i}));
|
2013-10-28 13:35:20 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return out;
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2013-10-28 16:04:55 +09:00
|
|
|
|
2013-10-15 12:28:57 +09:00
|
|
|
Handlebars.registerHelper('getSetting', function(setting, defaultArgument){
|
|
|
|
return getSetting(setting, defaultArgument);
|
2013-10-14 12:14:12 +09:00
|
|
|
});
|
2013-10-25 10:37:39 +09:00
|
|
|
Handlebars.registerHelper('canView', function() {
|
|
|
|
return canView(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2013-10-25 10:37:39 +09:00
|
|
|
Handlebars.registerHelper('canPost', function() {
|
|
|
|
return canPost(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2013-10-25 10:37:39 +09:00
|
|
|
Handlebars.registerHelper('canComment', function() {
|
|
|
|
return canComment(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2013-10-25 10:37:39 +09:00
|
|
|
Handlebars.registerHelper('canUpvote', function(collection) {
|
|
|
|
return canUpvote(Meteor.user(), collection);
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2013-10-25 10:37:39 +09:00
|
|
|
Handlebars.registerHelper('canDownvote', function(collection) {
|
|
|
|
return canDownvote(Meteor.user(), collection);
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
|
|
|
Handlebars.registerHelper('isAdmin', function(showError) {
|
|
|
|
if(isAdmin(Meteor.user())){
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
if((typeof showError === "string") && (showError === "true"))
|
2013-11-11 22:07:19 +01:00
|
|
|
throwError(i18n.t('Sorry, you do not have access to this page'));
|
2012-10-19 19:20:14 +09:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-11-21 14:31:58 +09:00
|
|
|
Handlebars.registerHelper('canEdit', function(collectionName, item, action) {
|
2012-10-19 19:20:14 +09:00
|
|
|
var action = (typeof action !== 'string') ? null : action;
|
|
|
|
var collection = (typeof collectionName !== 'string') ? Posts : eval(collectionName);
|
2012-11-21 14:31:58 +09:00
|
|
|
console.log(item);
|
|
|
|
// var itemId = (collectionName==="Posts") ? Session.get('selectedPostId') : Session.get('selectedCommentId');
|
|
|
|
// var item=collection.findOne(itemId);
|
2012-10-19 19:20:14 +09:00
|
|
|
return item && canEdit(Meteor.user(), item, action);
|
2013-11-21 11:32:09 +09:00
|
|
|
});
|