2015-05-30 15:50:48 +02:00
|
|
|
Template.headerUserBar.events({
|
2015-06-01 17:56:00 +02:00
|
|
|
'click .js-open-header-member-menu': Popup.open('memberMenu'),
|
2015-09-03 23:12:46 +02:00
|
|
|
'click .js-change-avatar': Popup.open('changeAvatar'),
|
2015-05-30 15:50:48 +02:00
|
|
|
});
|
|
|
|
|
2015-06-01 17:56:00 +02:00
|
|
|
Template.memberMenuPopup.events({
|
|
|
|
'click .js-edit-profile': Popup.open('editProfile'),
|
2016-11-19 19:02:33 +01:00
|
|
|
'click .js-change-settings': Popup.open('changeSettings'),
|
2015-06-01 17:56:00 +02:00
|
|
|
'click .js-change-avatar': Popup.open('changeAvatar'),
|
|
|
|
'click .js-change-password': Popup.open('changePassword'),
|
|
|
|
'click .js-change-language': Popup.open('changeLanguage'),
|
2016-01-05 23:26:02 +08:00
|
|
|
'click .js-edit-notification': Popup.open('editNotification'),
|
2015-09-03 23:12:46 +02:00
|
|
|
'click .js-logout'(evt) {
|
2015-06-01 17:56:00 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
AccountsTemplates.logout();
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2017-02-24 22:10:38 +08:00
|
|
|
'click .js-go-setting'() {
|
|
|
|
Popup.close();
|
|
|
|
},
|
2015-06-01 17:56:00 +02:00
|
|
|
});
|
|
|
|
|
2017-08-07 17:40:50 +09:00
|
|
|
Template.editProfilePopup.helpers({
|
|
|
|
allowEmailChange() {
|
|
|
|
return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-06-01 17:56:00 +02:00
|
|
|
Template.editProfilePopup.events({
|
2015-09-03 23:12:46 +02:00
|
|
|
submit(evt, tpl) {
|
2015-06-01 17:56:00 +02:00
|
|
|
evt.preventDefault();
|
2015-10-23 16:56:55 +02:00
|
|
|
const fullname = tpl.find('.js-profile-fullname').value.trim();
|
|
|
|
const username = tpl.find('.js-profile-username').value.trim();
|
|
|
|
const initials = tpl.find('.js-profile-initials').value.trim();
|
2017-08-07 17:40:50 +09:00
|
|
|
const email = tpl.find('.js-profile-email').value.trim();
|
|
|
|
let isChangeUserName = false;
|
|
|
|
let isChangeEmail = false;
|
2015-06-01 17:56:00 +02:00
|
|
|
Users.update(Meteor.userId(), {$set: {
|
|
|
|
'profile.fullname': fullname,
|
2015-09-03 23:12:46 +02:00
|
|
|
'profile.initials': initials,
|
2015-06-01 17:56:00 +02:00
|
|
|
}});
|
2017-08-07 17:40:50 +09:00
|
|
|
isChangeUserName = username !== Meteor.user().username;
|
|
|
|
isChangeEmail = email.toLowerCase() !== Meteor.user().emails[0].address.toLowerCase();
|
|
|
|
if (isChangeUserName && isChangeEmail) {
|
2017-11-08 11:34:05 +07:00
|
|
|
Meteor.call('setUsernameAndEmail', username, email.toLowerCase(), Meteor.userId(), function (error) {
|
2017-08-07 17:40:50 +09:00
|
|
|
const usernameMessageElement = tpl.$('.username-taken');
|
|
|
|
const emailMessageElement = tpl.$('.email-taken');
|
|
|
|
if (error) {
|
|
|
|
const errorElement = error.error;
|
|
|
|
if (errorElement === 'username-already-taken') {
|
|
|
|
usernameMessageElement.show();
|
|
|
|
emailMessageElement.hide();
|
|
|
|
} else if (errorElement === 'email-already-taken') {
|
|
|
|
usernameMessageElement.hide();
|
|
|
|
emailMessageElement.show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
usernameMessageElement.hide();
|
|
|
|
emailMessageElement.hide();
|
|
|
|
Popup.back();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (isChangeUserName) {
|
2017-11-08 11:34:05 +07:00
|
|
|
Meteor.call('setUsername', username, Meteor.userId(), function (error) {
|
2016-11-18 23:18:16 +01:00
|
|
|
const messageElement = tpl.$('.username-taken');
|
|
|
|
if (error) {
|
2016-11-18 23:23:13 +01:00
|
|
|
messageElement.show();
|
2016-11-18 23:18:16 +01:00
|
|
|
} else {
|
|
|
|
messageElement.hide();
|
|
|
|
Popup.back();
|
|
|
|
}
|
|
|
|
});
|
2017-08-07 17:40:50 +09:00
|
|
|
} else if (isChangeEmail) {
|
2017-11-08 11:34:05 +07:00
|
|
|
Meteor.call('setEmail', email.toLowerCase(), Meteor.userId(), function (error) {
|
2017-08-07 17:40:50 +09:00
|
|
|
const messageElement = tpl.$('.email-taken');
|
|
|
|
if (error) {
|
|
|
|
messageElement.show();
|
|
|
|
} else {
|
|
|
|
messageElement.hide();
|
|
|
|
Popup.back();
|
|
|
|
}
|
|
|
|
});
|
2016-11-18 23:18:16 +01:00
|
|
|
} else Popup.back();
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2015-06-01 17:56:00 +02:00
|
|
|
});
|
|
|
|
|
2016-01-05 23:26:02 +08:00
|
|
|
Template.editNotificationPopup.helpers({
|
|
|
|
hasTag(tag) {
|
|
|
|
const user = Meteor.user();
|
|
|
|
return user && user.hasTag(tag);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// we defined github like rules, see: https://github.com/settings/notifications
|
|
|
|
Template.editNotificationPopup.events({
|
|
|
|
'click .js-toggle-tag-notify-participate'() {
|
|
|
|
const user = Meteor.user();
|
|
|
|
if (user) user.toggleTag('notify-participate');
|
|
|
|
},
|
|
|
|
'click .js-toggle-tag-notify-watch'() {
|
|
|
|
const user = Meteor.user();
|
|
|
|
if (user) user.toggleTag('notify-watch');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-06-01 17:56:00 +02:00
|
|
|
// XXX For some reason the useraccounts autofocus isnt working in this case.
|
|
|
|
// See https://github.com/meteor-useraccounts/core/issues/384
|
2017-11-08 11:34:05 +07:00
|
|
|
Template.changePasswordPopup.onRendered(function () {
|
2015-06-01 17:56:00 +02:00
|
|
|
this.find('#at-field-current_password').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
Template.changeLanguagePopup.helpers({
|
2015-09-03 23:12:46 +02:00
|
|
|
languages() {
|
2017-06-18 17:21:46 +01:00
|
|
|
return _.map(TAPi18n.getLanguages(), (lang, code) => {
|
|
|
|
return {
|
|
|
|
tag: code,
|
2017-06-19 01:03:08 +01:00
|
|
|
name: lang.name === 'br' ? 'Brezhoneg' : lang.name,
|
2017-06-18 17:21:46 +01:00
|
|
|
};
|
2017-11-08 11:34:05 +07:00
|
|
|
}).sort(function (a, b) {
|
2017-06-18 17:21:46 +01:00
|
|
|
if (a.name === b.name) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return a.name > b.name ? 1 : -1;
|
|
|
|
}
|
2015-05-30 15:50:48 +02:00
|
|
|
});
|
|
|
|
},
|
2015-09-03 23:12:46 +02:00
|
|
|
|
|
|
|
isCurrentLanguage() {
|
2015-05-30 15:50:48 +02:00
|
|
|
return this.tag === TAPi18n.getLanguage();
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2015-05-30 15:50:48 +02:00
|
|
|
});
|
|
|
|
|
2015-06-01 17:56:00 +02:00
|
|
|
Template.changeLanguagePopup.events({
|
2015-09-03 23:12:46 +02:00
|
|
|
'click .js-set-language'(evt) {
|
2015-05-30 15:50:48 +02:00
|
|
|
Users.update(Meteor.userId(), {
|
|
|
|
$set: {
|
2015-09-03 23:12:46 +02:00
|
|
|
'profile.language': this.tag,
|
|
|
|
},
|
2015-05-30 15:50:48 +02:00
|
|
|
});
|
|
|
|
evt.preventDefault();
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2015-05-30 15:50:48 +02:00
|
|
|
});
|
2016-11-19 19:02:33 +01:00
|
|
|
|
|
|
|
Template.changeSettingsPopup.helpers({
|
|
|
|
hiddenSystemMessages() {
|
|
|
|
return Meteor.user().hasHiddenSystemMessages();
|
2016-11-19 19:19:24 +01:00
|
|
|
},
|
2016-11-25 21:45:11 +01:00
|
|
|
showCardsCountAt() {
|
|
|
|
return Meteor.user().getLimitToShowCardsCount();
|
|
|
|
},
|
2016-11-19 19:02:33 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Template.changeSettingsPopup.events({
|
2016-11-19 19:19:24 +01:00
|
|
|
'click .js-toggle-system-messages'() {
|
2016-11-19 19:02:33 +01:00
|
|
|
Meteor.call('toggleSystemMessages');
|
|
|
|
},
|
2016-11-25 21:45:11 +01:00
|
|
|
'click .js-apply-show-cards-at'(evt, tpl) {
|
|
|
|
evt.preventDefault();
|
2016-11-25 21:53:18 +01:00
|
|
|
const minLimit = parseInt(tpl.$('#show-cards-count-at').val(), 10);
|
2016-11-25 21:45:11 +01:00
|
|
|
if (!isNaN(minLimit)) {
|
|
|
|
Meteor.call('changeLimitToShowCardsCount', minLimit);
|
|
|
|
Popup.back();
|
|
|
|
}
|
|
|
|
},
|
2016-11-19 19:02:33 +01:00
|
|
|
});
|