cardDetails.js 22 KB

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