wekan/client/components/settings/settingBody.js

399 lines
11 KiB
JavaScript
Raw Normal View History

BlazeComponent.extendComponent({
onCreated() {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.generalSetting = new ReactiveVar(true);
this.emailSetting = new ReactiveVar(false);
this.accountSetting = new ReactiveVar(false);
2017-10-01 12:43:15 +09:00
this.announcementSetting = new ReactiveVar(false);
this.layoutSetting = new ReactiveVar(false);
this.webhookSetting = new ReactiveVar(false);
Meteor.subscribe('setting');
Meteor.subscribe('mailServer');
Meteor.subscribe('accountSettings');
Meteor.subscribe('announcements');
Meteor.subscribe('globalwebhooks');
},
setError(error) {
this.error.set(error);
},
setLoading(w) {
this.loading.set(w);
},
checkField(selector) {
const value = $(selector).val();
if (!value || value.trim() === '') {
2019-06-28 12:52:09 -05:00
$(selector)
.parents('li.smtp-form')
.addClass('has-error');
throw Error('blank field');
} else {
return value;
}
},
currentSetting() {
return Settings.findOne();
},
boards() {
2019-06-28 12:52:09 -05:00
return Boards.find(
{
archived: false,
'members.userId': Meteor.userId(),
'members.isAdmin': true,
},
{
sort: { sort: 1 /* boards default sorting */ },
2019-06-28 12:52:09 -05:00
},
);
},
toggleRegistration() {
this.setLoading(true);
const registrationClosed = this.currentSetting().disableRegistration;
2019-06-28 12:52:09 -05:00
Settings.update(Settings.findOne()._id, {
$set: { disableRegistration: !registrationClosed },
});
this.setLoading(false);
if (registrationClosed) {
$('.invite-people').slideUp();
} else {
$('.invite-people').slideDown();
}
},
toggleTLS() {
$('#mail-server-tls').toggleClass('is-checked');
},
toggleHideLogo() {
$('#hide-logo').toggleClass('is-checked');
},
2019-02-01 19:00:44 +01:00
toggleDisplayAuthenticationMethod() {
$('#display-authentication-method').toggleClass('is-checked');
},
switchMenu(event) {
const target = $(event.target);
if (!target.hasClass('active')) {
$('.side-menu li.active').removeClass('active');
target.parent().addClass('active');
const targetID = target.data('id');
this.generalSetting.set('registration-setting' === targetID);
this.emailSetting.set('email-setting' === targetID);
this.accountSetting.set('account-setting' === targetID);
2017-10-01 12:43:15 +09:00
this.announcementSetting.set('announcement-setting' === targetID);
this.layoutSetting.set('layout-setting' === targetID);
this.webhookSetting.set('webhook-setting' === targetID);
}
},
checkBoard(event) {
let target = $(event.target);
if (!target.hasClass('js-toggle-board-choose')) {
target = target.parent();
}
const checkboxId = target.attr('id');
$(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');
$(`#${checkboxId}`).toggleClass('is-checked');
},
inviteThroughEmail() {
2019-06-28 12:52:09 -05:00
const emails = $('#email-to-invite')
.val()
.toLowerCase()
.trim()
.split('\n')
.join(',')
.split(',');
const boardsToInvite = [];
2019-06-28 12:52:09 -05:00
$('.js-toggle-board-choose .materialCheckBox.is-checked').each(function() {
boardsToInvite.push($(this).data('id'));
});
const validEmails = [];
2019-06-28 12:52:09 -05:00
emails.forEach(email => {
if (email && SimpleSchema.RegEx.Email.test(email.trim())) {
validEmails.push(email.trim());
}
});
if (validEmails.length) {
this.setLoading(true);
Meteor.call('sendInvitation', validEmails, boardsToInvite, () => {
// if (!err) {
// TODO - show more info to user
// }
this.setLoading(false);
});
}
},
saveMailServerInfo() {
this.setLoading(true);
$('li').removeClass('has-error');
try {
const host = this.checkField('#mail-server-host');
const port = this.checkField('#mail-server-port');
2019-06-28 12:52:09 -05:00
const username = $('#mail-server-username')
.val()
.trim();
const password = $('#mail-server-password')
.val()
.trim();
const from = this.checkField('#mail-server-from');
const tls = $('#mail-server-tls.is-checked').length > 0;
Settings.update(Settings.findOne()._id, {
$set: {
2019-06-28 12:52:09 -05:00
'mailServer.host': host,
'mailServer.port': port,
'mailServer.username': username,
'mailServer.password': password,
'mailServer.enableTLS': tls,
'mailServer.from': from,
},
});
} catch (e) {
return;
} finally {
this.setLoading(false);
}
},
saveLayout() {
this.setLoading(true);
$('li').removeClass('has-error');
2019-06-28 12:52:09 -05:00
const productName = $('#product-name')
.val()
.trim();
const customLoginLogoImageUrl = $('#custom-login-logo-image-url')
.val()
.trim();
const customLoginLogoLinkUrl = $('#custom-login-logo-link-url')
.val()
.trim();
const textBelowCustomLoginLogo = $('#text-below-custom-login-logo')
.val()
.trim();
2021-03-04 16:38:47 +01:00
const automaticLinkedUrlSchemes = $('#automatic-linked-url-schemes')
.val()
.trim();
const customTopLeftCornerLogoImageUrl = $(
'#custom-top-left-corner-logo-image-url',
)
.val()
.trim();
const customTopLeftCornerLogoLinkUrl = $(
'#custom-top-left-corner-logo-link-url',
)
.val()
.trim();
const customTopLeftCornerLogoHeight = $(
'#custom-top-left-corner-logo-height',
)
.val()
.trim();
2019-06-28 12:52:09 -05:00
const hideLogoChange = $('input[name=hideLogo]:checked').val() === 'true';
const displayAuthenticationMethod =
$('input[name=displayAuthenticationMethod]:checked').val() === 'true';
2019-02-01 19:00:44 +01:00
const defaultAuthenticationMethod = $('#defaultAuthenticationMethod').val();
const spinnerName = $('#spinnerName').val();
try {
Settings.update(Settings.findOne()._id, {
$set: {
2018-10-24 12:13:20 +03:00
productName,
hideLogo: hideLogoChange,
customLoginLogoImageUrl,
customLoginLogoLinkUrl,
textBelowCustomLoginLogo,
customTopLeftCornerLogoImageUrl,
customTopLeftCornerLogoLinkUrl,
customTopLeftCornerLogoHeight,
2019-02-01 19:00:44 +01:00
displayAuthenticationMethod,
2019-02-01 21:26:04 +02:00
defaultAuthenticationMethod,
2021-03-04 16:38:47 +01:00
automaticLinkedUrlSchemes,
spinnerName,
},
});
} catch (e) {
return;
} finally {
this.setLoading(false);
}
DocHead.setTitle(productName);
},
2017-11-27 16:44:19 +09:00
sendSMTPTestEmail() {
Meteor.call('sendSMTPTestEmail', (err, ret) => {
2019-02-01 21:26:04 +02:00
if (!err && ret) {
2017-11-28 13:26:46 +09:00
const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
alert(message);
2017-11-27 16:44:19 +09:00
} else {
2017-11-28 13:26:46 +09:00
const reason = err.reason || '';
const message = `${TAPi18n.__(err.error)}\n${reason}`;
alert(message);
}
2017-11-27 16:44:19 +09:00
});
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click a.js-toggle-registration': this.toggleRegistration,
'click a.js-toggle-tls': this.toggleTLS,
'click a.js-setting-menu': this.switchMenu,
'click a.js-toggle-board-choose': this.checkBoard,
'click button.js-email-invite': this.inviteThroughEmail,
'click button.js-save': this.saveMailServerInfo,
'click button.js-send-smtp-test-email': this.sendSMTPTestEmail,
'click a.js-toggle-hide-logo': this.toggleHideLogo,
'click button.js-save-layout': this.saveLayout,
'click a.js-toggle-display-authentication-method': this
.toggleDisplayAuthenticationMethod,
},
];
},
}).register('setting');
BlazeComponent.extendComponent({
saveAccountsChange() {
2019-06-28 12:52:09 -05:00
const allowEmailChange =
$('input[name=allowEmailChange]:checked').val() === 'true';
const allowUserNameChange =
$('input[name=allowUserNameChange]:checked').val() === 'true';
const allowUserDelete =
$('input[name=allowUserDelete]:checked').val() === 'true';
AccountSettings.update('accounts-allowEmailChange', {
2019-06-28 12:52:09 -05:00
$set: { booleanValue: allowEmailChange },
});
AccountSettings.update('accounts-allowUserNameChange', {
2019-06-28 12:52:09 -05:00
$set: { booleanValue: allowUserNameChange },
});
AccountSettings.update('accounts-allowUserDelete', {
$set: { booleanValue: allowUserDelete },
});
},
allowEmailChange() {
return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
},
allowUserNameChange() {
return AccountSettings.findOne('accounts-allowUserNameChange').booleanValue;
},
allowUserDelete() {
return AccountSettings.findOne('accounts-allowUserDelete').booleanValue;
},
allHideSystemMessages() {
Meteor.call('setAllUsersHideSystemMessages', (err, ret) => {
if (!err && ret) {
if (ret === true) {
const message = `${TAPi18n.__(
'now-system-messages-of-all-users-are-hidden',
)}`;
alert(message);
}
} else {
const reason = err.reason || '';
const message = `${TAPi18n.__(err.error)}\n${reason}`;
alert(message);
}
});
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click button.js-accounts-save': this.saveAccountsChange,
},
{
'click button.js-all-hide-system-messages': this.allHideSystemMessages,
},
2019-06-28 12:52:09 -05:00
];
},
}).register('accountSettings');
2017-09-28 16:57:04 +09:00
BlazeComponent.extendComponent({
onCreated() {
this.loading = new ReactiveVar(false);
},
setLoading(w) {
this.loading.set(w);
},
currentSetting() {
2017-10-01 12:43:15 +09:00
return Announcements.findOne();
2017-09-28 16:57:04 +09:00
},
saveMessage() {
2019-06-28 12:52:09 -05:00
const message = $('#admin-announcement')
.val()
.trim();
2017-10-01 12:43:15 +09:00
Announcements.update(Announcements.findOne()._id, {
2019-06-28 12:52:09 -05:00
$set: { body: message },
2017-09-28 16:57:04 +09:00
});
},
toggleActive() {
2017-09-28 16:57:04 +09:00
this.setLoading(true);
const isActive = this.currentSetting().enabled;
2017-10-01 12:43:15 +09:00
Announcements.update(Announcements.findOne()._id, {
2019-06-28 12:52:09 -05:00
$set: { enabled: !isActive },
2017-09-28 16:57:04 +09:00
});
this.setLoading(false);
if (isActive) {
2017-10-01 12:43:15 +09:00
$('.admin-announcement').slideUp();
} else {
2017-10-01 12:43:15 +09:00
$('.admin-announcement').slideDown();
2017-09-28 16:57:04 +09:00
}
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click a.js-toggle-activemessage': this.toggleActive,
'click button.js-announcement-save': this.saveMessage,
},
];
2017-09-28 16:57:04 +09:00
},
2017-10-01 12:43:15 +09:00
}).register('announcementSettings');
2019-02-01 19:00:44 +01:00
Template.selectAuthenticationMethod.onCreated(function() {
this.authenticationMethods = new ReactiveVar([]);
Meteor.call('getAuthenticationsEnabled', (_, result) => {
if (result) {
// TODO : add a management of different languages
// (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
this.authenticationMethods.set([
2019-06-28 12:52:09 -05:00
{ value: 'password' },
2019-02-01 19:00:44 +01:00
// Gets only the authentication methods availables
2019-06-28 12:52:09 -05:00
...Object.entries(result)
.filter(e => e[1])
.map(e => ({ value: e[0] })),
2019-02-01 19:00:44 +01:00
]);
}
});
});
Template.selectAuthenticationMethod.helpers({
authentications() {
return Template.instance().authenticationMethods.get();
},
isSelected(match) {
return Template.instance().data.authenticationMethod === match;
2019-02-01 21:26:04 +02:00
},
});
Template.selectSpinnerName.helpers({
spinners() {
return ['Bounce', 'Wave']
},
isSelected(match) {
return Template.instance().data.spinnerName === match;
},
});