Vulcan/client/views/users/user_edit.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-07-05 11:24:28 +09:00
Template[getTemplate('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
},
hasNotificationsUsers : function(){
return getUserSetting('notifications.users', '', this) ? 'checked' : '';
},
2013-10-23 10:21:08 +08:00
hasNotificationsPosts : function(){
return getUserSetting('notifications.posts', '', this) ? 'checked' : '';
},
2013-10-23 10:21:08 +08:00
hasNotificationsComments : function(){
return getUserSetting('notifications.comments', '', this) ? 'checked' : '';
},
2013-10-23 10:21:08 +08:00
hasNotificationsReplies : function(){
return getUserSetting('notifications.replies', '', this) ? 'checked' : '';
},
hasPassword: function () {
return hasPassword(Meteor.user());
}
});
2014-07-05 11:24:28 +09:00
Template[getTemplate('user_edit')].events({
'submit #account-form': function(e){
e.preventDefault();
2013-10-09 20:50:26 +09: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(),
"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(),
"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,
"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
}
2012-10-01 13:08:46 +10:00
Meteor.users.update(user._id, {
$set: update
}, function(error){
if(error){
throwError(error.reason);
} else {
throwError(i18n.t('Profile updated'));
2012-10-01 13:08:46 +10:00
}
Deps.afterFlush(function() {
var element = $('.grid > .error');
$('html, body').animate({scrollTop: element.offset().top});
});
2012-10-01 13:08:46 +10:00
});
Meteor.call('setEmailHash', user);
2012-09-19 09:03:25 +09:00
}
});