cardDetails.js 22 KB

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