2015-04-13 14:52:03 +09:00
|
|
|
Template.userAccount.helpers({
|
2015-04-25 12:39:07 +09:00
|
|
|
user: function () {
|
|
|
|
return Meteor.user();
|
|
|
|
},
|
2015-04-27 17:14:07 +09:00
|
|
|
userFields: function () {
|
|
|
|
var userDataSchema = Telescope.schemas.userData._schema;
|
|
|
|
var user = Meteor.user();
|
|
|
|
|
|
|
|
// for easier manipulation, transform schema into array of objects, each with fieldName property
|
|
|
|
userDataSchema = _.map(userDataSchema, function (value, key) {
|
|
|
|
var field = value;
|
|
|
|
field.fieldName = "telescope." + key;
|
|
|
|
return field;
|
|
|
|
});
|
|
|
|
|
|
|
|
// filter out uneditable fields and only keep "fieldName"
|
|
|
|
var fields = _.pluck(_.filter(userDataSchema, function(field){
|
2015-04-28 17:15:53 +09:00
|
|
|
return Users.can.editField(user, field, user);
|
2015-04-27 17:14:07 +09:00
|
|
|
}), "fieldName");
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
},
|
2014-12-08 20:36:46 +09:00
|
|
|
profileIncomplete : function() {
|
2015-04-20 13:57:37 +09:00
|
|
|
return this && !this.loading && !Users.userProfileComplete(this);
|
2014-12-08 20:36:46 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// Template.userAccount.events({
|
|
|
|
// 'submit #account-form': function(e){
|
|
|
|
// e.preventDefault();
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// Messages.clearSeen();
|
|
|
|
// if(!Meteor.user())
|
|
|
|
// Messages.flash(i18n.t('you_must_be_logged_in'), 'error');
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// var $target=$(e.target);
|
|
|
|
// var name = $target.find('[name=name]').val();
|
|
|
|
// var email = $target.find('[name=email]').val();
|
|
|
|
// var user = this;
|
|
|
|
// var update = {
|
|
|
|
// "profile.username": name,
|
|
|
|
// "profile.slug": Telescope.utils.slugify(name),
|
|
|
|
// "profile.bio": $target.find('[name=bio]').val(),
|
|
|
|
// "profile.city": $target.find('[name=city]').val(),
|
|
|
|
// "profile.email": email,
|
|
|
|
// "profile.twitter": $target.find('[name=twitter]').val(),
|
|
|
|
// "profile.github": $target.find('[name=github]').val(),
|
|
|
|
// "profile.site": $target.find('[name=site]').val(),
|
|
|
|
// "profile.notifications.users": $('input[name=notifications_users]:checked').length, // only actually used for admins
|
|
|
|
// "profile.notifications.posts": $('input[name=notifications_posts]:checked').length,
|
|
|
|
// "profile.notifications.comments": $('input[name=notifications_comments]:checked').length,
|
|
|
|
// "profile.notifications.replies": $('input[name=notifications_replies]:checked').length
|
|
|
|
// };
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// var old_password = $target.find('[name=old_password]').val();
|
|
|
|
// var new_password = $target.find('[name=new_password]').val();
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// if(old_password && new_password){
|
|
|
|
// Accounts.changePassword(old_password, new_password, function(error){
|
|
|
|
// // TODO: interrupt update if there's an error at this point
|
|
|
|
// if(error)
|
|
|
|
// Messages.flash(error.reason, "error");
|
|
|
|
// });
|
|
|
|
// }
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// update = Users.hooks.userEditClientCallbacks.reduce(function(result, currentFunction) {
|
|
|
|
// return currentFunction(user, result);
|
|
|
|
// }, update);
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// Meteor.users.update(user._id, {
|
|
|
|
// $set: update
|
|
|
|
// }, function(error){
|
|
|
|
// if(error){
|
|
|
|
// Messages.flash(error.reason, "error");
|
|
|
|
// } else {
|
|
|
|
// Messages.flash(i18n.t('profile_updated'), 'success');
|
|
|
|
// }
|
|
|
|
// Deps.afterFlush(function() {
|
|
|
|
// var element = $('.grid > .error');
|
|
|
|
// $('html, body').animate({scrollTop: element.offset().top});
|
|
|
|
// });
|
|
|
|
// });
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// Meteor.call('changeEmail', user._id, email);
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// }
|
2014-12-08 20:36:46 +09:00
|
|
|
|
2015-04-28 17:15:53 +09:00
|
|
|
// });
|