cardDetails.js 32 KB

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