settingBody.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. Meteor.subscribe('setting');
  2. Meteor.subscribe('mailServer');
  3. Meteor.subscribe('accountSettings');
  4. BlazeComponent.extendComponent({
  5. onCreated() {
  6. this.error = new ReactiveVar('');
  7. this.loading = new ReactiveVar(false);
  8. this.generalSetting = new ReactiveVar(true);
  9. this.emailSetting = new ReactiveVar(false);
  10. this.accountSetting = new ReactiveVar(false);
  11. },
  12. setError(error) {
  13. this.error.set(error);
  14. },
  15. setLoading(w) {
  16. this.loading.set(w);
  17. },
  18. checkField(selector) {
  19. const value = $(selector).val();
  20. if(!value || value.trim() === ''){
  21. $(selector).parents('li.smtp-form').addClass('has-error');
  22. throw Error('blank field');
  23. } else {
  24. return value;
  25. }
  26. },
  27. currentSetting(){
  28. return Settings.findOne();
  29. },
  30. boards() {
  31. return Boards.find({
  32. archived: false,
  33. 'members.userId': Meteor.userId(),
  34. 'members.isAdmin': true,
  35. }, {
  36. sort: ['title'],
  37. });
  38. },
  39. toggleRegistration(){
  40. this.setLoading(true);
  41. const registrationClosed = this.currentSetting().disableRegistration;
  42. Settings.update(Settings.findOne()._id, {$set:{disableRegistration: !registrationClosed}});
  43. this.setLoading(false);
  44. if(registrationClosed){
  45. $('.invite-people').slideUp();
  46. }else{
  47. $('.invite-people').slideDown();
  48. }
  49. },
  50. toggleTLS(){
  51. $('#mail-server-tls').toggleClass('is-checked');
  52. },
  53. switchMenu(event){
  54. const target = $(event.target);
  55. if(!target.hasClass('active')){
  56. $('.side-menu li.active').removeClass('active');
  57. target.parent().addClass('active');
  58. const targetID = target.data('id');
  59. this.generalSetting.set('registration-setting' === targetID);
  60. this.emailSetting.set('email-setting' === targetID);
  61. this.accountSetting.set('account-setting' === targetID);
  62. }
  63. },
  64. checkBoard(event){
  65. let target = $(event.target);
  66. if(!target.hasClass('js-toggle-board-choose')){
  67. target = target.parent();
  68. }
  69. const checkboxId = target.attr('id');
  70. $(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');
  71. $(`#${checkboxId}`).toggleClass('is-checked');
  72. },
  73. inviteThroughEmail(){
  74. const emails = $('#email-to-invite').val().trim().split('\n').join(',').split(',');
  75. const boardsToInvite = [];
  76. $('.js-toggle-board-choose .materialCheckBox.is-checked').each(function () {
  77. boardsToInvite.push($(this).data('id'));
  78. });
  79. const validEmails = [];
  80. emails.forEach((email) => {
  81. if (email && SimpleSchema.RegEx.Email.test(email.trim())) {
  82. validEmails.push(email.trim());
  83. }
  84. });
  85. if (validEmails.length) {
  86. this.setLoading(true);
  87. Meteor.call('sendInvitation', validEmails, boardsToInvite, () => {
  88. // if (!err) {
  89. // TODO - show more info to user
  90. // }
  91. this.setLoading(false);
  92. });
  93. }
  94. },
  95. saveMailServerInfo(){
  96. this.setLoading(true);
  97. $('li').removeClass('has-error');
  98. try{
  99. const host = this.checkField('#mail-server-host');
  100. const port = this.checkField('#mail-server-port');
  101. const username = $('#mail-server-username').val().trim();
  102. const password = $('#mail-server-password').val().trim();
  103. const from = this.checkField('#mail-server-from');
  104. const tls = $('#mail-server-tls.is-checked').length > 0;
  105. Settings.update(Settings.findOne()._id, {$set:{'mailServer.host':host, 'mailServer.port': port, 'mailServer.username': username,
  106. 'mailServer.password': password, 'mailServer.enableTLS': tls, 'mailServer.from': from}});
  107. } catch (e) {
  108. return;
  109. } finally {
  110. this.setLoading(false);
  111. }
  112. },
  113. events(){
  114. return [{
  115. 'click a.js-toggle-registration': this.toggleRegistration,
  116. 'click a.js-toggle-tls': this.toggleTLS,
  117. 'click a.js-setting-menu': this.switchMenu,
  118. 'click a.js-toggle-board-choose': this.checkBoard,
  119. 'click button.js-email-invite': this.inviteThroughEmail,
  120. 'click button.js-save': this.saveMailServerInfo,
  121. }];
  122. },
  123. }).register('setting');
  124. BlazeComponent.extendComponent({
  125. saveAllowEmailChange() {
  126. const allowEmailChange = ($('input[name=allowEmailChange]:checked').val() === 'true');
  127. AccountSettings.update('accounts-allowEmailChange', {
  128. $set: { 'booleanValue': allowEmailChange },
  129. });
  130. },
  131. allowEmailChange() {
  132. return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
  133. },
  134. events() {
  135. return [{
  136. 'click button.js-accounts-save': this.saveAllowEmailChange,
  137. }];
  138. },
  139. }).register('accountSettings');