cardDetails.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. const subManager = new SubsManager();
  2. const { calculateIndexData, enableClickOnTouch } = Utils;
  3. let cardColors;
  4. Meteor.startup(() => {
  5. cardColors = Cards.simpleSchema()._schema.color.allowedValues;
  6. });
  7. BlazeComponent.extendComponent({
  8. mixins() {
  9. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  10. },
  11. calculateNextPeak() {
  12. const cardElement = this.find('.js-card-details');
  13. if (cardElement) {
  14. const altitude = cardElement.scrollHeight;
  15. this.callFirstWith(this, 'setNextPeak', altitude);
  16. }
  17. },
  18. reachNextPeak() {
  19. const activitiesComponent = this.childComponents('activities')[0];
  20. activitiesComponent.loadNextPage();
  21. },
  22. onCreated() {
  23. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  24. this.isLoaded = new ReactiveVar(false);
  25. const boardBody = this.parentComponent().parentComponent();
  26. //in Miniview parent is Board, not BoardBody.
  27. if (boardBody !== null) {
  28. boardBody.showOverlay.set(true);
  29. boardBody.mouseHasEnterCardDetails = false;
  30. }
  31. this.calculateNextPeak();
  32. Meteor.subscribe('unsaved-edits');
  33. },
  34. isWatching() {
  35. const card = this.currentData();
  36. return card.findWatcher(Meteor.userId());
  37. },
  38. hiddenSystemMessages() {
  39. return Meteor.user().hasHiddenSystemMessages();
  40. },
  41. canModifyCard() {
  42. return (
  43. Meteor.user() &&
  44. Meteor.user().isBoardMember() &&
  45. !Meteor.user().isCommentOnly()
  46. );
  47. },
  48. scrollParentContainer() {
  49. const cardPanelWidth = 510;
  50. const bodyBoardComponent = this.parentComponent().parentComponent();
  51. //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
  52. if (bodyBoardComponent === null) return;
  53. const $cardView = this.$(this.firstNode());
  54. const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
  55. const cardContainerScroll = $cardContainer.scrollLeft();
  56. const cardContainerWidth = $cardContainer.width();
  57. const cardViewStart = $cardView.offset().left;
  58. const cardViewEnd = cardViewStart + cardPanelWidth;
  59. let offset = false;
  60. if (cardViewStart < 0) {
  61. offset = cardViewStart;
  62. } else if (cardViewEnd > cardContainerWidth) {
  63. offset = cardViewEnd - cardContainerWidth;
  64. }
  65. if (offset) {
  66. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  67. }
  68. //Scroll top
  69. const cardViewStartTop = $cardView.offset().top;
  70. const cardContainerScrollTop = $cardContainer.scrollTop();
  71. let topOffset = false;
  72. if (cardViewStartTop !== 100) {
  73. topOffset = cardViewStartTop - 100;
  74. }
  75. if (topOffset !== false) {
  76. bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
  77. }
  78. },
  79. presentParentTask() {
  80. let result = this.currentBoard.presentParentTask;
  81. if (result === null || result === undefined) {
  82. result = 'no-parent';
  83. }
  84. return result;
  85. },
  86. linkForCard() {
  87. const card = this.currentData();
  88. let result = '#';
  89. if (card) {
  90. const board = Boards.findOne(card.boardId);
  91. if (board) {
  92. result = FlowRouter.url('card', {
  93. boardId: card.boardId,
  94. slug: board.slug,
  95. cardId: card._id,
  96. });
  97. }
  98. }
  99. return result;
  100. },
  101. onRendered() {
  102. // Send Webhook but not create Activities records ---
  103. const card = this.currentData();
  104. const userId = Meteor.userId();
  105. //console.log(`userId: ${userId}`);
  106. //console.log(`cardId: ${card._id}`);
  107. //console.log(`boardId: ${card.boardId}`);
  108. //console.log(`listId: ${card.listId}`);
  109. //console.log(`swimlaneId: ${card.swimlaneId}`);
  110. const params = {
  111. userId,
  112. cardId: card._id,
  113. boardId: card.boardId,
  114. listId: card.listId,
  115. user: Meteor.user().username,
  116. url: '',
  117. };
  118. //console.log('looking for integrations...');
  119. const integrations = Integrations.find({
  120. boardId: card.boardId,
  121. type: 'outgoing-webhooks',
  122. enabled: true,
  123. activities: { $in: ['CardDetailsRendered', 'all'] },
  124. }).fetch();
  125. //console.log(`Investigation length: ${integrations.length}`);
  126. if (integrations.length > 0) {
  127. Meteor.call('outgoingWebhooks', integrations, 'CardSelected', params);
  128. }
  129. //-------------
  130. if (!Utils.isMiniScreen()) {
  131. Meteor.setTimeout(() => {
  132. $('.card-details').mCustomScrollbar({
  133. theme: 'minimal-dark',
  134. setWidth: false,
  135. setLeft: 0,
  136. scrollbarPosition: 'outside',
  137. mouseWheel: true,
  138. });
  139. this.scrollParentContainer();
  140. }, 500);
  141. }
  142. const $checklistsDom = this.$('.card-checklist-items');
  143. $checklistsDom.sortable({
  144. tolerance: 'pointer',
  145. helper: 'clone',
  146. handle: '.checklist-title',
  147. items: '.js-checklist',
  148. placeholder: 'checklist placeholder',
  149. distance: 7,
  150. start(evt, ui) {
  151. ui.placeholder.height(ui.helper.height());
  152. EscapeActions.executeUpTo('popup-close');
  153. },
  154. stop(evt, ui) {
  155. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  156. if (prevChecklist) {
  157. prevChecklist = Blaze.getData(prevChecklist).checklist;
  158. }
  159. let nextChecklist = ui.item.next('.js-checklist').get(0);
  160. if (nextChecklist) {
  161. nextChecklist = Blaze.getData(nextChecklist).checklist;
  162. }
  163. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  164. $checklistsDom.sortable('cancel');
  165. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  166. Checklists.update(checklist._id, {
  167. $set: {
  168. sort: sortIndex.base,
  169. },
  170. });
  171. },
  172. });
  173. // ugly touch event hotfix
  174. enableClickOnTouch('.card-checklist-items .js-checklist');
  175. const $subtasksDom = this.$('.card-subtasks-items');
  176. $subtasksDom.sortable({
  177. tolerance: 'pointer',
  178. helper: 'clone',
  179. handle: '.subtask-title',
  180. items: '.js-subtasks',
  181. placeholder: 'subtasks placeholder',
  182. distance: 7,
  183. start(evt, ui) {
  184. ui.placeholder.height(ui.helper.height());
  185. EscapeActions.executeUpTo('popup-close');
  186. },
  187. stop(evt, ui) {
  188. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  189. if (prevChecklist) {
  190. prevChecklist = Blaze.getData(prevChecklist).subtask;
  191. }
  192. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  193. if (nextChecklist) {
  194. nextChecklist = Blaze.getData(nextChecklist).subtask;
  195. }
  196. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  197. $subtasksDom.sortable('cancel');
  198. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  199. Subtasks.update(subtask._id, {
  200. $set: {
  201. subtaskSort: sortIndex.base,
  202. },
  203. });
  204. },
  205. });
  206. // ugly touch event hotfix
  207. enableClickOnTouch('.card-subtasks-items .js-subtasks');
  208. function userIsMember() {
  209. return Meteor.user() && Meteor.user().isBoardMember();
  210. }
  211. // Disable sorting if the current user is not a board member
  212. this.autorun(() => {
  213. if ($checklistsDom.data('sortable')) {
  214. $checklistsDom.sortable('option', 'disabled', !userIsMember());
  215. }
  216. if ($subtasksDom.data('sortable')) {
  217. $subtasksDom.sortable('option', 'disabled', !userIsMember());
  218. }
  219. });
  220. },
  221. onDestroyed() {
  222. const parentComponent = this.parentComponent().parentComponent();
  223. //on mobile view parent is Board, not board body.
  224. if (parentComponent === null) return;
  225. parentComponent.showOverlay.set(false);
  226. },
  227. events() {
  228. const events = {
  229. [`${CSSEvents.transitionend} .js-card-details`]() {
  230. this.isLoaded.set(true);
  231. },
  232. [`${CSSEvents.animationend} .js-card-details`]() {
  233. this.isLoaded.set(true);
  234. },
  235. };
  236. return [
  237. {
  238. ...events,
  239. 'click .js-close-card-details'() {
  240. Utils.goBoardId(this.data().boardId);
  241. },
  242. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  243. 'submit .js-card-description'(event) {
  244. event.preventDefault();
  245. const description = this.currentComponent().getValue();
  246. this.data().setDescription(description);
  247. },
  248. 'submit .js-card-details-title'(event) {
  249. event.preventDefault();
  250. const title = this.currentComponent()
  251. .getValue()
  252. .trim();
  253. if (title) {
  254. this.data().setTitle(title);
  255. }
  256. },
  257. 'submit .js-card-details-assigner'(event) {
  258. event.preventDefault();
  259. const assigner = this.currentComponent()
  260. .getValue()
  261. .trim();
  262. if (assigner) {
  263. this.data().setAssignedBy(assigner);
  264. }
  265. },
  266. 'submit .js-card-details-requester'(event) {
  267. event.preventDefault();
  268. const requester = this.currentComponent()
  269. .getValue()
  270. .trim();
  271. if (requester) {
  272. this.data().setRequestedBy(requester);
  273. }
  274. },
  275. 'click .js-member': Popup.open('cardMember'),
  276. 'click .js-add-members': Popup.open('cardMembers'),
  277. 'click .js-add-labels': Popup.open('cardLabels'),
  278. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  279. 'click .js-start-date': Popup.open('editCardStartDate'),
  280. 'click .js-due-date': Popup.open('editCardDueDate'),
  281. 'click .js-end-date': Popup.open('editCardEndDate'),
  282. 'mouseenter .js-card-details'() {
  283. const parentComponent = this.parentComponent().parentComponent();
  284. //on mobile view parent is Board, not BoardBody.
  285. if (parentComponent === null) return;
  286. parentComponent.showOverlay.set(true);
  287. parentComponent.mouseHasEnterCardDetails = true;
  288. },
  289. 'click #toggleButton'() {
  290. Meteor.call('toggleSystemMessages');
  291. },
  292. },
  293. ];
  294. },
  295. }).register('cardDetails');
  296. // We extends the normal InlinedForm component to support UnsavedEdits draft
  297. // feature.
  298. (class extends InlinedForm {
  299. _getUnsavedEditKey() {
  300. return {
  301. fieldName: 'cardDescription',
  302. // XXX Recovering the currentCard identifier form a session variable is
  303. // fragile because this variable may change for instance if the route
  304. // change. We should use some component props instead.
  305. docId: Session.get('currentCard'),
  306. };
  307. }
  308. close(isReset = false) {
  309. if (this.isOpen.get() && !isReset) {
  310. const draft = this.getValue().trim();
  311. if (
  312. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  313. ) {
  314. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  315. }
  316. }
  317. super.close();
  318. }
  319. reset() {
  320. UnsavedEdits.reset(this._getUnsavedEditKey());
  321. this.close(true);
  322. }
  323. events() {
  324. const parentEvents = InlinedForm.prototype.events()[0];
  325. return [
  326. {
  327. ...parentEvents,
  328. 'click .js-close-inlined-form': this.reset,
  329. },
  330. ];
  331. }
  332. }.register('inlinedCardDescription'));
  333. Template.cardDetailsActionsPopup.helpers({
  334. isWatching() {
  335. return this.findWatcher(Meteor.userId());
  336. },
  337. canModifyCard() {
  338. return (
  339. Meteor.user() &&
  340. Meteor.user().isBoardMember() &&
  341. !Meteor.user().isCommentOnly()
  342. );
  343. },
  344. });
  345. Template.cardDetailsActionsPopup.events({
  346. 'click .js-members': Popup.open('cardMembers'),
  347. 'click .js-labels': Popup.open('cardLabels'),
  348. 'click .js-attachments': Popup.open('cardAttachments'),
  349. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  350. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  351. 'click .js-start-date': Popup.open('editCardStartDate'),
  352. 'click .js-due-date': Popup.open('editCardDueDate'),
  353. 'click .js-end-date': Popup.open('editCardEndDate'),
  354. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  355. 'click .js-move-card': Popup.open('moveCard'),
  356. 'click .js-copy-card': Popup.open('copyCard'),
  357. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  358. 'click .js-set-card-color': Popup.open('setCardColor'),
  359. 'click .js-move-card-to-top'(event) {
  360. event.preventDefault();
  361. const minOrder = _.min(
  362. this.list()
  363. .cards(this.swimlaneId)
  364. .map(c => c.sort),
  365. );
  366. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  367. },
  368. 'click .js-move-card-to-bottom'(event) {
  369. event.preventDefault();
  370. const maxOrder = _.max(
  371. this.list()
  372. .cards(this.swimlaneId)
  373. .map(c => c.sort),
  374. );
  375. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  376. },
  377. 'click .js-archive'(event) {
  378. event.preventDefault();
  379. this.archive();
  380. Popup.close();
  381. },
  382. 'click .js-more': Popup.open('cardMore'),
  383. 'click .js-toggle-watch-card'() {
  384. const currentCard = this;
  385. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  386. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  387. if (!err && ret) Popup.close();
  388. });
  389. },
  390. });
  391. Template.editCardTitleForm.onRendered(function() {
  392. autosize(this.$('.js-edit-card-title'));
  393. });
  394. Template.editCardTitleForm.events({
  395. 'keydown .js-edit-card-title'(event) {
  396. // If enter key was pressed, submit the data
  397. // Unless the shift key is also being pressed
  398. if (event.keyCode === 13 && !event.shiftKey) {
  399. $('.js-submit-edit-card-title-form').click();
  400. }
  401. },
  402. });
  403. Template.editCardRequesterForm.onRendered(function() {
  404. autosize(this.$('.js-edit-card-requester'));
  405. });
  406. Template.editCardRequesterForm.events({
  407. 'keydown .js-edit-card-requester'(event) {
  408. // If enter key was pressed, submit the data
  409. if (event.keyCode === 13) {
  410. $('.js-submit-edit-card-requester-form').click();
  411. }
  412. },
  413. });
  414. Template.editCardAssignerForm.onRendered(function() {
  415. autosize(this.$('.js-edit-card-assigner'));
  416. });
  417. Template.editCardAssignerForm.events({
  418. 'keydown .js-edit-card-assigner'(event) {
  419. // If enter key was pressed, submit the data
  420. if (event.keyCode === 13) {
  421. $('.js-submit-edit-card-assigner-form').click();
  422. }
  423. },
  424. });
  425. Template.moveCardPopup.events({
  426. 'click .js-done'() {
  427. // XXX We should *not* get the currentCard from the global state, but
  428. // instead from a “component” state.
  429. const card = Cards.findOne(Session.get('currentCard'));
  430. const bSelect = $('.js-select-boards')[0];
  431. const boardId = bSelect.options[bSelect.selectedIndex].value;
  432. const lSelect = $('.js-select-lists')[0];
  433. const listId = lSelect.options[lSelect.selectedIndex].value;
  434. const slSelect = $('.js-select-swimlanes')[0];
  435. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  436. card.move(boardId, swimlaneId, listId, 0);
  437. Popup.close();
  438. },
  439. });
  440. BlazeComponent.extendComponent({
  441. onCreated() {
  442. subManager.subscribe('board', Session.get('currentBoard'), false);
  443. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  444. },
  445. boards() {
  446. const boards = Boards.find(
  447. {
  448. archived: false,
  449. 'members.userId': Meteor.userId(),
  450. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  451. },
  452. {
  453. sort: ['title'],
  454. },
  455. );
  456. return boards;
  457. },
  458. swimlanes() {
  459. const board = Boards.findOne(this.selectedBoardId.get());
  460. return board.swimlanes();
  461. },
  462. aBoardLists() {
  463. const board = Boards.findOne(this.selectedBoardId.get());
  464. return board.lists();
  465. },
  466. events() {
  467. return [
  468. {
  469. 'change .js-select-boards'(event) {
  470. this.selectedBoardId.set($(event.currentTarget).val());
  471. subManager.subscribe('board', this.selectedBoardId.get(), false);
  472. },
  473. },
  474. ];
  475. },
  476. }).register('boardsAndLists');
  477. Template.copyCardPopup.events({
  478. 'click .js-done'() {
  479. const card = Cards.findOne(Session.get('currentCard'));
  480. const lSelect = $('.js-select-lists')[0];
  481. listId = lSelect.options[lSelect.selectedIndex].value;
  482. const slSelect = $('.js-select-swimlanes')[0];
  483. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  484. const bSelect = $('.js-select-boards')[0];
  485. const boardId = bSelect.options[bSelect.selectedIndex].value;
  486. const textarea = $('#copy-card-title');
  487. const title = textarea.val().trim();
  488. // insert new card to the bottom of new list
  489. card.sort = Lists.findOne(card.listId)
  490. .cards()
  491. .count();
  492. if (title) {
  493. card.title = title;
  494. card.coverId = '';
  495. const _id = card.copy(boardId, swimlaneId, listId);
  496. // In case the filter is active we need to add the newly inserted card in
  497. // the list of exceptions -- cards that are not filtered. Otherwise the
  498. // card will disappear instantly.
  499. // See https://github.com/wekan/wekan/issues/80
  500. Filter.addException(_id);
  501. Popup.close();
  502. }
  503. },
  504. });
  505. Template.copyChecklistToManyCardsPopup.events({
  506. 'click .js-done'() {
  507. const card = Cards.findOne(Session.get('currentCard'));
  508. const oldId = card._id;
  509. card._id = null;
  510. const lSelect = $('.js-select-lists')[0];
  511. card.listId = lSelect.options[lSelect.selectedIndex].value;
  512. const slSelect = $('.js-select-swimlanes')[0];
  513. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  514. const bSelect = $('.js-select-boards')[0];
  515. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  516. const textarea = $('#copy-card-title');
  517. const titleEntry = textarea.val().trim();
  518. // insert new card to the bottom of new list
  519. card.sort = Lists.findOne(card.listId)
  520. .cards()
  521. .count();
  522. if (titleEntry) {
  523. const titleList = JSON.parse(titleEntry);
  524. for (let i = 0; i < titleList.length; i++) {
  525. const obj = titleList[i];
  526. card.title = obj.title;
  527. card.description = obj.description;
  528. card.coverId = '';
  529. const _id = Cards.insert(card);
  530. // In case the filter is active we need to add the newly inserted card in
  531. // the list of exceptions -- cards that are not filtered. Otherwise the
  532. // card will disappear instantly.
  533. // See https://github.com/wekan/wekan/issues/80
  534. Filter.addException(_id);
  535. // copy checklists
  536. Checklists.find({ cardId: oldId }).forEach(ch => {
  537. ch.copy(_id);
  538. });
  539. // copy subtasks
  540. cursor = Cards.find({ parentId: oldId });
  541. cursor.forEach(function() {
  542. 'use strict';
  543. const subtask = arguments[0];
  544. subtask.parentId = _id;
  545. subtask._id = null;
  546. /* const newSubtaskId = */ Cards.insert(subtask);
  547. });
  548. // copy card comments
  549. CardComments.find({ cardId: oldId }).forEach(cmt => {
  550. cmt.copy(_id);
  551. });
  552. }
  553. Popup.close();
  554. }
  555. },
  556. });
  557. BlazeComponent.extendComponent({
  558. onCreated() {
  559. this.currentCard = this.currentData();
  560. this.currentColor = new ReactiveVar(this.currentCard.color);
  561. },
  562. colors() {
  563. return cardColors.map(color => ({ color, name: '' }));
  564. },
  565. isSelected(color) {
  566. if (this.currentColor.get() === null) {
  567. return color === 'white';
  568. }
  569. return this.currentColor.get() === color;
  570. },
  571. events() {
  572. return [
  573. {
  574. 'click .js-palette-color'() {
  575. this.currentColor.set(this.currentData().color);
  576. },
  577. 'click .js-submit'() {
  578. this.currentCard.setColor(this.currentColor.get());
  579. Popup.close();
  580. },
  581. 'click .js-remove-color'() {
  582. this.currentCard.setColor(null);
  583. Popup.close();
  584. },
  585. },
  586. ];
  587. },
  588. }).register('setCardColorPopup');
  589. BlazeComponent.extendComponent({
  590. onCreated() {
  591. this.currentCard = this.currentData();
  592. this.parentBoard = new ReactiveVar(null);
  593. this.parentCard = this.currentCard.parentCard();
  594. if (this.parentCard) {
  595. const list = $('.js-field-parent-card');
  596. list.val(this.parentCard._id);
  597. this.parentBoard.set(this.parentCard.board()._id);
  598. } else {
  599. this.parentBoard.set(null);
  600. }
  601. },
  602. boards() {
  603. const boards = Boards.find(
  604. {
  605. archived: false,
  606. 'members.userId': Meteor.userId(),
  607. _id: {
  608. $ne: Meteor.user().getTemplatesBoardId(),
  609. },
  610. },
  611. {
  612. sort: ['title'],
  613. },
  614. );
  615. return boards;
  616. },
  617. cards() {
  618. const currentId = Session.get('currentCard');
  619. if (this.parentBoard.get()) {
  620. return Cards.find({
  621. boardId: this.parentBoard.get(),
  622. _id: { $ne: currentId },
  623. });
  624. } else {
  625. return [];
  626. }
  627. },
  628. isParentBoard() {
  629. const board = this.currentData();
  630. if (this.parentBoard.get()) {
  631. return board._id === this.parentBoard.get();
  632. }
  633. return false;
  634. },
  635. isParentCard() {
  636. const card = this.currentData();
  637. if (this.parentCard) {
  638. return card._id === this.parentCard;
  639. }
  640. return false;
  641. },
  642. setParentCardId(cardId) {
  643. if (cardId) {
  644. this.parentCard = Cards.findOne(cardId);
  645. } else {
  646. this.parentCard = null;
  647. }
  648. this.currentCard.setParentId(cardId);
  649. },
  650. events() {
  651. return [
  652. {
  653. 'click .js-copy-card-link-to-clipboard'() {
  654. // Clipboard code from:
  655. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  656. const StringToCopyElement = document.getElementById('cardURL');
  657. StringToCopyElement.select();
  658. if (document.execCommand('copy')) {
  659. StringToCopyElement.blur();
  660. } else {
  661. document.getElementById('cardURL').selectionStart = 0;
  662. document.getElementById('cardURL').selectionEnd = 999;
  663. document.execCommand('copy');
  664. if (window.getSelection) {
  665. if (window.getSelection().empty) {
  666. // Chrome
  667. window.getSelection().empty();
  668. } else if (window.getSelection().removeAllRanges) {
  669. // Firefox
  670. window.getSelection().removeAllRanges();
  671. }
  672. } else if (document.selection) {
  673. // IE?
  674. document.selection.empty();
  675. }
  676. }
  677. },
  678. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  679. Popup.close();
  680. Cards.remove(this._id);
  681. Utils.goBoardId(this.boardId);
  682. }),
  683. 'change .js-field-parent-board'(event) {
  684. const selection = $(event.currentTarget).val();
  685. const list = $('.js-field-parent-card');
  686. if (selection === 'none') {
  687. this.parentBoard.set(null);
  688. } else {
  689. subManager.subscribe('board', $(event.currentTarget).val(), false);
  690. this.parentBoard.set(selection);
  691. list.prop('disabled', false);
  692. }
  693. this.setParentCardId(null);
  694. },
  695. 'change .js-field-parent-card'(event) {
  696. const selection = $(event.currentTarget).val();
  697. this.setParentCardId(selection);
  698. },
  699. },
  700. ];
  701. },
  702. }).register('cardMorePopup');
  703. // Close the card details pane by pressing escape
  704. EscapeActions.register(
  705. 'detailsPane',
  706. () => {
  707. Utils.goBoardId(Session.get('currentBoard'));
  708. },
  709. () => {
  710. return !Session.equals('currentCard', null);
  711. },
  712. {
  713. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  714. },
  715. );