cardDetails.js 21 KB

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