cardDetails.js 22 KB

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