cardDetails.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 bSelect = $('.js-select-boards')[0];
  369. const boardId = bSelect.options[bSelect.selectedIndex].value;
  370. const lSelect = $('.js-select-lists')[0];
  371. const listId = lSelect.options[lSelect.selectedIndex].value;
  372. const slSelect = $('.js-select-swimlanes')[0];
  373. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  374. card.move(boardId, swimlaneId, listId, 0);
  375. Popup.close();
  376. },
  377. });
  378. BlazeComponent.extendComponent({
  379. onCreated() {
  380. subManager.subscribe('board', Session.get('currentBoard'), false);
  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. _id: {$ne: Meteor.user().getTemplatesBoardId()},
  388. }, {
  389. sort: ['title'],
  390. });
  391. return boards;
  392. },
  393. swimlanes() {
  394. const board = Boards.findOne(this.selectedBoardId.get());
  395. return board.swimlanes();
  396. },
  397. aBoardLists() {
  398. const board = Boards.findOne(this.selectedBoardId.get());
  399. return board.lists();
  400. },
  401. events() {
  402. return [{
  403. 'change .js-select-boards'(evt) {
  404. this.selectedBoardId.set($(evt.currentTarget).val());
  405. subManager.subscribe('board', this.selectedBoardId.get(), false);
  406. },
  407. }];
  408. },
  409. }).register('boardsAndLists');
  410. Template.copyCardPopup.events({
  411. 'click .js-done'() {
  412. const card = Cards.findOne(Session.get('currentCard'));
  413. const lSelect = $('.js-select-lists')[0];
  414. listId = lSelect.options[lSelect.selectedIndex].value;
  415. const slSelect = $('.js-select-swimlanes')[0];
  416. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  417. const bSelect = $('.js-select-boards')[0];
  418. const boardId = bSelect.options[bSelect.selectedIndex].value;
  419. const textarea = $('#copy-card-title');
  420. const title = textarea.val().trim();
  421. // insert new card to the bottom of new list
  422. card.sort = Lists.findOne(card.listId).cards().count();
  423. if (title) {
  424. card.title = title;
  425. card.coverId = '';
  426. const _id = card.copy(boardId, swimlaneId, listId);
  427. // In case the filter is active we need to add the newly inserted card in
  428. // the list of exceptions -- cards that are not filtered. Otherwise the
  429. // card will disappear instantly.
  430. // See https://github.com/wekan/wekan/issues/80
  431. Filter.addException(_id);
  432. Popup.close();
  433. }
  434. },
  435. });
  436. Template.copyChecklistToManyCardsPopup.events({
  437. 'click .js-done' () {
  438. const card = Cards.findOne(Session.get('currentCard'));
  439. const oldId = card._id;
  440. card._id = null;
  441. const lSelect = $('.js-select-lists')[0];
  442. card.listId = lSelect.options[lSelect.selectedIndex].value;
  443. const slSelect = $('.js-select-swimlanes')[0];
  444. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  445. const bSelect = $('.js-select-boards')[0];
  446. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  447. const textarea = $('#copy-card-title');
  448. const titleEntry = textarea.val().trim();
  449. // insert new card to the bottom of new list
  450. card.sort = Lists.findOne(card.listId).cards().count();
  451. if (titleEntry) {
  452. const titleList = JSON.parse(titleEntry);
  453. for (let i = 0; i < titleList.length; i++){
  454. const obj = titleList[i];
  455. card.title = obj.title;
  456. card.description = obj.description;
  457. card.coverId = '';
  458. const _id = Cards.insert(card);
  459. // In case the filter is active we need to add the newly inserted card in
  460. // the list of exceptions -- cards that are not filtered. Otherwise the
  461. // card will disappear instantly.
  462. // See https://github.com/wekan/wekan/issues/80
  463. Filter.addException(_id);
  464. // copy checklists
  465. Checklists.find({cardId: oldId}).forEach((ch) => {
  466. ch.copy(_id);
  467. });
  468. // copy subtasks
  469. cursor = Cards.find({parentId: oldId});
  470. cursor.forEach(function() {
  471. 'use strict';
  472. const subtask = arguments[0];
  473. subtask.parentId = _id;
  474. subtask._id = null;
  475. /* const newSubtaskId = */ Cards.insert(subtask);
  476. });
  477. // copy card comments
  478. CardComments.find({cardId: oldId}).forEach((cmt) => {
  479. cmt.copy(_id);
  480. });
  481. }
  482. Popup.close();
  483. }
  484. },
  485. });
  486. BlazeComponent.extendComponent({
  487. onCreated() {
  488. this.currentCard = this.currentData();
  489. this.currentColor = new ReactiveVar(this.currentCard.color);
  490. },
  491. colors() {
  492. return cardColors.map((color) => ({ color, name: '' }));
  493. },
  494. isSelected(color) {
  495. if (this.currentColor.get() === null) {
  496. return color === 'white';
  497. }
  498. return this.currentColor.get() === color;
  499. },
  500. events() {
  501. return [{
  502. 'click .js-palette-color'() {
  503. this.currentColor.set(this.currentData().color);
  504. },
  505. 'click .js-submit' () {
  506. this.currentCard.setColor(this.currentColor.get());
  507. Popup.close();
  508. },
  509. 'click .js-remove-color'() {
  510. this.currentCard.setColor(null);
  511. Popup.close();
  512. },
  513. }];
  514. },
  515. }).register('setCardColorPopup');
  516. BlazeComponent.extendComponent({
  517. onCreated() {
  518. this.currentCard = this.currentData();
  519. this.parentBoard = new ReactiveVar(null);
  520. this.parentCard = this.currentCard.parentCard();
  521. if (this.parentCard) {
  522. const list = $('.js-field-parent-card');
  523. list.val(this.parentCard._id);
  524. this.parentBoard.set(this.parentCard.board()._id);
  525. } else {
  526. this.parentBoard.set(null);
  527. }
  528. },
  529. boards() {
  530. const boards = Boards.find({
  531. archived: false,
  532. 'members.userId': Meteor.userId(),
  533. _id: {
  534. $ne: Meteor.user().getTemplatesBoardId(),
  535. },
  536. }, {
  537. sort: ['title'],
  538. });
  539. return boards;
  540. },
  541. cards() {
  542. const currentId = Session.get('currentCard');
  543. if (this.parentBoard.get()) {
  544. return Cards.find({
  545. boardId: this.parentBoard.get(),
  546. _id: {$ne: currentId},
  547. });
  548. } else {
  549. return [];
  550. }
  551. },
  552. isParentBoard() {
  553. const board = this.currentData();
  554. if (this.parentBoard.get()) {
  555. return board._id === this.parentBoard.get();
  556. }
  557. return false;
  558. },
  559. isParentCard() {
  560. const card = this.currentData();
  561. if (this.parentCard) {
  562. return card._id === this.parentCard;
  563. }
  564. return false;
  565. },
  566. setParentCardId(cardId) {
  567. if (cardId) {
  568. this.parentCard = Cards.findOne(cardId);
  569. } else {
  570. this.parentCard = null;
  571. }
  572. this.currentCard.setParentId(cardId);
  573. },
  574. events() {
  575. return [{
  576. 'click .js-copy-card-link-to-clipboard' () {
  577. // Clipboard code from:
  578. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  579. const StringToCopyElement = document.getElementById('cardURL');
  580. StringToCopyElement.select();
  581. if (document.execCommand('copy')) {
  582. StringToCopyElement.blur();
  583. } else {
  584. document.getElementById('cardURL').selectionStart = 0;
  585. document.getElementById('cardURL').selectionEnd = 999;
  586. document.execCommand('copy');
  587. if (window.getSelection) {
  588. if (window.getSelection().empty) { // Chrome
  589. window.getSelection().empty();
  590. } else if (window.getSelection().removeAllRanges) { // Firefox
  591. window.getSelection().removeAllRanges();
  592. }
  593. } else if (document.selection) { // IE?
  594. document.selection.empty();
  595. }
  596. }
  597. },
  598. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  599. Popup.close();
  600. Cards.remove(this._id);
  601. Utils.goBoardId(this.boardId);
  602. }),
  603. 'change .js-field-parent-board'(evt) {
  604. const selection = $(evt.currentTarget).val();
  605. const list = $('.js-field-parent-card');
  606. if (selection === 'none') {
  607. this.parentBoard.set(null);
  608. } else {
  609. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  610. this.parentBoard.set(selection);
  611. list.prop('disabled', false);
  612. }
  613. this.setParentCardId(null);
  614. },
  615. 'change .js-field-parent-card'(evt) {
  616. const selection = $(evt.currentTarget).val();
  617. this.setParentCardId(selection);
  618. },
  619. }];
  620. },
  621. }).register('cardMorePopup');
  622. // Close the card details pane by pressing escape
  623. EscapeActions.register('detailsPane',
  624. () => {
  625. Utils.goBoardId(Session.get('currentBoard'));
  626. },
  627. () => {
  628. return !Session.equals('currentCard', null);
  629. }, {
  630. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  631. }
  632. );