sidebar.js 33 KB

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