cardDetails.js 23 KB

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