cardDetails.js 32 KB

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