2017-02-24 22:10:38 +08:00
|
|
|
BlazeComponent.extendComponent({
|
|
|
|
onCreated() {
|
|
|
|
this.error = new ReactiveVar('');
|
|
|
|
this.loading = new ReactiveVar(false);
|
|
|
|
this.generalSetting = new ReactiveVar(true);
|
|
|
|
this.emailSetting = new ReactiveVar(false);
|
2017-08-07 17:40:50 +09:00
|
|
|
this.accountSetting = new ReactiveVar(false);
|
2017-10-01 12:43:15 +09:00
|
|
|
this.announcementSetting = new ReactiveVar(false);
|
2018-10-24 11:39:45 +03:00
|
|
|
this.layoutSetting = new ReactiveVar(false);
|
2017-12-02 22:00:42 +02:00
|
|
|
|
|
|
|
Meteor.subscribe('setting');
|
|
|
|
Meteor.subscribe('mailServer');
|
|
|
|
Meteor.subscribe('accountSettings');
|
|
|
|
Meteor.subscribe('announcements');
|
2017-02-24 22:10:38 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
setError(error) {
|
|
|
|
this.error.set(error);
|
|
|
|
},
|
|
|
|
|
|
|
|
setLoading(w) {
|
|
|
|
this.loading.set(w);
|
|
|
|
},
|
2018-08-20 23:16:24 +03:00
|
|
|
|
2017-02-24 22:10:38 +08:00
|
|
|
checkField(selector) {
|
|
|
|
const value = $(selector).val();
|
2018-05-04 16:44:50 -03:00
|
|
|
if (!value || value.trim() === '') {
|
2017-02-24 22:10:38 +08:00
|
|
|
$(selector).parents('li.smtp-form').addClass('has-error');
|
|
|
|
throw Error('blank field');
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
},
|
2018-08-20 23:16:24 +03:00
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
currentSetting() {
|
2017-02-24 22:10:38 +08:00
|
|
|
return Settings.findOne();
|
|
|
|
},
|
|
|
|
|
|
|
|
boards() {
|
|
|
|
return Boards.find({
|
|
|
|
archived: false,
|
|
|
|
'members.userId': Meteor.userId(),
|
|
|
|
'members.isAdmin': true,
|
|
|
|
}, {
|
|
|
|
sort: ['title'],
|
|
|
|
});
|
|
|
|
},
|
2018-05-04 16:44:50 -03:00
|
|
|
toggleRegistration() {
|
2017-02-24 22:10:38 +08:00
|
|
|
this.setLoading(true);
|
2017-02-26 21:11:15 +08:00
|
|
|
const registrationClosed = this.currentSetting().disableRegistration;
|
2018-05-04 16:44:50 -03:00
|
|
|
Settings.update(Settings.findOne()._id, {$set: {disableRegistration: !registrationClosed}});
|
2017-02-24 22:10:38 +08:00
|
|
|
this.setLoading(false);
|
2018-05-04 16:44:50 -03:00
|
|
|
if (registrationClosed) {
|
2017-02-24 22:10:38 +08:00
|
|
|
$('.invite-people').slideUp();
|
2018-05-04 16:44:50 -03:00
|
|
|
} else {
|
2017-02-24 22:10:38 +08:00
|
|
|
$('.invite-people').slideDown();
|
|
|
|
}
|
|
|
|
},
|
2018-05-04 16:44:50 -03:00
|
|
|
toggleTLS() {
|
2017-03-30 19:13:57 +02:00
|
|
|
$('#mail-server-tls').toggleClass('is-checked');
|
|
|
|
},
|
2018-11-20 02:38:00 +02:00
|
|
|
toggleHideLogo() {
|
|
|
|
$('#hide-logo').toggleClass('is-checked');
|
|
|
|
},
|
2018-05-04 16:44:50 -03:00
|
|
|
switchMenu(event) {
|
2017-02-24 22:10:38 +08:00
|
|
|
const target = $(event.target);
|
2018-05-04 16:44:50 -03:00
|
|
|
if (!target.hasClass('active')) {
|
2017-02-24 22:10:38 +08:00
|
|
|
$('.side-menu li.active').removeClass('active');
|
|
|
|
target.parent().addClass('active');
|
|
|
|
const targetID = target.data('id');
|
2017-02-26 21:11:15 +08:00
|
|
|
this.generalSetting.set('registration-setting' === targetID);
|
2017-02-24 22:10:38 +08:00
|
|
|
this.emailSetting.set('email-setting' === targetID);
|
2017-08-07 17:40:50 +09:00
|
|
|
this.accountSetting.set('account-setting' === targetID);
|
2017-10-01 12:43:15 +09:00
|
|
|
this.announcementSetting.set('announcement-setting' === targetID);
|
2018-10-24 11:39:45 +03:00
|
|
|
this.layoutSetting.set('layout-setting' === targetID);
|
2017-02-24 22:10:38 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
checkBoard(event) {
|
2017-02-24 22:10:38 +08:00
|
|
|
let target = $(event.target);
|
2018-05-04 16:44:50 -03:00
|
|
|
if (!target.hasClass('js-toggle-board-choose')) {
|
2017-02-24 22:10:38 +08:00
|
|
|
target = target.parent();
|
|
|
|
}
|
|
|
|
const checkboxId = target.attr('id');
|
|
|
|
$(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');
|
|
|
|
$(`#${checkboxId}`).toggleClass('is-checked');
|
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
inviteThroughEmail() {
|
2017-02-24 22:10:38 +08:00
|
|
|
const emails = $('#email-to-invite').val().trim().split('\n').join(',').split(',');
|
|
|
|
const boardsToInvite = [];
|
|
|
|
$('.js-toggle-board-choose .materialCheckBox.is-checked').each(function () {
|
|
|
|
boardsToInvite.push($(this).data('id'));
|
|
|
|
});
|
|
|
|
const validEmails = [];
|
|
|
|
emails.forEach((email) => {
|
|
|
|
if (email && SimpleSchema.RegEx.Email.test(email.trim())) {
|
|
|
|
validEmails.push(email.trim());
|
|
|
|
}
|
|
|
|
});
|
2017-02-26 21:11:15 +08:00
|
|
|
if (validEmails.length) {
|
|
|
|
this.setLoading(true);
|
|
|
|
Meteor.call('sendInvitation', validEmails, boardsToInvite, () => {
|
|
|
|
// if (!err) {
|
|
|
|
// TODO - show more info to user
|
|
|
|
// }
|
|
|
|
this.setLoading(false);
|
|
|
|
});
|
|
|
|
}
|
2017-02-24 22:10:38 +08:00
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
saveMailServerInfo() {
|
2017-02-24 22:10:38 +08:00
|
|
|
this.setLoading(true);
|
|
|
|
$('li').removeClass('has-error');
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
try {
|
2017-02-24 22:10:38 +08:00
|
|
|
const host = this.checkField('#mail-server-host');
|
|
|
|
const port = this.checkField('#mail-server-port');
|
2017-03-09 23:29:48 +08:00
|
|
|
const username = $('#mail-server-username').val().trim();
|
|
|
|
const password = $('#mail-server-password').val().trim();
|
2017-02-24 22:10:38 +08:00
|
|
|
const from = this.checkField('#mail-server-from');
|
2017-03-30 19:13:57 +02:00
|
|
|
const tls = $('#mail-server-tls.is-checked').length > 0;
|
2018-05-04 16:44:50 -03:00
|
|
|
Settings.update(Settings.findOne()._id, {
|
|
|
|
$set: {
|
|
|
|
'mailServer.host': host, 'mailServer.port': port, 'mailServer.username': username,
|
|
|
|
'mailServer.password': password, 'mailServer.enableTLS': tls, 'mailServer.from': from,
|
|
|
|
},
|
|
|
|
});
|
2017-02-24 22:10:38 +08:00
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
this.setLoading(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2018-08-20 23:16:24 +03:00
|
|
|
|
2018-10-24 11:39:45 +03:00
|
|
|
saveLayout() {
|
|
|
|
this.setLoading(true);
|
|
|
|
$('li').removeClass('has-error');
|
|
|
|
|
2018-11-20 02:38:00 +02:00
|
|
|
const productName = $('#product-name').val().trim();
|
|
|
|
const hideLogoChange = ($('input[name=hideLogo]:checked').val() === 'true');
|
|
|
|
|
2018-10-24 11:39:45 +03:00
|
|
|
try {
|
2018-11-20 02:38:00 +02:00
|
|
|
|
2018-10-24 11:39:45 +03:00
|
|
|
Settings.update(Settings.findOne()._id, {
|
|
|
|
$set: {
|
2018-10-24 12:13:20 +03:00
|
|
|
productName,
|
2018-11-20 02:38:00 +02:00
|
|
|
hideLogo: hideLogoChange,
|
2018-10-24 11:39:45 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
this.setLoading(false);
|
|
|
|
}
|
|
|
|
|
2018-11-20 11:35:14 +02:00
|
|
|
saveMailServerInfo();
|
|
|
|
|
2018-10-24 11:39:45 +03:00
|
|
|
},
|
|
|
|
|
2017-11-27 16:44:19 +09:00
|
|
|
sendSMTPTestEmail() {
|
|
|
|
Meteor.call('sendSMTPTestEmail', (err, ret) => {
|
|
|
|
if (!err && ret) { /* eslint-disable no-console */
|
2017-11-28 13:26:46 +09:00
|
|
|
const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
|
|
|
|
console.log(message);
|
|
|
|
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}`;
|
|
|
|
console.log(message, err);
|
|
|
|
alert(message);
|
2018-05-04 16:44:50 -03:00
|
|
|
}
|
|
|
|
/* eslint-enable no-console */
|
2017-11-27 16:44:19 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
events() {
|
2017-02-24 22:10:38 +08:00
|
|
|
return [{
|
2017-02-26 21:11:15 +08:00
|
|
|
'click a.js-toggle-registration': this.toggleRegistration,
|
2017-03-30 19:13:57 +02:00
|
|
|
'click a.js-toggle-tls': this.toggleTLS,
|
2017-02-24 22:10:38 +08:00
|
|
|
'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,
|
2017-11-27 16:44:19 +09:00
|
|
|
'click button.js-send-smtp-test-email': this.sendSMTPTestEmail,
|
2018-11-20 02:38:00 +02:00
|
|
|
'click a.js-toggle-hide-logo': this.toggleHideLogo,
|
2018-10-24 11:39:45 +03:00
|
|
|
'click button.js-save-layout': this.saveLayout,
|
2017-02-24 22:10:38 +08:00
|
|
|
}];
|
|
|
|
},
|
|
|
|
}).register('setting');
|
2017-08-07 17:40:50 +09:00
|
|
|
|
|
|
|
BlazeComponent.extendComponent({
|
2018-05-04 16:44:50 -03:00
|
|
|
|
|
|
|
saveAccountsChange() {
|
2017-08-07 17:40:50 +09:00
|
|
|
const allowEmailChange = ($('input[name=allowEmailChange]:checked').val() === 'true');
|
2018-05-04 16:44:50 -03:00
|
|
|
const allowUserNameChange = ($('input[name=allowUserNameChange]:checked').val() === 'true');
|
2017-08-07 17:40:50 +09:00
|
|
|
AccountSettings.update('accounts-allowEmailChange', {
|
2018-05-04 16:44:50 -03:00
|
|
|
$set: {'booleanValue': allowEmailChange},
|
|
|
|
});
|
|
|
|
AccountSettings.update('accounts-allowUserNameChange', {
|
|
|
|
$set: {'booleanValue': allowUserNameChange},
|
2017-08-07 17:40:50 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
allowEmailChange() {
|
|
|
|
return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
|
|
|
|
},
|
2018-05-04 16:44:50 -03:00
|
|
|
allowUserNameChange() {
|
|
|
|
return AccountSettings.findOne('accounts-allowUserNameChange').booleanValue;
|
|
|
|
},
|
2017-08-07 17:40:50 +09:00
|
|
|
|
|
|
|
events() {
|
|
|
|
return [{
|
2018-05-04 16:44:50 -03:00
|
|
|
'click button.js-accounts-save': this.saveAccountsChange,
|
2017-08-07 17:40:50 +09: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);
|
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03:00
|
|
|
currentSetting() {
|
2017-10-01 12:43:15 +09:00
|
|
|
return Announcements.findOne();
|
2017-09-28 16:57:04 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
saveMessage() {
|
2017-10-01 12:43:15 +09:00
|
|
|
const message = $('#admin-announcement').val().trim();
|
|
|
|
Announcements.update(Announcements.findOne()._id, {
|
2018-05-04 16:44:50 -03:00
|
|
|
$set: {'body': message},
|
2017-09-28 16:57:04 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-05-04 16:44:50 -03: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, {
|
2018-05-04 16:44:50 -03:00
|
|
|
$set: {'enabled': !isActive},
|
2017-09-28 16:57:04 +09:00
|
|
|
});
|
|
|
|
this.setLoading(false);
|
2018-05-04 16:44:50 -03:00
|
|
|
if (isActive) {
|
2017-10-01 12:43:15 +09:00
|
|
|
$('.admin-announcement').slideUp();
|
2018-05-04 16:44:50 -03:00
|
|
|
} else {
|
2017-10-01 12:43:15 +09:00
|
|
|
$('.admin-announcement').slideDown();
|
2017-09-28 16:57:04 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
events() {
|
|
|
|
return [{
|
|
|
|
'click a.js-toggle-activemessage': this.toggleActive,
|
2017-10-01 12:43:15 +09:00
|
|
|
'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');
|