2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_edit')].helpers({
|
2013-01-19 18:24:18 +09:00
|
|
|
profileIncomplete : function() {
|
2013-10-09 20:50:26 +09:00
|
|
|
return this && !this.loading && !userProfileComplete(this);
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-24 14:24:03 +09:00
|
|
|
userName: function(){
|
|
|
|
return getUserName(this);
|
|
|
|
},
|
2013-02-22 15:41:15 +09:00
|
|
|
userEmail : function(){
|
2013-10-09 20:50:26 +09:00
|
|
|
return getEmail(this);
|
2013-02-22 15:41:15 +09:00
|
|
|
},
|
2013-11-07 09:57:57 +09:00
|
|
|
getTwitter: function(){
|
2013-11-11 22:09:24 +02:00
|
|
|
return getTwitterName(this) || "";
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
|
|
|
getGitHub: function(){
|
2013-11-11 22:09:24 +02:00
|
|
|
return getGitHubName(this) || "";
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
2013-10-24 11:15:07 +09:00
|
|
|
profileUrl: function(){
|
2013-10-24 14:24:03 +09:00
|
|
|
return Meteor.absoluteUrl()+"users/"+this.slug;
|
2013-10-24 11:15:07 +09:00
|
|
|
},
|
2013-11-18 11:30:58 +09:00
|
|
|
hasNotificationsUsers : function(){
|
|
|
|
return getUserSetting('notifications.users', '', this) ? 'checked' : '';
|
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsPosts : function(){
|
2014-02-03 18:25:09 +00:00
|
|
|
return getUserSetting('notifications.posts', '', this) ? 'checked' : '';
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsComments : function(){
|
2013-11-18 11:30:58 +09:00
|
|
|
return getUserSetting('notifications.comments', '', this) ? 'checked' : '';
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsReplies : function(){
|
2013-11-18 11:30:58 +09:00
|
|
|
return getUserSetting('notifications.replies', '', this) ? 'checked' : '';
|
2014-06-22 13:20:10 +09:00
|
|
|
},
|
|
|
|
hasPassword: function () {
|
|
|
|
return hasPassword(Meteor.user());
|
2013-01-19 18:24:18 +09:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_edit')].events({
|
2012-10-01 13:08:46 +10:00
|
|
|
'submit form': function(e){
|
2014-01-06 02:30:59 +02:00
|
|
|
e.preventDefault();
|
2013-10-09 20:50:26 +09:00
|
|
|
|
2014-01-06 02:30:59 +02:00
|
|
|
clearSeenErrors();
|
2013-10-09 20:50:26 +09:00
|
|
|
if(!Meteor.user())
|
2013-11-09 02:02:05 +01:00
|
|
|
throwError(i18n.t('You must be logged in.'));
|
|
|
|
|
2012-10-01 13:59:23 +09:00
|
|
|
var $target=$(e.target);
|
2013-10-24 11:15:07 +09:00
|
|
|
var name = $target.find('[name=name]').val();
|
2013-10-09 20:50:26 +09:00
|
|
|
var user = this;
|
2012-10-01 13:08:46 +10:00
|
|
|
var update = {
|
2013-10-24 11:15:07 +09:00
|
|
|
"profile.name": name,
|
|
|
|
"profile.slug": slugify(name),
|
2012-10-01 13:59:23 +09:00
|
|
|
"profile.bio": $target.find('[name=bio]').val(),
|
2013-01-19 18:24:18 +09:00
|
|
|
"profile.email": $target.find('[name=email]').val(),
|
2013-11-07 09:57:57 +09:00
|
|
|
"profile.twitter": $target.find('[name=twitter]').val(),
|
|
|
|
"profile.github": $target.find('[name=github]').val(),
|
|
|
|
"profile.site": $target.find('[name=site]').val(),
|
2013-11-18 11:30:58 +09:00
|
|
|
"profile.notifications.users": $('input[name=notifications_users]:checked').length, // only actually used for admins
|
2013-10-23 10:21:08 +08:00
|
|
|
"profile.notifications.posts": $('input[name=notifications_posts]:checked').length,
|
|
|
|
"profile.notifications.comments": $('input[name=notifications_comments]:checked').length,
|
2013-10-23 19:43:42 +09:00
|
|
|
"profile.notifications.replies": $('input[name=notifications_replies]:checked').length,
|
2013-11-14 10:49:37 +09:00
|
|
|
"inviteCount": parseInt($target.find('[name=inviteCount]').val())
|
2012-10-01 13:08:46 +10:00
|
|
|
};
|
2013-10-23 19:43:42 +09:00
|
|
|
|
2012-10-01 13:57:52 +09:00
|
|
|
var old_password = $target.find('[name=old_password]').val();
|
|
|
|
var new_password = $target.find('[name=new_password]').val();
|
2012-10-01 13:08:46 +10:00
|
|
|
|
2012-09-19 09:03:25 +09:00
|
|
|
if(old_password && new_password){
|
2013-10-21 19:01:52 +08:00
|
|
|
Accounts.changePassword(old_password, new_password, function(error){
|
|
|
|
// TODO: interrupt update if there's an error at this point
|
|
|
|
if(error)
|
|
|
|
throwError(error.reason);
|
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
2014-02-03 18:25:09 +00:00
|
|
|
|
2012-10-01 13:08:46 +10:00
|
|
|
Meteor.users.update(user._id, {
|
|
|
|
$set: update
|
|
|
|
}, function(error){
|
|
|
|
if(error){
|
|
|
|
throwError(error.reason);
|
|
|
|
} else {
|
2013-11-06 01:01:56 +01:00
|
|
|
throwError(i18n.t('Profile updated'));
|
2012-10-01 13:08:46 +10:00
|
|
|
}
|
2014-01-06 02:30:59 +02:00
|
|
|
Deps.afterFlush(function() {
|
|
|
|
var element = $('.grid > .error');
|
|
|
|
$('html, body').animate({scrollTop: element.offset().top});
|
|
|
|
});
|
2012-10-01 13:08:46 +10:00
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
|
|
|
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|