sidebar.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. import { Cookies } from 'meteor/ostrio:cookies';
  2. const cookies = new Cookies();
  3. Sidebar = null;
  4. const defaultView = 'home';
  5. const MCB = '.materialCheckBox';
  6. const CKCLS = 'is-checked';
  7. const viewTitles = {
  8. filter: 'filter-cards',
  9. search: 'search-cards',
  10. multiselection: 'multi-selection',
  11. customFields: 'custom-fields',
  12. archives: 'archives',
  13. };
  14. BlazeComponent.extendComponent({
  15. mixins() {
  16. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  17. },
  18. onCreated() {
  19. this._isOpen = new ReactiveVar(false);
  20. this._view = new ReactiveVar(defaultView);
  21. Sidebar = this;
  22. },
  23. onDestroyed() {
  24. Sidebar = null;
  25. },
  26. isOpen() {
  27. return this._isOpen.get();
  28. },
  29. open() {
  30. if (!this._isOpen.get()) {
  31. this._isOpen.set(true);
  32. EscapeActions.executeUpTo('detailsPane');
  33. }
  34. },
  35. hide() {
  36. if (this._isOpen.get()) {
  37. this._isOpen.set(false);
  38. }
  39. },
  40. toggle() {
  41. this._isOpen.set(!this._isOpen.get());
  42. },
  43. calculateNextPeak() {
  44. const sidebarElement = this.find('.js-board-sidebar-content');
  45. if (sidebarElement) {
  46. const altitude = sidebarElement.scrollHeight;
  47. this.callFirstWith(this, 'setNextPeak', altitude);
  48. }
  49. },
  50. reachNextPeak() {
  51. const activitiesComponent = this.childComponents('activities')[0];
  52. activitiesComponent.loadNextPage();
  53. },
  54. isTongueHidden() {
  55. return this.isOpen() && this.getView() !== defaultView;
  56. },
  57. scrollTop() {
  58. this.$('.js-board-sidebar-content').scrollTop(0);
  59. },
  60. getView() {
  61. return this._view.get();
  62. },
  63. setView(view) {
  64. view = _.isString(view) ? view : defaultView;
  65. if (this._view.get() !== view) {
  66. this._view.set(view);
  67. this.scrollTop();
  68. EscapeActions.executeUpTo('detailsPane');
  69. }
  70. this.open();
  71. },
  72. isDefaultView() {
  73. return this.getView() === defaultView;
  74. },
  75. getViewTemplate() {
  76. return `${this.getView()}Sidebar`;
  77. },
  78. getViewTitle() {
  79. return TAPi18n.__(viewTitles[this.getView()]);
  80. },
  81. showTongueTitle() {
  82. if (this.isOpen()) return `${TAPi18n.__('sidebar-close')}`;
  83. else return `${TAPi18n.__('sidebar-open')}`;
  84. },
  85. events() {
  86. return [
  87. {
  88. 'click .js-hide-sidebar': this.hide,
  89. 'click .js-toggle-sidebar': this.toggle,
  90. 'click .js-back-home': this.setView,
  91. 'click .js-toggle-minicard-label-text'() {
  92. currentUser = Meteor.user();
  93. if (currentUser) {
  94. Meteor.call('toggleMinicardLabelText');
  95. } else if (cookies.has('hiddenMinicardLabelText')) {
  96. cookies.remove('hiddenMinicardLabelText');
  97. } else {
  98. cookies.set('hiddenMinicardLabelText', 'true');
  99. }
  100. },
  101. 'click .js-shortcuts'() {
  102. FlowRouter.go('shortcuts');
  103. },
  104. },
  105. ];
  106. },
  107. }).register('sidebar');
  108. Blaze.registerHelper('Sidebar', () => Sidebar);
  109. Template.homeSidebar.helpers({
  110. hiddenMinicardLabelText() {
  111. currentUser = Meteor.user();
  112. if (currentUser) {
  113. return (currentUser.profile || {}).hiddenMinicardLabelText;
  114. } else if (cookies.has('hiddenMinicardLabelText')) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. },
  120. });
  121. EscapeActions.register(
  122. 'sidebarView',
  123. () => {
  124. Sidebar.setView(defaultView);
  125. },
  126. () => {
  127. return Sidebar && Sidebar.getView() !== defaultView;
  128. },
  129. );
  130. Template.memberPopup.helpers({
  131. user() {
  132. return Users.findOne(this.userId);
  133. },
  134. memberType() {
  135. const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
  136. if (type === 'normal') {
  137. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  138. const commentOnly = currentBoard.hasCommentOnly(this.userId);
  139. const noComments = currentBoard.hasNoComments(this.userId);
  140. const worker = currentBoard.hasWorker(this.userId);
  141. if (commentOnly) {
  142. return TAPi18n.__('comment-only').toLowerCase();
  143. } else if (noComments) {
  144. return TAPi18n.__('no-comments').toLowerCase();
  145. } else if (worker) {
  146. return TAPi18n.__('worker').toLowerCase();
  147. } else {
  148. return TAPi18n.__(type).toLowerCase();
  149. }
  150. } else {
  151. return TAPi18n.__(type).toLowerCase();
  152. }
  153. },
  154. isInvited() {
  155. return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
  156. },
  157. });
  158. Template.boardMenuPopup.events({
  159. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  160. 'click .js-open-rules-view'() {
  161. Modal.openWide('rulesMain');
  162. Popup.close();
  163. },
  164. 'click .js-custom-fields'() {
  165. Sidebar.setView('customFields');
  166. Popup.close();
  167. },
  168. 'click .js-open-archives'() {
  169. Sidebar.setView('archives');
  170. Popup.close();
  171. },
  172. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  173. 'click .js-change-language': Popup.open('changeLanguage'),
  174. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  175. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  176. currentBoard.archive();
  177. // XXX We should have some kind of notification on top of the page to
  178. // confirm that the board was successfully archived.
  179. FlowRouter.go('home');
  180. }),
  181. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  182. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  183. Popup.close();
  184. Boards.remove(currentBoard._id);
  185. FlowRouter.go('home');
  186. }),
  187. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  188. 'click .js-import-board': Popup.open('chooseBoardSource'),
  189. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  190. 'click .js-card-settings': Popup.open('boardCardSettings'),
  191. });
  192. Template.boardMenuPopup.onCreated(function() {
  193. this.apiEnabled = new ReactiveVar(false);
  194. Meteor.call('_isApiEnabled', (e, result) => {
  195. this.apiEnabled.set(result);
  196. });
  197. });
  198. Template.boardMenuPopup.helpers({
  199. withApi() {
  200. return Template.instance().apiEnabled.get();
  201. },
  202. exportUrl() {
  203. const params = {
  204. boardId: Session.get('currentBoard'),
  205. };
  206. const queryParams = {
  207. authToken: Accounts._storedLoginToken(),
  208. };
  209. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  210. },
  211. exportFilename() {
  212. const boardId = Session.get('currentBoard');
  213. return `wekan-export-board-${boardId}.json`;
  214. },
  215. });
  216. Template.memberPopup.events({
  217. 'click .js-filter-member'() {
  218. Filter.members.toggle(this.userId);
  219. Popup.close();
  220. },
  221. 'click .js-change-role': Popup.open('changePermissions'),
  222. 'click .js-remove-member': Popup.afterConfirm('removeMember', function() {
  223. const boardId = Session.get('currentBoard');
  224. const memberId = this.userId;
  225. Cards.find({ boardId, members: memberId }).forEach(card => {
  226. card.unassignMember(memberId);
  227. });
  228. Boards.findOne(boardId).removeMember(memberId);
  229. Popup.close();
  230. }),
  231. 'click .js-leave-member': Popup.afterConfirm('leaveBoard', () => {
  232. const boardId = Session.get('currentBoard');
  233. Meteor.call('quitBoard', boardId, () => {
  234. Popup.close();
  235. FlowRouter.go('home');
  236. });
  237. }),
  238. });
  239. Template.removeMemberPopup.helpers({
  240. user() {
  241. return Users.findOne(this.userId);
  242. },
  243. board() {
  244. return Boards.findOne(Session.get('currentBoard'));
  245. },
  246. });
  247. Template.leaveBoardPopup.helpers({
  248. board() {
  249. return Boards.findOne(Session.get('currentBoard'));
  250. },
  251. });
  252. Template.membersWidget.helpers({
  253. isInvited() {
  254. const user = Meteor.user();
  255. return user && user.isInvitedTo(Session.get('currentBoard'));
  256. },
  257. isWorker() {
  258. const user = Meteor.user();
  259. if (user) {
  260. return Meteor.call(Boards.hasWorker(user.memberId));
  261. } else {
  262. return false;
  263. }
  264. },
  265. });
  266. Template.membersWidget.events({
  267. 'click .js-member': Popup.open('member'),
  268. 'click .js-open-board-menu': Popup.open('boardMenu'),
  269. 'click .js-manage-board-members': Popup.open('addMember'),
  270. 'click .js-import': Popup.open('boardImportBoard'),
  271. submit: this.onSubmit,
  272. 'click .js-import-board': Popup.open('chooseBoardSource'),
  273. 'click .js-open-archived-board'() {
  274. Modal.open('archivedBoards');
  275. },
  276. 'click .sandstorm-powerbox-request-identity'() {
  277. window.sandstormRequestIdentity();
  278. },
  279. 'click .js-member-invite-accept'() {
  280. const boardId = Session.get('currentBoard');
  281. Meteor.user().removeInvite(boardId);
  282. },
  283. 'click .js-member-invite-decline'() {
  284. const boardId = Session.get('currentBoard');
  285. Meteor.call('quitBoard', boardId, (err, ret) => {
  286. if (!err && ret) {
  287. Meteor.user().removeInvite(boardId);
  288. FlowRouter.go('home');
  289. }
  290. });
  291. },
  292. });
  293. BlazeComponent.extendComponent({
  294. boardId() {
  295. return Session.get('currentBoard') || Integrations.Const.GLOBAL_WEBHOOK_ID;
  296. },
  297. integrations() {
  298. const boardId = this.boardId();
  299. return Integrations.find({ boardId: `${boardId}` }).fetch();
  300. },
  301. types() {
  302. return Integrations.Const.WEBHOOK_TYPES;
  303. },
  304. integration(cond) {
  305. const boardId = this.boardId();
  306. const condition = { boardId, ...cond };
  307. for (const k in condition) {
  308. if (!condition[k]) delete condition[k];
  309. }
  310. return Integrations.findOne(condition);
  311. },
  312. onCreated() {
  313. this.disabled = new ReactiveVar(false);
  314. },
  315. events() {
  316. return [
  317. {
  318. 'click a.flex'(evt) {
  319. this.disabled.set(!this.disabled.get());
  320. $(evt.target).toggleClass(CKCLS, this.disabled.get());
  321. },
  322. submit(evt) {
  323. evt.preventDefault();
  324. const url = evt.target.url.value;
  325. const boardId = this.boardId();
  326. let id = null;
  327. let integration = null;
  328. const title = evt.target.title.value;
  329. const token = evt.target.token.value;
  330. const type = evt.target.type.value;
  331. const enabled = !this.disabled.get();
  332. let remove = false;
  333. const values = {
  334. url,
  335. type,
  336. token,
  337. title,
  338. enabled,
  339. };
  340. if (evt.target.id) {
  341. id = evt.target.id.value;
  342. integration = this.integration({ _id: id });
  343. remove = !url;
  344. } else if (url) {
  345. integration = this.integration({ url, token });
  346. }
  347. if (remove) {
  348. Integrations.remove(integration._id);
  349. } else if (integration && integration._id) {
  350. Integrations.update(integration._id, {
  351. $set: values,
  352. });
  353. } else if (url) {
  354. Integrations.insert({
  355. ...values,
  356. userId: Meteor.userId(),
  357. enabled: true,
  358. boardId,
  359. activities: ['all'],
  360. });
  361. }
  362. Popup.close();
  363. },
  364. },
  365. ];
  366. },
  367. }).register('outgoingWebhooksPopup');
  368. BlazeComponent.extendComponent({
  369. template() {
  370. return 'chooseBoardSource';
  371. },
  372. }).register('chooseBoardSourcePopup');
  373. Template.labelsWidget.events({
  374. 'click .js-label': Popup.open('editLabel'),
  375. 'click .js-add-label': Popup.open('createLabel'),
  376. });
  377. // Board members can assign people or labels by drag-dropping elements from the
  378. // sidebar to the cards on the board. In order to re-initialize the jquery-ui
  379. // plugin any time a draggable member or label is modified or removed we use a
  380. // autorun function and register a dependency on the both members and labels
  381. // fields of the current board document.
  382. function draggableMembersLabelsWidgets() {
  383. this.autorun(() => {
  384. const currentBoardId = Tracker.nonreactive(() => {
  385. return Session.get('currentBoard');
  386. });
  387. Boards.findOne(currentBoardId, {
  388. fields: {
  389. members: 1,
  390. labels: 1,
  391. },
  392. });
  393. Tracker.afterFlush(() => {
  394. const $draggables = this.$('.js-member,.js-label');
  395. $draggables.draggable({
  396. appendTo: 'body',
  397. helper: 'clone',
  398. revert: 'invalid',
  399. revertDuration: 150,
  400. snap: false,
  401. snapMode: 'both',
  402. start() {
  403. EscapeActions.executeUpTo('popup-back');
  404. },
  405. });
  406. function userIsMember() {
  407. return Meteor.user() && Meteor.user().isBoardMember();
  408. }
  409. this.autorun(() => {
  410. $draggables.draggable('option', 'disabled', !userIsMember());
  411. });
  412. });
  413. });
  414. }
  415. Template.membersWidget.onRendered(draggableMembersLabelsWidgets);
  416. Template.labelsWidget.onRendered(draggableMembersLabelsWidgets);
  417. BlazeComponent.extendComponent({
  418. backgroundColors() {
  419. return Boards.simpleSchema()._schema.color.allowedValues;
  420. },
  421. isSelected() {
  422. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  423. return currentBoard.color === this.currentData().toString();
  424. },
  425. events() {
  426. return [
  427. {
  428. 'click .js-select-background'(evt) {
  429. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  430. const newColor = this.currentData().toString();
  431. currentBoard.setColor(newColor);
  432. evt.preventDefault();
  433. },
  434. },
  435. ];
  436. },
  437. }).register('boardChangeColorPopup');
  438. BlazeComponent.extendComponent({
  439. onCreated() {
  440. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  441. },
  442. allowsSubtasks() {
  443. return this.currentBoard.allowsSubtasks;
  444. },
  445. allowsReceivedDate() {
  446. return this.currentBoard.allowsReceivedDate;
  447. },
  448. isBoardSelected() {
  449. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  450. },
  451. isNullBoardSelected() {
  452. return (
  453. this.currentBoard.subtasksDefaultBoardId === null ||
  454. this.currentBoard.subtasksDefaultBoardId === undefined
  455. );
  456. },
  457. boards() {
  458. return Boards.find(
  459. {
  460. archived: false,
  461. 'members.userId': Meteor.userId(),
  462. },
  463. {
  464. sort: { sort: 1 /* boards default sorting */ },
  465. },
  466. );
  467. },
  468. lists() {
  469. return Lists.find(
  470. {
  471. boardId: this.currentBoard._id,
  472. archived: false,
  473. },
  474. {
  475. sort: ['title'],
  476. },
  477. );
  478. },
  479. hasLists() {
  480. return this.lists().count() > 0;
  481. },
  482. isListSelected() {
  483. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  484. },
  485. presentParentTask() {
  486. let result = this.currentBoard.presentParentTask;
  487. if (result === null || result === undefined) {
  488. result = 'no-parent';
  489. }
  490. return result;
  491. },
  492. events() {
  493. return [
  494. {
  495. 'click .js-field-has-subtasks'(evt) {
  496. evt.preventDefault();
  497. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  498. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  499. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  500. CKCLS,
  501. this.currentBoard.allowsSubtasks,
  502. );
  503. $('.js-field-has-subtasks').toggleClass(
  504. CKCLS,
  505. this.currentBoard.allowsSubtasks,
  506. );
  507. $('.js-field-deposit-board').prop(
  508. 'disabled',
  509. !this.currentBoard.allowsSubtasks,
  510. );
  511. },
  512. 'change .js-field-deposit-board'(evt) {
  513. let value = evt.target.value;
  514. if (value === 'null') {
  515. value = null;
  516. }
  517. this.currentBoard.setSubtasksDefaultBoardId(value);
  518. evt.preventDefault();
  519. },
  520. 'change .js-field-deposit-list'(evt) {
  521. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  522. evt.preventDefault();
  523. },
  524. 'click .js-field-show-parent-in-minicard'(evt) {
  525. const value =
  526. evt.target.id ||
  527. $(evt.target).parent()[0].id ||
  528. $(evt.target)
  529. .parent()[0]
  530. .parent()[0].id;
  531. const options = [
  532. 'prefix-with-full-path',
  533. 'prefix-with-parent',
  534. 'subtext-with-full-path',
  535. 'subtext-with-parent',
  536. 'no-parent',
  537. ];
  538. options.forEach(function(element) {
  539. if (element !== value) {
  540. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  541. $(`#${element}`).toggleClass(CKCLS, false);
  542. }
  543. });
  544. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  545. $(`#${value}`).toggleClass(CKCLS, true);
  546. this.currentBoard.setPresentParentTask(value);
  547. evt.preventDefault();
  548. },
  549. },
  550. ];
  551. },
  552. }).register('boardSubtaskSettingsPopup');
  553. BlazeComponent.extendComponent({
  554. onCreated() {
  555. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  556. },
  557. allowsReceivedDate() {
  558. return this.currentBoard.allowsReceivedDate;
  559. },
  560. allowsStartDate() {
  561. return this.currentBoard.allowsStartDate;
  562. },
  563. allowsDueDate() {
  564. return this.currentBoard.allowsDueDate;
  565. },
  566. allowsEndDate() {
  567. return this.currentBoard.allowsEndDate;
  568. },
  569. allowsSubtasks() {
  570. return this.currentBoard.allowsSubtasks;
  571. },
  572. allowsMembers() {
  573. return this.currentBoard.allowsMembers;
  574. },
  575. allowsAssignee() {
  576. return this.currentBoard.allowsAssignee;
  577. },
  578. allowsAssignedBy() {
  579. return this.currentBoard.allowsAssignedBy;
  580. },
  581. allowsRequestedBy() {
  582. return this.currentBoard.allowsRequestedBy;
  583. },
  584. allowsLabels() {
  585. return this.currentBoard.allowsLabels;
  586. },
  587. allowsChecklists() {
  588. return this.currentBoard.allowsChecklists;
  589. },
  590. allowsAttachments() {
  591. return this.currentBoard.allowsAttachments;
  592. },
  593. allowsComments() {
  594. return this.currentBoard.allowsComments;
  595. },
  596. allowsDescriptionTitle() {
  597. return this.currentBoard.allowsDescriptionTitle;
  598. },
  599. allowsDescriptionText() {
  600. return this.currentBoard.allowsDescriptionText;
  601. },
  602. isBoardSelected() {
  603. return this.currentBoard.dateSettingsDefaultBoardID;
  604. },
  605. isNullBoardSelected() {
  606. return (
  607. this.currentBoard.dateSettingsDefaultBoardId === null ||
  608. this.currentBoard.dateSettingsDefaultBoardId === undefined
  609. );
  610. },
  611. boards() {
  612. return Boards.find(
  613. {
  614. archived: false,
  615. 'members.userId': Meteor.userId(),
  616. },
  617. {
  618. sort: { sort: 1 /* boards default sorting */ },
  619. },
  620. );
  621. },
  622. lists() {
  623. return Lists.find(
  624. {
  625. boardId: this.currentBoard._id,
  626. archived: false,
  627. },
  628. {
  629. sort: ['title'],
  630. },
  631. );
  632. },
  633. hasLists() {
  634. return this.lists().count() > 0;
  635. },
  636. isListSelected() {
  637. return (
  638. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  639. );
  640. },
  641. events() {
  642. return [
  643. {
  644. 'click .js-field-has-receiveddate'(evt) {
  645. evt.preventDefault();
  646. this.currentBoard.allowsReceivedDate = !this.currentBoard
  647. .allowsReceivedDate;
  648. this.currentBoard.setAllowsReceivedDate(
  649. this.currentBoard.allowsReceivedDate,
  650. );
  651. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  652. CKCLS,
  653. this.currentBoard.allowsReceivedDate,
  654. );
  655. $('.js-field-has-receiveddate').toggleClass(
  656. CKCLS,
  657. this.currentBoard.allowsReceivedDate,
  658. );
  659. },
  660. 'click .js-field-has-startdate'(evt) {
  661. evt.preventDefault();
  662. this.currentBoard.allowsStartDate = !this.currentBoard
  663. .allowsStartDate;
  664. this.currentBoard.setAllowsStartDate(
  665. this.currentBoard.allowsStartDate,
  666. );
  667. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  668. CKCLS,
  669. this.currentBoard.allowsStartDate,
  670. );
  671. $('.js-field-has-startdate').toggleClass(
  672. CKCLS,
  673. this.currentBoard.allowsStartDate,
  674. );
  675. },
  676. 'click .js-field-has-enddate'(evt) {
  677. evt.preventDefault();
  678. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  679. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  680. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  681. CKCLS,
  682. this.currentBoard.allowsEndDate,
  683. );
  684. $('.js-field-has-enddate').toggleClass(
  685. CKCLS,
  686. this.currentBoard.allowsEndDate,
  687. );
  688. },
  689. 'click .js-field-has-duedate'(evt) {
  690. evt.preventDefault();
  691. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  692. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  693. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  694. CKCLS,
  695. this.currentBoard.allowsDueDate,
  696. );
  697. $('.js-field-has-duedate').toggleClass(
  698. CKCLS,
  699. this.currentBoard.allowsDueDate,
  700. );
  701. },
  702. 'click .js-field-has-subtasks'(evt) {
  703. evt.preventDefault();
  704. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  705. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  706. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  707. CKCLS,
  708. this.currentBoard.allowsSubtasks,
  709. );
  710. $('.js-field-has-subtasks').toggleClass(
  711. CKCLS,
  712. this.currentBoard.allowsSubtasks,
  713. );
  714. },
  715. 'click .js-field-has-members'(evt) {
  716. evt.preventDefault();
  717. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  718. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  719. $(`.js-field-has-members ${MCB}`).toggleClass(
  720. CKCLS,
  721. this.currentBoard.allowsMembers,
  722. );
  723. $('.js-field-has-members').toggleClass(
  724. CKCLS,
  725. this.currentBoard.allowsMembers,
  726. );
  727. },
  728. 'click .js-field-has-assignee'(evt) {
  729. evt.preventDefault();
  730. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  731. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  732. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  733. CKCLS,
  734. this.currentBoard.allowsAssignee,
  735. );
  736. $('.js-field-has-assignee').toggleClass(
  737. CKCLS,
  738. this.currentBoard.allowsAssignee,
  739. );
  740. },
  741. 'click .js-field-has-assigned-by'(evt) {
  742. evt.preventDefault();
  743. this.currentBoard.allowsAssignedBy = !this.currentBoard
  744. .allowsAssignedBy;
  745. this.currentBoard.setAllowsAssignedBy(
  746. this.currentBoard.allowsAssignedBy,
  747. );
  748. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  749. CKCLS,
  750. this.currentBoard.allowsAssignedBy,
  751. );
  752. $('.js-field-has-assigned-by').toggleClass(
  753. CKCLS,
  754. this.currentBoard.allowsAssignedBy,
  755. );
  756. },
  757. 'click .js-field-has-requested-by'(evt) {
  758. evt.preventDefault();
  759. this.currentBoard.allowsRequestedBy = !this.currentBoard
  760. .allowsRequestedBy;
  761. this.currentBoard.setAllowsRequestedBy(
  762. this.currentBoard.allowsRequestedBy,
  763. );
  764. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  765. CKCLS,
  766. this.currentBoard.allowsRequestedBy,
  767. );
  768. $('.js-field-has-requested-by').toggleClass(
  769. CKCLS,
  770. this.currentBoard.allowsRequestedBy,
  771. );
  772. },
  773. 'click .js-field-has-labels'(evt) {
  774. evt.preventDefault();
  775. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  776. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  777. $(`.js-field-has-labels ${MCB}`).toggleClass(
  778. CKCLS,
  779. this.currentBoard.allowsAssignee,
  780. );
  781. $('.js-field-has-labels').toggleClass(
  782. CKCLS,
  783. this.currentBoard.allowsLabels,
  784. );
  785. },
  786. 'click .js-field-has-description-title'(evt) {
  787. evt.preventDefault();
  788. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  789. .allowsDescriptionTitle;
  790. this.currentBoard.setAllowsDescriptionTitle(
  791. this.currentBoard.allowsDescriptionTitle,
  792. );
  793. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  794. CKCLS,
  795. this.currentBoard.allowsDescriptionTitle,
  796. );
  797. $('.js-field-has-description-title').toggleClass(
  798. CKCLS,
  799. this.currentBoard.allowsDescriptionTitle,
  800. );
  801. },
  802. 'click .js-field-has-description-text'(evt) {
  803. evt.preventDefault();
  804. this.currentBoard.allowsDescriptionText = !this.currentBoard
  805. .allowsDescriptionText;
  806. this.currentBoard.setAllowsDescriptionText(
  807. this.currentBoard.allowsDescriptionText,
  808. );
  809. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  810. CKCLS,
  811. this.currentBoard.allowsDescriptionText,
  812. );
  813. $('.js-field-has-description-text').toggleClass(
  814. CKCLS,
  815. this.currentBoard.allowsDescriptionText,
  816. );
  817. },
  818. 'click .js-field-has-checklists'(evt) {
  819. evt.preventDefault();
  820. this.currentBoard.allowsChecklists = !this.currentBoard
  821. .allowsChecklists;
  822. this.currentBoard.setAllowsChecklists(
  823. this.currentBoard.allowsChecklists,
  824. );
  825. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  826. CKCLS,
  827. this.currentBoard.allowsChecklists,
  828. );
  829. $('.js-field-has-checklists').toggleClass(
  830. CKCLS,
  831. this.currentBoard.allowsChecklists,
  832. );
  833. },
  834. 'click .js-field-has-attachments'(evt) {
  835. evt.preventDefault();
  836. this.currentBoard.allowsAttachments = !this.currentBoard
  837. .allowsAttachments;
  838. this.currentBoard.setAllowsAttachments(
  839. this.currentBoard.allowsAttachments,
  840. );
  841. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  842. CKCLS,
  843. this.currentBoard.allowsAttachments,
  844. );
  845. $('.js-field-has-attachments').toggleClass(
  846. CKCLS,
  847. this.currentBoard.allowsAttachments,
  848. );
  849. },
  850. 'click .js-field-has-comments'(evt) {
  851. evt.preventDefault();
  852. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  853. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  854. $(`.js-field-has-comments ${MCB}`).toggleClass(
  855. CKCLS,
  856. this.currentBoard.allowsComments,
  857. );
  858. $('.js-field-has-comments').toggleClass(
  859. CKCLS,
  860. this.currentBoard.allowsComments,
  861. );
  862. },
  863. 'click .js-field-has-activities'(evt) {
  864. evt.preventDefault();
  865. this.currentBoard.allowsActivities = !this.currentBoard
  866. .allowsActivities;
  867. this.currentBoard.setAllowsActivities(
  868. this.currentBoard.allowsActivities,
  869. );
  870. $(`.js-field-has-activities ${MCB}`).toggleClass(
  871. CKCLS,
  872. this.currentBoard.allowsActivities,
  873. );
  874. $('.js-field-has-activities').toggleClass(
  875. CKCLS,
  876. this.currentBoard.allowsActivities,
  877. );
  878. },
  879. },
  880. ];
  881. },
  882. }).register('boardCardSettingsPopup');
  883. BlazeComponent.extendComponent({
  884. onCreated() {
  885. this.error = new ReactiveVar('');
  886. this.loading = new ReactiveVar(false);
  887. },
  888. onRendered() {
  889. this.find('.js-search-member input').focus();
  890. this.setLoading(false);
  891. },
  892. isBoardMember() {
  893. const userId = this.currentData()._id;
  894. const user = Users.findOne(userId);
  895. return user && user.isBoardMember();
  896. },
  897. isValidEmail(email) {
  898. return SimpleSchema.RegEx.Email.test(email);
  899. },
  900. setError(error) {
  901. this.error.set(error);
  902. },
  903. setLoading(w) {
  904. this.loading.set(w);
  905. },
  906. isLoading() {
  907. return this.loading.get();
  908. },
  909. inviteUser(idNameEmail) {
  910. const boardId = Session.get('currentBoard');
  911. this.setLoading(true);
  912. const self = this;
  913. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  914. self.setLoading(false);
  915. if (err) self.setError(err.error);
  916. else if (ret.email) self.setError('email-sent');
  917. else Popup.close();
  918. });
  919. },
  920. events() {
  921. return [
  922. {
  923. 'keyup input'() {
  924. this.setError('');
  925. },
  926. 'click .js-select-member'() {
  927. const userId = this.currentData()._id;
  928. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  929. if (!currentBoard.hasMember(userId)) {
  930. this.inviteUser(userId);
  931. }
  932. },
  933. 'click .js-email-invite'() {
  934. const idNameEmail = $('.js-search-member input').val();
  935. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  936. this.inviteUser(idNameEmail);
  937. } else this.setError('email-invalid');
  938. },
  939. },
  940. ];
  941. },
  942. }).register('addMemberPopup');
  943. Template.changePermissionsPopup.events({
  944. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  945. event,
  946. ) {
  947. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  948. const memberId = this.userId;
  949. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  950. const isCommentOnly = $(event.currentTarget).hasClass(
  951. 'js-set-comment-only',
  952. );
  953. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  954. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  955. currentBoard.setMemberPermission(
  956. memberId,
  957. isAdmin,
  958. isNoComments,
  959. isCommentOnly,
  960. isWorker,
  961. );
  962. Popup.back(1);
  963. },
  964. });
  965. Template.changePermissionsPopup.helpers({
  966. isAdmin() {
  967. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  968. return currentBoard.hasAdmin(this.userId);
  969. },
  970. isNormal() {
  971. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  972. return (
  973. !currentBoard.hasAdmin(this.userId) &&
  974. !currentBoard.hasNoComments(this.userId) &&
  975. !currentBoard.hasCommentOnly(this.userId) &&
  976. !currentBoard.hasWorker(this.userId)
  977. );
  978. },
  979. isNoComments() {
  980. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  981. return (
  982. !currentBoard.hasAdmin(this.userId) &&
  983. currentBoard.hasNoComments(this.userId)
  984. );
  985. },
  986. isCommentOnly() {
  987. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  988. return (
  989. !currentBoard.hasAdmin(this.userId) &&
  990. currentBoard.hasCommentOnly(this.userId)
  991. );
  992. },
  993. isWorker() {
  994. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  995. return (
  996. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  997. );
  998. },
  999. isLastAdmin() {
  1000. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1001. return (
  1002. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1003. );
  1004. },
  1005. });