cardDetails.js 22 KB

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