settingBody.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. BlazeComponent.extendComponent({
  2. onCreated() {
  3. this.error = new ReactiveVar('');
  4. this.loading = new ReactiveVar(false);
  5. this.generalSetting = new ReactiveVar(true);
  6. this.emailSetting = new ReactiveVar(false);
  7. this.accountSetting = new ReactiveVar(false);
  8. this.announcementSetting = new ReactiveVar(false);
  9. Meteor.subscribe('setting');
  10. Meteor.subscribe('mailServer');
  11. Meteor.subscribe('accountSettings');
  12. Meteor.subscribe('announcements');
  13. },
  14. setError(error) {
  15. this.error.set(error);
  16. },
  17. setLoading(w) {
  18. this.loading.set(w);
  19. },
  20. /*
  21. checkField(selector) {
  22. const value = $(selector).val();
  23. if (!value || value.trim() === '') {
  24. $(selector).parents('li.smtp-form').addClass('has-error');
  25. throw Error('blank field');
  26. } else {
  27. return value;
  28. }
  29. },
  30. */
  31. currentSetting() {
  32. return Settings.findOne();
  33. },
  34. boards() {
  35. return Boards.find({
  36. archived: false,
  37. 'members.userId': Meteor.userId(),
  38. 'members.isAdmin': true,
  39. }, {
  40. sort: ['title'],
  41. });
  42. },
  43. toggleRegistration() {
  44. this.setLoading(true);
  45. const registrationClosed = this.currentSetting().disableRegistration;
  46. Settings.update(Settings.findOne()._id, {$set: {disableRegistration: !registrationClosed}});
  47. this.setLoading(false);
  48. if (registrationClosed) {
  49. $('.invite-people').slideUp();
  50. } else {
  51. $('.invite-people').slideDown();
  52. }
  53. },
  54. /*
  55. toggleTLS() {
  56. $('#mail-server-tls').toggleClass('is-checked');
  57. },
  58. */
  59. switchMenu(event) {
  60. const target = $(event.target);
  61. if (!target.hasClass('active')) {
  62. $('.side-menu li.active').removeClass('active');
  63. target.parent().addClass('active');
  64. const targetID = target.data('id');
  65. this.generalSetting.set('registration-setting' === targetID);
  66. this.emailSetting.set('email-setting' === targetID);
  67. this.accountSetting.set('account-setting' === targetID);
  68. this.announcementSetting.set('announcement-setting' === targetID);
  69. }
  70. },
  71. checkBoard(event) {
  72. let target = $(event.target);
  73. if (!target.hasClass('js-toggle-board-choose')) {
  74. target = target.parent();
  75. }
  76. const checkboxId = target.attr('id');
  77. $(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');
  78. $(`#${checkboxId}`).toggleClass('is-checked');
  79. },
  80. inviteThroughEmail() {
  81. const emails = $('#email-to-invite').val().trim().split('\n').join(',').split(',');
  82. const boardsToInvite = [];
  83. $('.js-toggle-board-choose .materialCheckBox.is-checked').each(function () {
  84. boardsToInvite.push($(this).data('id'));
  85. });
  86. const validEmails = [];
  87. emails.forEach((email) => {
  88. if (email && SimpleSchema.RegEx.Email.test(email.trim())) {
  89. validEmails.push(email.trim());
  90. }
  91. });
  92. if (validEmails.length) {
  93. this.setLoading(true);
  94. Meteor.call('sendInvitation', validEmails, boardsToInvite, () => {
  95. // if (!err) {
  96. // TODO - show more info to user
  97. // }
  98. this.setLoading(false);
  99. });
  100. }
  101. },
  102. /*
  103. saveMailServerInfo() {
  104. this.setLoading(true);
  105. $('li').removeClass('has-error');
  106. try {
  107. const host = this.checkField('#mail-server-host');
  108. const port = this.checkField('#mail-server-port');
  109. const username = $('#mail-server-username').val().trim();
  110. const password = $('#mail-server-password').val().trim();
  111. const from = this.checkField('#mail-server-from');
  112. const tls = $('#mail-server-tls.is-checked').length > 0;
  113. Settings.update(Settings.findOne()._id, {
  114. $set: {
  115. 'mailServer.host': host, 'mailServer.port': port, 'mailServer.username': username,
  116. 'mailServer.password': password, 'mailServer.enableTLS': tls, 'mailServer.from': from,
  117. },
  118. });
  119. } catch (e) {
  120. return;
  121. } finally {
  122. this.setLoading(false);
  123. }
  124. },
  125. */
  126. sendSMTPTestEmail() {
  127. Meteor.call('sendSMTPTestEmail', (err, ret) => {
  128. if (!err && ret) { /* eslint-disable no-console */
  129. const message = `${TAPi18n.__(ret.message)}: ${ret.email}`;
  130. console.log(message);
  131. alert(message);
  132. } else {
  133. const reason = err.reason || '';
  134. const message = `${TAPi18n.__(err.error)}\n${reason}`;
  135. console.log(message, err);
  136. alert(message);
  137. }
  138. /* eslint-enable no-console */
  139. });
  140. },
  141. events() {
  142. return [{
  143. 'click a.js-toggle-registration': this.toggleRegistration,
  144. /*
  145. 'click a.js-toggle-tls': this.toggleTLS,
  146. */
  147. 'click a.js-setting-menu': this.switchMenu,
  148. 'click a.js-toggle-board-choose': this.checkBoard,
  149. 'click button.js-email-invite': this.inviteThroughEmail,
  150. /*
  151. 'click button.js-save': this.saveMailServerInfo,
  152. */
  153. 'click button.js-send-smtp-test-email': this.sendSMTPTestEmail,
  154. }];
  155. },
  156. }).register('setting');
  157. BlazeComponent.extendComponent({
  158. saveAccountsChange() {
  159. const allowEmailChange = ($('input[name=allowEmailChange]:checked').val() === 'true');
  160. const allowUserNameChange = ($('input[name=allowUserNameChange]:checked').val() === 'true');
  161. AccountSettings.update('accounts-allowEmailChange', {
  162. $set: {'booleanValue': allowEmailChange},
  163. });
  164. AccountSettings.update('accounts-allowUserNameChange', {
  165. $set: {'booleanValue': allowUserNameChange},
  166. });
  167. },
  168. allowEmailChange() {
  169. return AccountSettings.findOne('accounts-allowEmailChange').booleanValue;
  170. },
  171. allowUserNameChange() {
  172. return AccountSettings.findOne('accounts-allowUserNameChange').booleanValue;
  173. },
  174. events() {
  175. return [{
  176. 'click button.js-accounts-save': this.saveAccountsChange,
  177. }];
  178. },
  179. }).register('accountSettings');
  180. BlazeComponent.extendComponent({
  181. onCreated() {
  182. this.loading = new ReactiveVar(false);
  183. },
  184. setLoading(w) {
  185. this.loading.set(w);
  186. },
  187. currentSetting() {
  188. return Announcements.findOne();
  189. },
  190. saveMessage() {
  191. const message = $('#admin-announcement').val().trim();
  192. Announcements.update(Announcements.findOne()._id, {
  193. $set: {'body': message},
  194. });
  195. },
  196. toggleActive() {
  197. this.setLoading(true);
  198. const isActive = this.currentSetting().enabled;
  199. Announcements.update(Announcements.findOne()._id, {
  200. $set: {'enabled': !isActive},
  201. });
  202. this.setLoading(false);
  203. if (isActive) {
  204. $('.admin-announcement').slideUp();
  205. } else {
  206. $('.admin-announcement').slideDown();
  207. }
  208. },
  209. events() {
  210. return [{
  211. 'click a.js-toggle-activemessage': this.toggleActive,
  212. 'click button.js-announcement-save': this.saveMessage,
  213. }];
  214. },
  215. }).register('announcementSettings');