cardDetails.js 32 KB

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