2012-10-19 19:20:14 +09:00
|
|
|
// ** Handlebars helpers **
|
|
|
|
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.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
|
2014-05-06 20:15:48 -07:00
|
|
|
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
|
|
|
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.registerHelper('getSetting', function(setting, defaultArgument){
|
2015-01-18 23:55:39 -08:00
|
|
|
defaultArgument = defaultArgument || '';
|
|
|
|
setting = getSetting(setting, defaultArgument);
|
2014-08-12 16:16:44 +09:00
|
|
|
return setting;
|
2013-10-14 12:14:12 +09:00
|
|
|
});
|
2014-08-12 17:11:36 +09:00
|
|
|
UI.registerHelper('isLoggedIn', function() {
|
|
|
|
return !!Meteor.user();
|
|
|
|
});
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.registerHelper('canView', function() {
|
2015-01-07 08:22:46 +01:00
|
|
|
return can.view(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.registerHelper('canPost', function() {
|
2015-01-07 08:22:46 +01:00
|
|
|
return can.post(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.registerHelper('canComment', function() {
|
2015-01-07 08:22:46 +01:00
|
|
|
return can.comment(Meteor.user());
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2014-05-09 15:55:50 +09:00
|
|
|
UI.registerHelper('isAdmin', function(showError) {
|
2015-01-18 23:55:39 -08:00
|
|
|
if (isAdmin(Meteor.user())) {
|
2012-10-19 19:20:14 +09:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-18 23:55:39 -08:00
|
|
|
if ((typeof showError === 'string') && (showError === 'true')) {
|
|
|
|
flashMessage(i18n.t('sorry_you_do_not_have_access_to_this_page'), 'error');
|
|
|
|
}
|
|
|
|
return false;
|
2012-10-19 19:20:14 +09:00
|
|
|
});
|
2015-01-07 08:22:46 +01:00
|
|
|
UI.registerHelper('canEdit', function(item) {
|
|
|
|
return can.edit(Meteor.user(), item, false);
|
2014-05-09 15:55:50 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
UI.registerHelper('log', function(context){
|
|
|
|
console.log(context);
|
2014-08-11 10:14:53 +09:00
|
|
|
});
|
|
|
|
|
2015-01-18 23:55:39 -08:00
|
|
|
UI.registerHelper('formatDate', function(datetime, format) {
|
2014-11-21 12:50:26 +09:00
|
|
|
Session.get('momentLocale'); // depend on session variable to reactively rerun the helper
|
2014-08-11 10:14:53 +09:00
|
|
|
return moment(datetime).format(format);
|
2014-08-31 16:11:48 +09:00
|
|
|
});
|
|
|
|
|
2015-01-18 23:55:39 -08:00
|
|
|
UI.registerHelper('timeAgo', function(datetime) {
|
2014-11-21 12:50:26 +09:00
|
|
|
Session.get('momentLocale'); // depend on session variable to reactively rerun the helper
|
2015-01-18 23:55:39 -08:00
|
|
|
return moment(datetime).fromNow();
|
2014-11-20 14:55:34 +09:00
|
|
|
});
|
|
|
|
|
2015-01-18 23:55:39 -08:00
|
|
|
UI.registerHelper('sanitize', function(content) {
|
|
|
|
console.log('cleaning up…');
|
|
|
|
console.log(content);
|
2014-08-31 16:11:48 +09:00
|
|
|
return cleanUp(content);
|
2014-09-15 12:42:17 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
UI.registerHelper('pluralize', function(count, string) {
|
|
|
|
string = count === 1 ? string : string + 's';
|
|
|
|
return i18n.t(string);
|
Replace "throwError" with "flashMessage" and type
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] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
});
|
2014-12-14 15:15:34 +09:00
|
|
|
|
2015-01-18 23:55:39 -08:00
|
|
|
UI.registerHelper('profileUrl', function(userOrUserId) {
|
|
|
|
var user = (typeof userOrUserId === 'string') ? Meteor.users.findOne(userOrUserId) : userOrUserId;
|
|
|
|
if (!!user) {
|
2014-12-14 15:15:34 +09:00
|
|
|
return getProfileUrl(user);
|
2015-01-18 23:55:39 -08:00
|
|
|
}
|
2014-12-14 15:15:34 +09:00
|
|
|
});
|
|
|
|
|
2015-01-18 23:55:39 -08:00
|
|
|
UI.registerHelper('userName', function(userOrUserId) {
|
|
|
|
var user = (typeof userOrUserId === 'string') ? Meteor.users.findOne(userOrUserId) : userOrUserId;
|
|
|
|
if (!!user) {
|
2014-12-14 15:15:34 +09:00
|
|
|
return getUserName(user);
|
2015-01-18 23:55:39 -08:00
|
|
|
}
|
2015-02-03 10:22:42 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
UI.registerHelper('displayName', function(userOrUserId) {
|
|
|
|
var user = (typeof userOrUserId === 'string') ? Meteor.users.findOne(userOrUserId) : userOrUserId;
|
|
|
|
if (!!user) {
|
|
|
|
return getDisplayName(user);
|
|
|
|
}
|
2014-12-14 15:15:34 +09:00
|
|
|
});
|