cardDetails.js 32 KB

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