cardDetails.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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. voteState() {
  35. const card = this.currentData();
  36. const userId = Meteor.userId();
  37. let state;
  38. if (card.vote) {
  39. if (card.vote.positive) {
  40. state = _.contains(card.vote.positive, userId);
  41. if (state === true) return true;
  42. }
  43. if (card.vote.negative) {
  44. state = _.contains(card.vote.negative, userId);
  45. if (state === true) return false;
  46. }
  47. }
  48. return null;
  49. },
  50. votePublic() {
  51. const card = this.currentData();
  52. if (card.vote) return card.vote.public;
  53. return null;
  54. },
  55. voteCountPositive() {
  56. const card = this.currentData();
  57. if (card.vote && card.vote.positive) return card.vote.positive.length;
  58. return null;
  59. },
  60. voteCountNegative() {
  61. const card = this.currentData();
  62. if (card.vote && card.vote.negative) return card.vote.negative.length;
  63. return null;
  64. },
  65. isWatching() {
  66. const card = this.currentData();
  67. return card.findWatcher(Meteor.userId());
  68. },
  69. hiddenSystemMessages() {
  70. return Meteor.user().hasHiddenSystemMessages();
  71. },
  72. canModifyCard() {
  73. return (
  74. Meteor.user() &&
  75. Meteor.user().isBoardMember() &&
  76. !Meteor.user().isCommentOnly() &&
  77. !Meteor.user().isWorker()
  78. );
  79. },
  80. scrollParentContainer() {
  81. const cardPanelWidth = 510;
  82. const bodyBoardComponent = this.parentComponent().parentComponent();
  83. //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
  84. if (bodyBoardComponent === null) return;
  85. const $cardView = this.$(this.firstNode());
  86. const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
  87. const cardContainerScroll = $cardContainer.scrollLeft();
  88. const cardContainerWidth = $cardContainer.width();
  89. const cardViewStart = $cardView.offset().left;
  90. const cardViewEnd = cardViewStart + cardPanelWidth;
  91. let offset = false;
  92. if (cardViewStart < 0) {
  93. offset = cardViewStart;
  94. } else if (cardViewEnd > cardContainerWidth) {
  95. offset = cardViewEnd - cardContainerWidth;
  96. }
  97. if (offset) {
  98. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  99. }
  100. //Scroll top
  101. const cardViewStartTop = $cardView.offset().top;
  102. const cardContainerScrollTop = $cardContainer.scrollTop();
  103. let topOffset = false;
  104. if (cardViewStartTop !== 100) {
  105. topOffset = cardViewStartTop - 100;
  106. }
  107. if (topOffset !== false) {
  108. bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
  109. }
  110. },
  111. presentParentTask() {
  112. let result = this.currentBoard.presentParentTask;
  113. if (result === null || result === undefined) {
  114. result = 'no-parent';
  115. }
  116. return result;
  117. },
  118. linkForCard() {
  119. const card = this.currentData();
  120. let result = '#';
  121. if (card) {
  122. const board = Boards.findOne(card.boardId);
  123. if (board) {
  124. result = FlowRouter.url('card', {
  125. boardId: card.boardId,
  126. slug: board.slug,
  127. cardId: card._id,
  128. });
  129. }
  130. }
  131. return result;
  132. },
  133. onRendered() {
  134. if (Meteor.settings.public.CARD_OPENED_WEBHOOK_ENABLED) {
  135. // Send Webhook but not create Activities records ---
  136. const card = this.currentData();
  137. const userId = Meteor.userId();
  138. const params = {
  139. userId,
  140. cardId: card._id,
  141. boardId: card.boardId,
  142. listId: card.listId,
  143. user: Meteor.user().username,
  144. url: '',
  145. };
  146. const integrations = Integrations.find({
  147. boardId: { $in: [card.boardId, Integrations.Const.GLOBAL_WEBHOOK_ID] },
  148. enabled: true,
  149. activities: { $in: ['CardDetailsRendered', 'all'] },
  150. }).fetch();
  151. if (integrations.length > 0) {
  152. integrations.forEach(integration => {
  153. Meteor.call(
  154. 'outgoingWebhooks',
  155. integration,
  156. 'CardSelected',
  157. params,
  158. () => {
  159. return;
  160. },
  161. );
  162. });
  163. }
  164. //-------------
  165. }
  166. if (!Utils.isMiniScreen()) {
  167. Meteor.setTimeout(() => {
  168. $('.card-details').mCustomScrollbar({
  169. theme: 'minimal-dark',
  170. setWidth: false,
  171. setLeft: 0,
  172. scrollbarPosition: 'outside',
  173. mouseWheel: true,
  174. });
  175. this.scrollParentContainer();
  176. }, 500);
  177. }
  178. const $checklistsDom = this.$('.card-checklist-items');
  179. $checklistsDom.sortable({
  180. tolerance: 'pointer',
  181. helper: 'clone',
  182. handle: '.checklist-title',
  183. items: '.js-checklist',
  184. placeholder: 'checklist placeholder',
  185. distance: 7,
  186. start(evt, ui) {
  187. ui.placeholder.height(ui.helper.height());
  188. EscapeActions.executeUpTo('popup-close');
  189. },
  190. stop(evt, ui) {
  191. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  192. if (prevChecklist) {
  193. prevChecklist = Blaze.getData(prevChecklist).checklist;
  194. }
  195. let nextChecklist = ui.item.next('.js-checklist').get(0);
  196. if (nextChecklist) {
  197. nextChecklist = Blaze.getData(nextChecklist).checklist;
  198. }
  199. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  200. $checklistsDom.sortable('cancel');
  201. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  202. Checklists.update(checklist._id, {
  203. $set: {
  204. sort: sortIndex.base,
  205. },
  206. });
  207. },
  208. });
  209. // ugly touch event hotfix
  210. enableClickOnTouch('.card-checklist-items .js-checklist');
  211. const $subtasksDom = this.$('.card-subtasks-items');
  212. $subtasksDom.sortable({
  213. tolerance: 'pointer',
  214. helper: 'clone',
  215. handle: '.subtask-title',
  216. items: '.js-subtasks',
  217. placeholder: 'subtasks placeholder',
  218. distance: 7,
  219. start(evt, ui) {
  220. ui.placeholder.height(ui.helper.height());
  221. EscapeActions.executeUpTo('popup-close');
  222. },
  223. stop(evt, ui) {
  224. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  225. if (prevChecklist) {
  226. prevChecklist = Blaze.getData(prevChecklist).subtask;
  227. }
  228. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  229. if (nextChecklist) {
  230. nextChecklist = Blaze.getData(nextChecklist).subtask;
  231. }
  232. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  233. $subtasksDom.sortable('cancel');
  234. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  235. Subtasks.update(subtask._id, {
  236. $set: {
  237. subtaskSort: sortIndex.base,
  238. },
  239. });
  240. },
  241. });
  242. // ugly touch event hotfix
  243. enableClickOnTouch('.card-subtasks-items .js-subtasks');
  244. function userIsMember() {
  245. return Meteor.user() && Meteor.user().isBoardMember();
  246. }
  247. // Disable sorting if the current user is not a board member
  248. this.autorun(() => {
  249. const disabled = !userIsMember() || Utils.isMiniScreen();
  250. if ($checklistsDom.data('uiSortable')) {
  251. $checklistsDom.sortable('option', 'disabled', disabled);
  252. }
  253. if ($subtasksDom.data('uiSortable')) {
  254. $subtasksDom.sortable('option', 'disabled', disabled);
  255. }
  256. });
  257. },
  258. onDestroyed() {
  259. const parentComponent = this.parentComponent().parentComponent();
  260. //on mobile view parent is Board, not board body.
  261. if (parentComponent === null) return;
  262. parentComponent.showOverlay.set(false);
  263. },
  264. events() {
  265. const events = {
  266. [`${CSSEvents.transitionend} .js-card-details`]() {
  267. this.isLoaded.set(true);
  268. },
  269. [`${CSSEvents.animationend} .js-card-details`]() {
  270. this.isLoaded.set(true);
  271. },
  272. };
  273. return [
  274. {
  275. ...events,
  276. 'click .js-close-card-details'() {
  277. Utils.goBoardId(this.data().boardId);
  278. },
  279. 'click .js-copy-link'() {
  280. StringToCopyElement = document.getElementById('cardURL_copy');
  281. StringToCopyElement.select();
  282. if (document.execCommand('copy')) {
  283. StringToCopyElement.blur();
  284. } else {
  285. document.getElementById('cardURL_copy').selectionStart = 0;
  286. document.getElementById('cardURL_copy').selectionEnd = 999;
  287. document.execCommand('copy');
  288. if (window.getSelection) {
  289. if (window.getSelection().empty) {
  290. // Chrome
  291. window.getSelection().empty();
  292. } else if (window.getSelection().removeAllRanges) {
  293. // Firefox
  294. window.getSelection().removeAllRanges();
  295. }
  296. } else if (document.selection) {
  297. // IE?
  298. document.selection.empty();
  299. }
  300. }
  301. },
  302. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  303. 'submit .js-card-description'(event) {
  304. event.preventDefault();
  305. const description = this.currentComponent().getValue();
  306. this.data().setDescription(description);
  307. },
  308. 'submit .js-card-details-title'(event) {
  309. event.preventDefault();
  310. const title = this.currentComponent()
  311. .getValue()
  312. .trim();
  313. if (title) {
  314. this.data().setTitle(title);
  315. } else {
  316. this.data().setTitle('');
  317. }
  318. },
  319. 'submit .js-card-details-assigner'(event) {
  320. event.preventDefault();
  321. const assigner = this.currentComponent()
  322. .getValue()
  323. .trim();
  324. if (assigner) {
  325. this.data().setAssignedBy(assigner);
  326. } else {
  327. this.data().setAssignedBy('');
  328. }
  329. },
  330. 'submit .js-card-details-requester'(event) {
  331. event.preventDefault();
  332. const requester = this.currentComponent()
  333. .getValue()
  334. .trim();
  335. if (requester) {
  336. this.data().setRequestedBy(requester);
  337. } else {
  338. this.data().setRequestedBy('');
  339. }
  340. },
  341. 'click .js-go-to-linked-card'() {
  342. Utils.goCardId(this.data().linkedId);
  343. },
  344. 'click .js-member': Popup.open('cardMember'),
  345. 'click .js-add-members': Popup.open('cardMembers'),
  346. 'click .js-assignee': Popup.open('cardAssignee'),
  347. 'click .js-add-assignees': Popup.open('cardAssignees'),
  348. 'click .js-add-labels': Popup.open('cardLabels'),
  349. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  350. 'click .js-start-date': Popup.open('editCardStartDate'),
  351. 'click .js-due-date': Popup.open('editCardDueDate'),
  352. 'click .js-end-date': Popup.open('editCardEndDate'),
  353. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  354. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  355. 'mouseenter .js-card-details'() {
  356. const parentComponent = this.parentComponent().parentComponent();
  357. //on mobile view parent is Board, not BoardBody.
  358. if (parentComponent === null) return;
  359. parentComponent.showOverlay.set(true);
  360. parentComponent.mouseHasEnterCardDetails = true;
  361. },
  362. 'mousedown .js-card-details'() {
  363. Session.set('cardDetailsIsDragging', false);
  364. Session.set('cardDetailsIsMouseDown', true);
  365. },
  366. 'mousemove .js-card-details'() {
  367. if (Session.get('cardDetailsIsMouseDown')) {
  368. Session.set('cardDetailsIsDragging', true);
  369. }
  370. },
  371. 'mouseup .js-card-details'() {
  372. Session.set('cardDetailsIsDragging', false);
  373. Session.set('cardDetailsIsMouseDown', false);
  374. },
  375. 'click #toggleButton'() {
  376. Meteor.call('toggleSystemMessages');
  377. },
  378. 'click .js-vote'(e) {
  379. const forIt = $(e.target).hasClass('js-vote-positive');
  380. let newState = null;
  381. if (
  382. this.voteState() === null ||
  383. (this.voteState() === false && forIt) ||
  384. (this.voteState() === true && !forIt)
  385. ) {
  386. newState = forIt;
  387. }
  388. this.data().setVote(Meteor.userId(), newState);
  389. },
  390. },
  391. ];
  392. },
  393. }).register('cardDetails');
  394. Template.cardDetails.helpers({
  395. userData() {
  396. // We need to handle a special case for the search results provided by the
  397. // `matteodem:easy-search` package. Since these results gets published in a
  398. // separate collection, and not in the standard Meteor.Users collection as
  399. // expected, we use a component parameter ("property") to distinguish the
  400. // two cases.
  401. const userCollection = this.esSearch ? ESSearchResults : Users;
  402. return userCollection.findOne(this.userId, {
  403. fields: {
  404. profile: 1,
  405. username: 1,
  406. },
  407. });
  408. },
  409. receivedSelected() {
  410. if (this.getReceived().length === 0) {
  411. return false;
  412. } else {
  413. return true;
  414. }
  415. },
  416. startSelected() {
  417. if (this.getStart().length === 0) {
  418. return false;
  419. } else {
  420. return true;
  421. }
  422. },
  423. endSelected() {
  424. if (this.getEnd().length === 0) {
  425. return false;
  426. } else {
  427. return true;
  428. }
  429. },
  430. dueSelected() {
  431. if (this.getDue().length === 0) {
  432. return false;
  433. } else {
  434. return true;
  435. }
  436. },
  437. memberSelected() {
  438. if (this.getMembers().length === 0) {
  439. return false;
  440. } else {
  441. return true;
  442. }
  443. },
  444. labelSelected() {
  445. if (this.getLabels().length === 0) {
  446. return false;
  447. } else {
  448. return true;
  449. }
  450. },
  451. assigneeSelected() {
  452. if (this.getAssignees().length === 0) {
  453. return false;
  454. } else {
  455. return true;
  456. }
  457. },
  458. requestBySelected() {
  459. if (this.getRequestBy().length === 0) {
  460. return false;
  461. } else {
  462. return true;
  463. }
  464. },
  465. assigneeBySelected() {
  466. if (this.getAssigneeBy().length === 0) {
  467. return false;
  468. } else {
  469. return true;
  470. }
  471. },
  472. memberType() {
  473. const user = Users.findOne(this.userId);
  474. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  475. },
  476. presenceStatusClassName() {
  477. const user = Users.findOne(this.userId);
  478. const userPresence = presences.findOne({ userId: this.userId });
  479. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  480. else if (!userPresence) return 'disconnected';
  481. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  482. return 'active';
  483. else return 'idle';
  484. },
  485. });
  486. Template.userAvatarAssigneeInitials.helpers({
  487. initials() {
  488. const user = Users.findOne(this.userId);
  489. return user && user.getInitials();
  490. },
  491. viewPortWidth() {
  492. const user = Users.findOne(this.userId);
  493. return ((user && user.getInitials().length) || 1) * 12;
  494. },
  495. });
  496. // We extends the normal InlinedForm component to support UnsavedEdits draft
  497. // feature.
  498. (class extends InlinedForm {
  499. _getUnsavedEditKey() {
  500. return {
  501. fieldName: 'cardDescription',
  502. // XXX Recovering the currentCard identifier form a session variable is
  503. // fragile because this variable may change for instance if the route
  504. // change. We should use some component props instead.
  505. docId: Session.get('currentCard'),
  506. };
  507. }
  508. close(isReset = false) {
  509. if (this.isOpen.get() && !isReset) {
  510. const draft = this.getValue().trim();
  511. if (
  512. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  513. ) {
  514. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  515. }
  516. }
  517. super.close();
  518. }
  519. reset() {
  520. UnsavedEdits.reset(this._getUnsavedEditKey());
  521. this.close(true);
  522. }
  523. events() {
  524. const parentEvents = InlinedForm.prototype.events()[0];
  525. return [
  526. {
  527. ...parentEvents,
  528. 'click .js-close-inlined-form': this.reset,
  529. },
  530. ];
  531. }
  532. }.register('inlinedCardDescription'));
  533. Template.cardDetailsActionsPopup.helpers({
  534. isWatching() {
  535. return this.findWatcher(Meteor.userId());
  536. },
  537. canModifyCard() {
  538. return (
  539. Meteor.user() &&
  540. Meteor.user().isBoardMember() &&
  541. !Meteor.user().isCommentOnly()
  542. );
  543. },
  544. });
  545. Template.cardDetailsActionsPopup.events({
  546. 'click .js-members': Popup.open('cardMembers'),
  547. 'click .js-assignees': Popup.open('cardAssignees'),
  548. 'click .js-labels': Popup.open('cardLabels'),
  549. 'click .js-attachments': Popup.open('cardAttachments'),
  550. 'click .js-start-voting': Popup.open('cardStartVoting'),
  551. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  552. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  553. 'click .js-start-date': Popup.open('editCardStartDate'),
  554. 'click .js-due-date': Popup.open('editCardDueDate'),
  555. 'click .js-end-date': Popup.open('editCardEndDate'),
  556. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  557. 'click .js-move-card': Popup.open('moveCard'),
  558. 'click .js-copy-card': Popup.open('copyCard'),
  559. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  560. 'click .js-set-card-color': Popup.open('setCardColor'),
  561. 'click .js-cancel-voting'(event) {
  562. event.preventDefault();
  563. this.unsetVote();
  564. Popup.close();
  565. },
  566. 'click .js-move-card-to-top'(event) {
  567. event.preventDefault();
  568. const minOrder = _.min(
  569. this.list()
  570. .cards(this.swimlaneId)
  571. .map(c => c.sort),
  572. );
  573. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  574. },
  575. 'click .js-move-card-to-bottom'(event) {
  576. event.preventDefault();
  577. const maxOrder = _.max(
  578. this.list()
  579. .cards(this.swimlaneId)
  580. .map(c => c.sort),
  581. );
  582. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  583. },
  584. 'click .js-archive'(event) {
  585. event.preventDefault();
  586. this.archive();
  587. Popup.close();
  588. },
  589. 'click .js-more': Popup.open('cardMore'),
  590. 'click .js-toggle-watch-card'() {
  591. const currentCard = this;
  592. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  593. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  594. if (!err && ret) Popup.close();
  595. });
  596. },
  597. });
  598. Template.editCardTitleForm.onRendered(function() {
  599. autosize(this.$('.js-edit-card-title'));
  600. });
  601. Template.editCardTitleForm.events({
  602. 'keydown .js-edit-card-title'(event) {
  603. // If enter key was pressed, submit the data
  604. // Unless the shift key is also being pressed
  605. if (event.keyCode === 13 && !event.shiftKey) {
  606. $('.js-submit-edit-card-title-form').click();
  607. }
  608. },
  609. });
  610. Template.editCardRequesterForm.onRendered(function() {
  611. autosize(this.$('.js-edit-card-requester'));
  612. });
  613. Template.editCardRequesterForm.events({
  614. 'keydown .js-edit-card-requester'(event) {
  615. // If enter key was pressed, submit the data
  616. if (event.keyCode === 13) {
  617. $('.js-submit-edit-card-requester-form').click();
  618. }
  619. },
  620. });
  621. Template.editCardAssignerForm.onRendered(function() {
  622. autosize(this.$('.js-edit-card-assigner'));
  623. });
  624. Template.editCardAssignerForm.events({
  625. 'keydown .js-edit-card-assigner'(event) {
  626. // If enter key was pressed, submit the data
  627. if (event.keyCode === 13) {
  628. $('.js-submit-edit-card-assigner-form').click();
  629. }
  630. },
  631. });
  632. Template.moveCardPopup.events({
  633. 'click .js-done'() {
  634. // XXX We should *not* get the currentCard from the global state, but
  635. // instead from a “component” state.
  636. const card = Cards.findOne(Session.get('currentCard'));
  637. const bSelect = $('.js-select-boards')[0];
  638. const boardId = bSelect.options[bSelect.selectedIndex].value;
  639. const lSelect = $('.js-select-lists')[0];
  640. const listId = lSelect.options[lSelect.selectedIndex].value;
  641. const slSelect = $('.js-select-swimlanes')[0];
  642. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  643. card.move(boardId, swimlaneId, listId, 0);
  644. Popup.close();
  645. },
  646. });
  647. BlazeComponent.extendComponent({
  648. onCreated() {
  649. subManager.subscribe('board', Session.get('currentBoard'), false);
  650. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  651. },
  652. boards() {
  653. const boards = Boards.find(
  654. {
  655. archived: false,
  656. 'members.userId': Meteor.userId(),
  657. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  658. },
  659. {
  660. sort: { sort: 1 /* boards default sorting */ },
  661. },
  662. );
  663. return boards;
  664. },
  665. swimlanes() {
  666. const board = Boards.findOne(this.selectedBoardId.get());
  667. return board.swimlanes();
  668. },
  669. aBoardLists() {
  670. const board = Boards.findOne(this.selectedBoardId.get());
  671. return board.lists();
  672. },
  673. events() {
  674. return [
  675. {
  676. 'change .js-select-boards'(event) {
  677. this.selectedBoardId.set($(event.currentTarget).val());
  678. subManager.subscribe('board', this.selectedBoardId.get(), false);
  679. },
  680. },
  681. ];
  682. },
  683. }).register('boardsAndLists');
  684. Template.copyCardPopup.events({
  685. 'click .js-done'() {
  686. const card = Cards.findOne(Session.get('currentCard'));
  687. const lSelect = $('.js-select-lists')[0];
  688. listId = lSelect.options[lSelect.selectedIndex].value;
  689. const slSelect = $('.js-select-swimlanes')[0];
  690. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  691. const bSelect = $('.js-select-boards')[0];
  692. const boardId = bSelect.options[bSelect.selectedIndex].value;
  693. const textarea = $('#copy-card-title');
  694. const title = textarea.val().trim();
  695. // insert new card to the bottom of new list
  696. card.sort = Lists.findOne(card.listId)
  697. .cards()
  698. .count();
  699. if (title) {
  700. card.title = title;
  701. card.coverId = '';
  702. const _id = card.copy(boardId, swimlaneId, listId);
  703. // In case the filter is active we need to add the newly inserted card in
  704. // the list of exceptions -- cards that are not filtered. Otherwise the
  705. // card will disappear instantly.
  706. // See https://github.com/wekan/wekan/issues/80
  707. Filter.addException(_id);
  708. Popup.close();
  709. }
  710. },
  711. });
  712. Template.copyChecklistToManyCardsPopup.events({
  713. 'click .js-done'() {
  714. const card = Cards.findOne(Session.get('currentCard'));
  715. const oldId = card._id;
  716. card._id = null;
  717. const lSelect = $('.js-select-lists')[0];
  718. card.listId = lSelect.options[lSelect.selectedIndex].value;
  719. const slSelect = $('.js-select-swimlanes')[0];
  720. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  721. const bSelect = $('.js-select-boards')[0];
  722. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  723. const textarea = $('#copy-card-title');
  724. const titleEntry = textarea.val().trim();
  725. // insert new card to the bottom of new list
  726. card.sort = Lists.findOne(card.listId)
  727. .cards()
  728. .count();
  729. if (titleEntry) {
  730. const titleList = JSON.parse(titleEntry);
  731. for (let i = 0; i < titleList.length; i++) {
  732. const obj = titleList[i];
  733. card.title = obj.title;
  734. card.description = obj.description;
  735. card.coverId = '';
  736. const _id = Cards.insert(card);
  737. // In case the filter is active we need to add the newly inserted card in
  738. // the list of exceptions -- cards that are not filtered. Otherwise the
  739. // card will disappear instantly.
  740. // See https://github.com/wekan/wekan/issues/80
  741. Filter.addException(_id);
  742. // copy checklists
  743. Checklists.find({ cardId: oldId }).forEach(ch => {
  744. ch.copy(_id);
  745. });
  746. // copy subtasks
  747. cursor = Cards.find({ parentId: oldId });
  748. cursor.forEach(function() {
  749. 'use strict';
  750. const subtask = arguments[0];
  751. subtask.parentId = _id;
  752. subtask._id = null;
  753. /* const newSubtaskId = */ Cards.insert(subtask);
  754. });
  755. // copy card comments
  756. CardComments.find({ cardId: oldId }).forEach(cmt => {
  757. cmt.copy(_id);
  758. });
  759. }
  760. Popup.close();
  761. }
  762. },
  763. });
  764. BlazeComponent.extendComponent({
  765. onCreated() {
  766. this.currentCard = this.currentData();
  767. this.currentColor = new ReactiveVar(this.currentCard.color);
  768. },
  769. colors() {
  770. return cardColors.map(color => ({ color, name: '' }));
  771. },
  772. isSelected(color) {
  773. if (this.currentColor.get() === null) {
  774. return color === 'white';
  775. }
  776. return this.currentColor.get() === color;
  777. },
  778. events() {
  779. return [
  780. {
  781. 'click .js-palette-color'() {
  782. this.currentColor.set(this.currentData().color);
  783. },
  784. 'click .js-submit'() {
  785. this.currentCard.setColor(this.currentColor.get());
  786. Popup.close();
  787. },
  788. 'click .js-remove-color'() {
  789. this.currentCard.setColor(null);
  790. Popup.close();
  791. },
  792. },
  793. ];
  794. },
  795. }).register('setCardColorPopup');
  796. BlazeComponent.extendComponent({
  797. onCreated() {
  798. this.currentCard = this.currentData();
  799. this.parentBoard = new ReactiveVar(null);
  800. this.parentCard = this.currentCard.parentCard();
  801. if (this.parentCard) {
  802. const list = $('.js-field-parent-card');
  803. list.val(this.parentCard._id);
  804. this.parentBoard.set(this.parentCard.board()._id);
  805. } else {
  806. this.parentBoard.set(null);
  807. }
  808. },
  809. boards() {
  810. const boards = Boards.find(
  811. {
  812. archived: false,
  813. 'members.userId': Meteor.userId(),
  814. _id: {
  815. $ne: Meteor.user().getTemplatesBoardId(),
  816. },
  817. },
  818. {
  819. sort: { sort: 1 /* boards default sorting */ },
  820. },
  821. );
  822. return boards;
  823. },
  824. cards() {
  825. const currentId = Session.get('currentCard');
  826. if (this.parentBoard.get()) {
  827. return Cards.find({
  828. boardId: this.parentBoard.get(),
  829. _id: { $ne: currentId },
  830. });
  831. } else {
  832. return [];
  833. }
  834. },
  835. isParentBoard() {
  836. const board = this.currentData();
  837. if (this.parentBoard.get()) {
  838. return board._id === this.parentBoard.get();
  839. }
  840. return false;
  841. },
  842. isParentCard() {
  843. const card = this.currentData();
  844. if (this.parentCard) {
  845. return card._id === this.parentCard;
  846. }
  847. return false;
  848. },
  849. setParentCardId(cardId) {
  850. if (cardId) {
  851. this.parentCard = Cards.findOne(cardId);
  852. } else {
  853. this.parentCard = null;
  854. }
  855. this.currentCard.setParentId(cardId);
  856. },
  857. events() {
  858. return [
  859. {
  860. 'click .js-copy-card-link-to-clipboard'() {
  861. // Clipboard code from:
  862. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  863. const StringToCopyElement = document.getElementById('cardURL');
  864. StringToCopyElement.select();
  865. if (document.execCommand('copy')) {
  866. StringToCopyElement.blur();
  867. } else {
  868. document.getElementById('cardURL').selectionStart = 0;
  869. document.getElementById('cardURL').selectionEnd = 999;
  870. document.execCommand('copy');
  871. if (window.getSelection) {
  872. if (window.getSelection().empty) {
  873. // Chrome
  874. window.getSelection().empty();
  875. } else if (window.getSelection().removeAllRanges) {
  876. // Firefox
  877. window.getSelection().removeAllRanges();
  878. }
  879. } else if (document.selection) {
  880. // IE?
  881. document.selection.empty();
  882. }
  883. }
  884. },
  885. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  886. Popup.close();
  887. Cards.remove(this._id);
  888. Utils.goBoardId(this.boardId);
  889. }),
  890. 'change .js-field-parent-board'(event) {
  891. const selection = $(event.currentTarget).val();
  892. const list = $('.js-field-parent-card');
  893. if (selection === 'none') {
  894. this.parentBoard.set(null);
  895. } else {
  896. subManager.subscribe('board', $(event.currentTarget).val(), false);
  897. this.parentBoard.set(selection);
  898. list.prop('disabled', false);
  899. }
  900. this.setParentCardId(null);
  901. },
  902. 'change .js-field-parent-card'(event) {
  903. const selection = $(event.currentTarget).val();
  904. this.setParentCardId(selection);
  905. },
  906. },
  907. ];
  908. },
  909. }).register('cardMorePopup');
  910. BlazeComponent.extendComponent({
  911. onCreated() {
  912. this.currentCard = this.currentData();
  913. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  914. },
  915. events() {
  916. return [
  917. {
  918. 'submit .edit-vote-question'(evt) {
  919. evt.preventDefault();
  920. const voteQuestion = evt.target.vote.value;
  921. const publicVote = $('#vote-public').hasClass('is-checked');
  922. this.currentCard.setVoteQuestion(voteQuestion, publicVote);
  923. Popup.close();
  924. },
  925. 'click a.js-toggle-vote-public'(event) {
  926. event.preventDefault();
  927. $('#vote-public').toggleClass('is-checked');
  928. },
  929. },
  930. ];
  931. },
  932. }).register('cardStartVotingPopup');
  933. // Close the card details pane by pressing escape
  934. EscapeActions.register(
  935. 'detailsPane',
  936. () => {
  937. if (Session.get('cardDetailsIsDragging')) {
  938. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  939. Session.set('cardDetailsIsDragging', false);
  940. Session.set('cardDetailsIsMouseDown', false);
  941. } else {
  942. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  943. Utils.goBoardId(Session.get('currentBoard'));
  944. }
  945. },
  946. () => {
  947. return !Session.equals('currentCard', null);
  948. },
  949. {
  950. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  951. },
  952. );
  953. Template.cardAssigneesPopup.events({
  954. 'click .js-select-assignee'(event) {
  955. const card = Cards.findOne(Session.get('currentCard'));
  956. const assigneeId = this.userId;
  957. card.toggleAssignee(assigneeId);
  958. event.preventDefault();
  959. },
  960. });
  961. Template.cardAssigneesPopup.helpers({
  962. isCardAssignee() {
  963. const card = Template.parentData();
  964. const cardAssignees = card.getAssignees();
  965. return _.contains(cardAssignees, this.userId);
  966. },
  967. user() {
  968. return Users.findOne(this.userId);
  969. },
  970. });
  971. Template.cardAssigneePopup.helpers({
  972. userData() {
  973. // We need to handle a special case for the search results provided by the
  974. // `matteodem:easy-search` package. Since these results gets published in a
  975. // separate collection, and not in the standard Meteor.Users collection as
  976. // expected, we use a component parameter ("property") to distinguish the
  977. // two cases.
  978. const userCollection = this.esSearch ? ESSearchResults : Users;
  979. return userCollection.findOne(this.userId, {
  980. fields: {
  981. profile: 1,
  982. username: 1,
  983. },
  984. });
  985. },
  986. memberType() {
  987. const user = Users.findOne(this.userId);
  988. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  989. },
  990. presenceStatusClassName() {
  991. const user = Users.findOne(this.userId);
  992. const userPresence = presences.findOne({ userId: this.userId });
  993. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  994. else if (!userPresence) return 'disconnected';
  995. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  996. return 'active';
  997. else return 'idle';
  998. },
  999. isCardAssignee() {
  1000. const card = Template.parentData();
  1001. const cardAssignees = card.getAssignees();
  1002. return _.contains(cardAssignees, this.userId);
  1003. },
  1004. user() {
  1005. return Users.findOne(this.userId);
  1006. },
  1007. });
  1008. Template.cardAssigneePopup.events({
  1009. 'click .js-remove-assignee'() {
  1010. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1011. Popup.close();
  1012. },
  1013. 'click .js-edit-profile': Popup.open('editProfile'),
  1014. });