123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- 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);
- this.announcementSetting = new ReactiveVar(false);
- this.layoutSetting = new ReactiveVar(false);
- Meteor.subscribe('setting');
- Meteor.subscribe('mailServer');
- Meteor.subscribe('accountSettings');
- Meteor.subscribe('announcements');
- },
- setError(error) {
- this.error.set(error);
- },
- setLoading(w) {
- this.loading.set(w);
- },
- checkField(selector) {
- const value = $(selector).val();
- if (!value || value.trim() === '') {
- $(selector).parents('li.smtp-form').addClass('has-error');
- throw Error('blank field');
- } else {
- return value;
- }
- },
- currentSetting() {
- return Settings.findOne();
- },
- boards() {
- return Boards.find({
- archived: false,
- 'members.userId': Meteor.userId(),
- 'members.isAdmin': true,
- }, {
- sort: ['title'],
- });
- },
- toggleRegistration() {
- this.setLoading(true);
- const registrationClosed = this.currentSetting().disableRegistration;
- 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');
- },
- 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);
- this.announcementSetting.set('announcement-setting' === targetID);
- this.layoutSetting.set('layout-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() {
- 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());
- }
- });
- 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');
- 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: {
- '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');
- const productName = $('#product-name').val().trim();
- const hideLogoChange = ($('input[name=hideLogo]:checked').val() === 'true');
- try {
- Settings.update(Settings.findOne()._id, {
- $set: {
- productName,
- hideLogo: hideLogoChange,
- },
- });
- } catch (e) {
- return;
- } finally {
- this.setLoading(false);
- }
- DocHead.setTitle(productName);
- saveMailServerInfo();
- },
- sendSMTPTestEmail() {
- Meteor.call('sendSMTPTestEmail', (err, ret) => {
- if (!err && ret) { /* eslint-disable no-console */
- const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
- console.log(message);
- alert(message);
- } else {
- const reason = err.reason || '';
- const message = `${TAPi18n.__(err.error)}\n${reason}`;
- console.log(message, err);
- alert(message);
- }
- /* eslint-enable no-console */
- });
- },
- events() {
- 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,
- }];
- },
- }).register('setting');
- BlazeComponent.extendComponent({
- saveAccountsChange() {
- const allowEmailChange = ($('input[name=allowEmailChange]:checked').val() === 'true');
- const allowUserNameChange = ($('input[name=allowUserNameChange]:checked').val() === 'true');
- AccountSettings.update('accounts-allowEmailChange', {
- $set: {'booleanValue': allowEmailChange},
- });
- AccountSettings.update('accounts-allowUserNameChange', {
- $set: {'booleanValue': allowUserNameChange},
- });
- },
- allowEmailChange() {
- return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
- },
- allowUserNameChange() {
- return AccountSettings.findOne('accounts-allowUserNameChange').booleanValue;
- },
- events() {
- return [{
- 'click button.js-accounts-save': this.saveAccountsChange,
- }];
- },
- }).register('accountSettings');
- BlazeComponent.extendComponent({
- onCreated() {
- this.loading = new ReactiveVar(false);
- },
- setLoading(w) {
- this.loading.set(w);
- },
- currentSetting() {
- return Announcements.findOne();
- },
- saveMessage() {
- const message = $('#admin-announcement').val().trim();
- Announcements.update(Announcements.findOne()._id, {
- $set: {'body': message},
- });
- },
- toggleActive() {
- this.setLoading(true);
- const isActive = this.currentSetting().enabled;
- Announcements.update(Announcements.findOne()._id, {
- $set: {'enabled': !isActive},
- });
- this.setLoading(false);
- if (isActive) {
- $('.admin-announcement').slideUp();
- } else {
- $('.admin-announcement').slideDown();
- }
- },
- events() {
- return [{
- 'click a.js-toggle-activemessage': this.toggleActive,
- 'click button.js-announcement-save': this.saveMessage,
- }];
- },
- }).register('announcementSettings');
|