mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00

Currently, ``throwError`` is used for all manner of messages, including errors, "success" messages, and "info" messages. This makes appropriate styling of the error message difficult. In addition, the name ``throwError`` seems to create confusion, implying that an error will actually be thrown (e.g. stopping execution when a user isn't logged in [0][1]), when in fact it just displays a message. Replace ``throwError`` with ``flashMessage``, and reliably include a message "type" (e.g. "error", "success", "info") every time. rename ``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its function. This commit doesn't rename the message collection (``Errors``), nor the template responsible for rendering the messages (``error_item.html``) -- that should probably still be done, but has higher likelihood of trouble for existing alternate themes and installations. [0]6ccf7d7d47/client/views/users/user_edit.js (L43)
[1]083a4c4dc4/client/views/users/user_email.js (L13)
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
// ** Handlebars helpers **
|
|
|
|
UI.registerHelper('eachWithRank', function(items, options) {
|
|
// not used, forces multiple renders
|
|
// note: cannot use this because it would delete and recreate all nodes
|
|
items.rewind();
|
|
var out = '';
|
|
items.forEach(function(item, i){
|
|
var key = 'Branch-' + i;
|
|
out = out + Spark.labelBranch(key,function(){
|
|
return options.fn(_.extend(item, {rank: i}));
|
|
});
|
|
});
|
|
return out;
|
|
});
|
|
|
|
UI.registerHelper('getSetting', function(setting, defaultArgument){
|
|
var defaultArgument = (typeof defaultArgument !== 'undefined') ? defaultArgument : '';
|
|
var setting = getSetting(setting, defaultArgument);
|
|
return setting;
|
|
});
|
|
UI.registerHelper('isLoggedIn', function() {
|
|
return !!Meteor.user();
|
|
});
|
|
UI.registerHelper('canView', function() {
|
|
return canView(Meteor.user());
|
|
});
|
|
UI.registerHelper('canPost', function() {
|
|
return canPost(Meteor.user());
|
|
});
|
|
UI.registerHelper('canComment', function() {
|
|
return canComment(Meteor.user());
|
|
});
|
|
UI.registerHelper('canUpvote', function(collection) {
|
|
return canUpvote(Meteor.user(), collection);
|
|
});
|
|
UI.registerHelper('canDownvote', function(collection) {
|
|
return canDownvote(Meteor.user(), collection);
|
|
});
|
|
UI.registerHelper('isAdmin', function(showError) {
|
|
if(isAdmin(Meteor.user())){
|
|
return true;
|
|
}else{
|
|
if((typeof showError === "string") && (showError === "true"))
|
|
flashMessage(i18n.t('Sorry, you do not have access to this page'), "error");
|
|
return false;
|
|
}
|
|
});
|
|
UI.registerHelper('canEdit', function(collectionName, item, action) {
|
|
var action = (typeof action !== 'string') ? null : action;
|
|
var collection = (typeof collectionName !== 'string') ? Posts : eval(collectionName);
|
|
// console.log(item);
|
|
// var itemId = (collectionName==="Posts") ? Session.get('selectedPostId') : Session.get('selectedCommentId');
|
|
// var item=collection.findOne(itemId);
|
|
return item && canEdit(Meteor.user(), item, action);
|
|
});
|
|
|
|
UI.registerHelper('log', function(context){
|
|
console.log(context);
|
|
});
|
|
|
|
UI.registerHelper("formatDate", function(datetime, format) {
|
|
return moment(datetime).format(format);
|
|
});
|
|
|
|
UI.registerHelper("sanitize", function(content) {
|
|
console.log('cleaning up…')
|
|
console.log(content)
|
|
return cleanUp(content);
|
|
});
|
|
|
|
UI.registerHelper('pluralize', function(count, string) {
|
|
string = count === 1 ? string : string + 's';
|
|
return i18n.t(string);
|
|
});
|