Vulcan/client/views/users/user_edit.js

78 lines
2.4 KiB
JavaScript
Raw Normal View History

Template.user_edit.helpers({
profileIncomplete : function() {
2013-10-09 20:50:26 +09:00
return this && !this.loading && !userProfileComplete(this);
},
userName: function(){
return getUserName(this);
},
userEmail : function(){
2013-10-09 20:50:26 +09:00
return getEmail(this);
},
getTwitter: function(){
return getTwitterName(this) || "";
},
getGitHub: function(){
return getGitHubName(this) || "";
},
2013-10-24 11:15:07 +09:00
profileUrl: function(){
return Meteor.absoluteUrl()+"users/"+this.slug;
2013-10-24 11:15:07 +09:00
},
2013-10-23 10:21:08 +08:00
hasNotificationsPosts : function(){
return getUserSetting('notifications.posts') ? 'checked' : '';
},
2013-10-23 10:21:08 +08:00
hasNotificationsComments : function(){
return getUserSetting('notifications.comments') ? 'checked' : '';
},
2013-10-23 10:21:08 +08:00
hasNotificationsReplies : function(){
return getUserSetting('notifications.replies') ? 'checked' : '';
}
})
2012-09-19 09:03:25 +09:00
Template.user_edit.events = {
2012-10-01 13:08:46 +10:00
'submit form': function(e){
2012-09-19 09:03:25 +09:00
e.preventDefault();
2013-10-09 20:50:26 +09:00
if(!Meteor.user())
throwError('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(),
"profile.email": $target.find('[name=email]').val(),
"profile.twitter": $target.find('[name=twitter]').val(),
"profile.github": $target.find('[name=github]').val(),
"profile.site": $target.find('[name=site]').val(),
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,
"invitesCount": parseInt($target.find('[name=invitesCount]').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
}
2012-10-01 13:08:46 +10:00
Meteor.users.update(user._id, {
$set: update
}, function(error){
if(error){
throwError(error.reason);
} else {
throwError('Profile updated');
}
});
2012-09-19 09:03:25 +09:00
}
};