cardDetails.js 22 KB

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