2012-10-01 14:52:32 +09:00
|
|
|
Template.user_email.events = {
|
2012-10-01 13:57:52 +09:00
|
|
|
'submit form': function(e){
|
|
|
|
e.preventDefault();
|
2013-11-06 01:01:56 +01:00
|
|
|
if(!Meteor.user()) throwError(i18n.t('You must be logged in.'));
|
2012-10-01 13:59:23 +09:00
|
|
|
var $target=$(e.target);
|
2012-10-11 08:23:52 +09:00
|
|
|
var user=Session.get('selectedUserId')? Meteor.users.findOne(Session.get('selectedUserId')) : Meteor.user();
|
2012-10-01 13:57:52 +09:00
|
|
|
var update = {
|
2012-10-01 13:59:23 +09:00
|
|
|
"profile.email": $target.find('[name=email]').val()
|
2012-10-01 13:57:52 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: enable change email
|
2012-10-01 13:59:23 +09:00
|
|
|
var email = $target.find('[name=email]').val();
|
2012-10-01 13:57:52 +09: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('Thanks for signing up!'));
|
2013-10-05 11:43:07 +09:00
|
|
|
Meteor.call('addCurrentUserToMailChimpList');
|
2012-10-01 14:52:32 +09:00
|
|
|
trackEvent("new sign-up", {'userId': user._id, 'auth':'twitter'});
|
2013-10-09 21:49:02 +09:00
|
|
|
Router.go('/');
|
2012-10-01 13:57:52 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-10-01 14:52:32 +09:00
|
|
|
Template.user_email.profileIncomplete = function() {
|
2012-10-01 13:57:52 +09:00
|
|
|
return Meteor.user() && !this.loading && !userProfileComplete(this);
|
|
|
|
}
|
|
|
|
|
2012-10-01 14:52:32 +09:00
|
|
|
Template.user_email.user = function(){
|
2012-10-01 13:57:52 +09:00
|
|
|
var current_user=Meteor.user();
|
2012-10-11 08:23:52 +09:00
|
|
|
if(Session.get('selectedUserId') && !current_user.loading && current_user.isAdmin){
|
|
|
|
return Meteor.users.findOne(Session.get('selectedUserId'));
|
2012-10-01 13:57:52 +09:00
|
|
|
}else{
|
|
|
|
return current_user;
|
|
|
|
}
|
|
|
|
}
|