Vulcan/packages/telescope-users/lib/client/templates/profile/user_info.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

Template.user_info.helpers({
2014-12-08 14:53:26 +09:00
canEditProfile: function() {
var currentUser = Meteor.user();
return currentUser && (this._id === currentUser._id || Users.is.admin(currentUser));
2014-12-08 14:53:26 +09:00
},
createdAtFormatted: function() {
return this.createdAt;
},
canInvite: function() {
// if the user is logged in, the target user hasn't been invited yet, invites are enabled, and user is not viewing their own profile
return Meteor.user() && Meteor.user()._id !== this._id && !Users.is.invited(this) && Telescope.utils.invitesEnabled() && Users.can.invite(Meteor.user());
2014-12-08 14:53:26 +09:00
},
inviteCount: function() {
return Meteor.user().telescope.inviteCount;
2014-12-08 14:53:26 +09:00
},
getTwitterName: function () {
return Users.getTwitterName(this);
2014-12-08 14:53:26 +09:00
},
getGitHubName: function () {
return Users.getGitHubName(this);
},
publicProfileFields: function () {
var user = this;
var schema = Users.simpleSchema();
var publicData = _.compact(_.map(schema.getPublicFields(), function (fieldName) {
if (Telescope.getNestedProperty(user, fieldName)) {
var field = schema._schema[fieldName];
var item = {
label: i18n.t(fieldName.replace("telescope.", "")),
value: Telescope.getNestedProperty(user, fieldName)
};
if (!!field.template) {
item.template = field.template;
}
return item;
}
}));
return publicData;
2014-12-08 14:53:26 +09:00
}
});
Template.user_info.events({
2014-12-08 14:53:26 +09:00
'click .invite-link': function(e, instance){
Meteor.call('inviteUser', instance.data.user._id);
2015-03-27 16:24:21 +08:00
Messages.flash('Thanks, user has been invited.', "success");
2014-12-08 14:53:26 +09:00
}
});