Vulcan/client/templates/user_edit.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

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();
2012-10-01 13:57:52 +09:00
if(!Meteor.user()) throwError('You must be logged in.');
2012-10-01 13:59:23 +09:00
var $target=$(e.target);
2012-10-01 16:08:30 +09:00
var user=window.selectedUserId? Meteor.users.findOne(window.selectedUserId) : Meteor.user();
2012-10-01 13:08:46 +10:00
var update = {
2012-10-01 13:59:23 +09:00
"profile.name": $target.find('[name=name]').val(),
"profile.bio": $target.find('[name=bio]').val(),
"profile.email": $target.find('[name=email]').val()
2012-10-01 13:08:46 +10:00
};
// TODO: enable change email
2012-10-01 13:59:23 +09:00
var email = $target.find('[name=email]').val();
2012-10-01 13:08:46 +10: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-10-01 13:57:52 +09:00
// XXX we should do something if there is an error updating these things
2012-09-19 09:03:25 +09:00
if(old_password && new_password){
Meteor.changePassword(old_password, new_password);
}
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
}
};
Template.user_edit.profileIncomplete = function() {
2012-10-01 13:57:52 +09:00
return Meteor.user() && !this.loading && !userProfileComplete(this);
}
2012-09-19 09:03:25 +09:00
Template.user_edit.user = function(){
2012-10-01 16:08:30 +09:00
var currentUser=Meteor.user();
if(window.selectedUserId && !currentUser.loading && currentUser.isAdmin){
return Meteor.users.findOne(window.selectedUserId);
2012-09-19 09:03:25 +09:00
}else{
2012-10-01 16:08:30 +09:00
return currentUser;
2012-09-19 09:03:25 +09:00
}
2012-10-01 13:57:52 +09:00
}