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(){
|
2014-12-03 00:06:00 -08:00
|
|
|
return getProfileUrlBySlugOrId(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-09-16 15:18:27 -04:00
|
|
|
});
|
2013-01-19 18:24:18 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_edit')].events({
|
2014-07-31 01:19:26 +02:00
|
|
|
'submit #account-form': function(e){
|
2014-01-06 02:30:59 +02:00
|
|
|
e.preventDefault();
|
2013-10-09 20:50:26 +09:00
|
|
|
|
2014-12-06 17:41:15 +09:00
|
|
|
clearSeenMessages();
|
2013-10-09 20:50:26 +09:00
|
|
|
if(!Meteor.user())
|
2014-12-06 17:34:08 +09:00
|
|
|
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
|
2013-11-09 02:02:05 +01:00
|
|
|
|
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();
|
2014-10-15 16:48:04 -05:00
|
|
|
var email = $target.find('[name=email]').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(),
|
2014-10-15 16:48:04 -05:00
|
|
|
"profile.email": email,
|
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,
|
2014-09-26 09:40:55 +09:00
|
|
|
"profile.notifications.replies": $('input[name=notifications_replies]:checked').length
|
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)
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage(error.reason, "error");
|
2013-10-21 19:01:52 +08:00
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
2014-02-03 18:25:09 +00:00
|
|
|
|
2014-11-17 17:11:13 -07:00
|
|
|
update = userEditClientCallbacks.reduce(function(result, currentFunction) {
|
|
|
|
return currentFunction(user, result);
|
|
|
|
}, update);
|
|
|
|
|
2012-10-01 13:08:46 +10:00
|
|
|
Meteor.users.update(user._id, {
|
|
|
|
$set: update
|
|
|
|
}, function(error){
|
|
|
|
if(error){
|
2014-11-17 17:00:21 -07:00
|
|
|
flashMessage(error.reason, "error");
|
2012-10-01 13:08:46 +10:00
|
|
|
} else {
|
2014-12-06 17:34:08 +09:00
|
|
|
flashMessage(i18n.t('profile_updated'), 'success');
|
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
|
|
|
});
|
2014-09-12 11:54:04 +09:00
|
|
|
|
2014-10-15 16:48:04 -05:00
|
|
|
Meteor.call('changeEmail', email);
|
2014-09-12 11:54:04 +09:00
|
|
|
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
|
|
|
|
2014-10-06 17:11:43 -06:00
|
|
|
});
|