cardDetails.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. import { DatePicker } from '/client/lib/datepicker';
  2. import Cards from '/models/cards';
  3. import Boards from '/models/boards';
  4. import Checklists from '/models/checklists';
  5. import Integrations from '/models/integrations';
  6. import Users from '/models/users';
  7. import Lists from '/models/lists';
  8. import CardComments from '/models/cardComments';
  9. import { ALLOWED_COLORS } from '/config/const';
  10. import moment from 'moment';
  11. import { UserAvatar } from '../users/userAvatar';
  12. const subManager = new SubsManager();
  13. const { calculateIndexData } = Utils;
  14. BlazeComponent.extendComponent({
  15. mixins() {
  16. return [Mixins.InfiniteScrolling];
  17. },
  18. calculateNextPeak() {
  19. const cardElement = this.find('.js-card-details');
  20. if (cardElement) {
  21. const altitude = cardElement.scrollHeight;
  22. this.callFirstWith(this, 'setNextPeak', altitude);
  23. }
  24. },
  25. reachNextPeak() {
  26. const activitiesComponent = this.childComponents('activities')[0];
  27. activitiesComponent.loadNextPage();
  28. },
  29. onCreated() {
  30. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  31. this.isLoaded = new ReactiveVar(false);
  32. const boardBody = this.parentComponent().parentComponent();
  33. //in Miniview parent is Board, not BoardBody.
  34. if (boardBody !== null) {
  35. boardBody.showOverlay.set(true);
  36. boardBody.mouseHasEnterCardDetails = false;
  37. }
  38. this.calculateNextPeak();
  39. Meteor.subscribe('unsaved-edits');
  40. },
  41. isWatching() {
  42. const card = this.currentData();
  43. return card.findWatcher(Meteor.userId());
  44. },
  45. hiddenSystemMessages() {
  46. return Meteor.user().hasHiddenSystemMessages();
  47. },
  48. cardMaximized() {
  49. return Meteor.user().hasCardMaximized();
  50. },
  51. canModifyCard() {
  52. return (
  53. Meteor.user() &&
  54. Meteor.user().isBoardMember() &&
  55. !Meteor.user().isCommentOnly() &&
  56. !Meteor.user().isWorker()
  57. );
  58. },
  59. scrollParentContainer() {
  60. const cardPanelWidth = 600;
  61. const parentComponent = this.parentComponent();
  62. // TODO sometimes parentComponent is not available, maybe because it's not
  63. // yet created?!
  64. if (!parentComponent) return;
  65. const bodyBoardComponent = parentComponent.parentComponent();
  66. //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
  67. if (bodyBoardComponent === null) return;
  68. const $cardView = this.$(this.firstNode());
  69. const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
  70. // TODO sometimes cardContainer is not available, maybe because it's not yet
  71. // created?!
  72. if (!$cardContainer) return;
  73. const cardContainerScroll = $cardContainer.scrollLeft();
  74. const cardContainerWidth = $cardContainer.width();
  75. const cardViewStart = $cardView.offset().left;
  76. const cardViewEnd = cardViewStart + cardPanelWidth;
  77. let offset = false;
  78. if (cardViewStart < 0) {
  79. offset = cardViewStart;
  80. } else if (cardViewEnd > cardContainerWidth) {
  81. offset = cardViewEnd - cardContainerWidth;
  82. }
  83. if (offset) {
  84. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  85. }
  86. //Scroll top
  87. const cardViewStartTop = $cardView.offset().top;
  88. const cardContainerScrollTop = $cardContainer.scrollTop();
  89. let topOffset = false;
  90. if (cardViewStartTop !== 100) {
  91. topOffset = cardViewStartTop - 100;
  92. }
  93. if (topOffset !== false) {
  94. bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
  95. }
  96. },
  97. presentParentTask() {
  98. let result = this.currentBoard.presentParentTask;
  99. if (result === null || result === undefined) {
  100. result = 'no-parent';
  101. }
  102. return result;
  103. },
  104. linkForCard() {
  105. const card = this.currentData();
  106. let result = '#';
  107. if (card) {
  108. const board = Boards.findOne(card.boardId);
  109. if (board) {
  110. result = FlowRouter.path('card', {
  111. boardId: card.boardId,
  112. slug: board.slug,
  113. cardId: card._id,
  114. });
  115. }
  116. }
  117. return result;
  118. },
  119. showVotingButtons() {
  120. const card = this.currentData();
  121. return (
  122. (currentUser.isBoardMember() ||
  123. (currentUser && card.voteAllowNonBoardMembers())) &&
  124. !card.expiredVote()
  125. );
  126. },
  127. showPlanningPokerButtons() {
  128. const card = this.currentData();
  129. return (
  130. (currentUser.isBoardMember() ||
  131. (currentUser && card.pokerAllowNonBoardMembers())) &&
  132. !card.expiredPoker()
  133. );
  134. },
  135. onRendered() {
  136. if (Meteor.settings.public.CARD_OPENED_WEBHOOK_ENABLED) {
  137. // Send Webhook but not create Activities records ---
  138. const card = this.currentData();
  139. const userId = Meteor.userId();
  140. const params = {
  141. userId,
  142. cardId: card._id,
  143. boardId: card.boardId,
  144. listId: card.listId,
  145. user: Meteor.user().username,
  146. url: '',
  147. };
  148. const integrations = Integrations.find({
  149. boardId: { $in: [card.boardId, Integrations.Const.GLOBAL_WEBHOOK_ID] },
  150. enabled: true,
  151. activities: { $in: ['CardDetailsRendered', 'all'] },
  152. }).fetch();
  153. if (integrations.length > 0) {
  154. integrations.forEach((integration) => {
  155. Meteor.call(
  156. 'outgoingWebhooks',
  157. integration,
  158. 'CardSelected',
  159. params,
  160. () => {},
  161. );
  162. });
  163. }
  164. //-------------
  165. }
  166. if (!Utils.isMiniScreen()) {
  167. Meteor.setTimeout(() => {
  168. this.scrollParentContainer();
  169. }, 500);
  170. }
  171. const $checklistsDom = this.$('.card-checklist-items');
  172. $checklistsDom.sortable({
  173. tolerance: 'pointer',
  174. helper: 'clone',
  175. handle: '.checklist-title',
  176. items: '.js-checklist',
  177. placeholder: 'checklist placeholder',
  178. distance: 7,
  179. start(evt, ui) {
  180. ui.placeholder.height(ui.helper.height());
  181. EscapeActions.executeUpTo('popup-close');
  182. },
  183. stop(evt, ui) {
  184. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  185. if (prevChecklist) {
  186. prevChecklist = Blaze.getData(prevChecklist).checklist;
  187. }
  188. let nextChecklist = ui.item.next('.js-checklist').get(0);
  189. if (nextChecklist) {
  190. nextChecklist = Blaze.getData(nextChecklist).checklist;
  191. }
  192. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  193. $checklistsDom.sortable('cancel');
  194. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  195. Checklists.update(checklist._id, {
  196. $set: {
  197. sort: sortIndex.base,
  198. },
  199. });
  200. },
  201. });
  202. const $subtasksDom = this.$('.card-subtasks-items');
  203. $subtasksDom.sortable({
  204. tolerance: 'pointer',
  205. helper: 'clone',
  206. handle: '.subtask-title',
  207. items: '.js-subtasks',
  208. placeholder: 'subtasks placeholder',
  209. distance: 7,
  210. start(evt, ui) {
  211. ui.placeholder.height(ui.helper.height());
  212. EscapeActions.executeUpTo('popup-close');
  213. },
  214. stop(evt, ui) {
  215. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  216. if (prevChecklist) {
  217. prevChecklist = Blaze.getData(prevChecklist).subtask;
  218. }
  219. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  220. if (nextChecklist) {
  221. nextChecklist = Blaze.getData(nextChecklist).subtask;
  222. }
  223. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  224. $subtasksDom.sortable('cancel');
  225. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  226. Subtasks.update(subtask._id, {
  227. $set: {
  228. subtaskSort: sortIndex.base,
  229. },
  230. });
  231. },
  232. });
  233. function userIsMember() {
  234. return Meteor.user() && Meteor.user().isBoardMember();
  235. }
  236. // Disable sorting if the current user is not a board member
  237. this.autorun(() => {
  238. const disabled = !userIsMember();
  239. if (
  240. $checklistsDom.data('uiSortable') ||
  241. $checklistsDom.data('sortable')
  242. ) {
  243. $checklistsDom.sortable('option', 'disabled', disabled);
  244. if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
  245. $checklistsDom.sortable({ handle: '.checklist-handle' });
  246. }
  247. }
  248. if ($subtasksDom.data('uiSortable') || $subtasksDom.data('sortable')) {
  249. $subtasksDom.sortable('option', 'disabled', disabled);
  250. }
  251. });
  252. },
  253. onDestroyed() {
  254. const parentComponent = this.parentComponent().parentComponent();
  255. //on mobile view parent is Board, not board body.
  256. if (parentComponent === null) return;
  257. parentComponent.showOverlay.set(false);
  258. },
  259. events() {
  260. const events = {
  261. [`${CSSEvents.transitionend} .js-card-details`]() {
  262. this.isLoaded.set(true);
  263. },
  264. [`${CSSEvents.animationend} .js-card-details`]() {
  265. this.isLoaded.set(true);
  266. },
  267. };
  268. return [
  269. {
  270. ...events,
  271. 'click .js-close-card-details'() {
  272. Utils.goBoardId(this.data().boardId);
  273. },
  274. 'click .js-copy-link'() {
  275. const StringToCopyElement = document.getElementById('cardURL_copy');
  276. StringToCopyElement.value =
  277. window.location.origin + window.location.pathname;
  278. StringToCopyElement.select();
  279. if (document.execCommand('copy')) {
  280. StringToCopyElement.blur();
  281. } else {
  282. document.getElementById('cardURL_copy').selectionStart = 0;
  283. document.getElementById('cardURL_copy').selectionEnd = 999;
  284. document.execCommand('copy');
  285. if (window.getSelection) {
  286. if (window.getSelection().empty) {
  287. // Chrome
  288. window.getSelection().empty();
  289. } else if (window.getSelection().removeAllRanges) {
  290. // Firefox
  291. window.getSelection().removeAllRanges();
  292. }
  293. } else if (document.selection) {
  294. // IE?
  295. document.selection.empty();
  296. }
  297. }
  298. },
  299. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  300. 'submit .js-card-description'(event) {
  301. event.preventDefault();
  302. const description = this.currentComponent().getValue();
  303. this.data().setDescription(description);
  304. },
  305. 'submit .js-card-details-title'(event) {
  306. event.preventDefault();
  307. const title = this.currentComponent().getValue().trim();
  308. if (title) {
  309. this.data().setTitle(title);
  310. } else {
  311. this.data().setTitle('');
  312. }
  313. },
  314. 'submit .js-card-details-assigner'(event) {
  315. event.preventDefault();
  316. const assigner = this.currentComponent().getValue().trim();
  317. if (assigner) {
  318. this.data().setAssignedBy(assigner);
  319. } else {
  320. this.data().setAssignedBy('');
  321. }
  322. },
  323. 'submit .js-card-details-requester'(event) {
  324. event.preventDefault();
  325. const requester = this.currentComponent().getValue().trim();
  326. if (requester) {
  327. this.data().setRequestedBy(requester);
  328. } else {
  329. this.data().setRequestedBy('');
  330. }
  331. },
  332. 'submit .js-card-details-sort'(event) {
  333. event.preventDefault();
  334. const sort = parseFloat(this.currentComponent()
  335. .getValue()
  336. .trim());
  337. if (!Number.isNaN(sort)) {
  338. let card = this.data();
  339. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  340. }
  341. },
  342. 'click .js-go-to-linked-card'() {
  343. Utils.goCardId(this.data().linkedId);
  344. },
  345. 'click .js-member': Popup.open('cardMember'),
  346. 'click .js-add-members': Popup.open('cardMembers'),
  347. 'click .js-assignee': Popup.open('cardAssignee'),
  348. 'click .js-add-assignees': Popup.open('cardAssignees'),
  349. 'click .js-add-labels': Popup.open('cardLabels'),
  350. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  351. 'click .js-start-date': Popup.open('editCardStartDate'),
  352. 'click .js-due-date': Popup.open('editCardDueDate'),
  353. 'click .js-end-date': Popup.open('editCardEndDate'),
  354. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  355. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  356. 'mouseenter .js-card-details'() {
  357. const parentComponent = this.parentComponent().parentComponent();
  358. //on mobile view parent is Board, not BoardBody.
  359. if (parentComponent === null) return;
  360. parentComponent.showOverlay.set(true);
  361. parentComponent.mouseHasEnterCardDetails = true;
  362. },
  363. 'mousedown .js-card-details'() {
  364. Session.set('cardDetailsIsDragging', false);
  365. Session.set('cardDetailsIsMouseDown', true);
  366. },
  367. 'mousemove .js-card-details'() {
  368. if (Session.get('cardDetailsIsMouseDown')) {
  369. Session.set('cardDetailsIsDragging', true);
  370. }
  371. },
  372. 'mouseup .js-card-details'() {
  373. Session.set('cardDetailsIsDragging', false);
  374. Session.set('cardDetailsIsMouseDown', false);
  375. },
  376. 'click #toggleButton'() {
  377. Meteor.call('toggleSystemMessages');
  378. },
  379. 'click .js-maximize-card-details'() {
  380. Meteor.call('toggleCardMaximized');
  381. autosize($('.card-details'));
  382. },
  383. 'click .js-minimize-card-details'() {
  384. Meteor.call('toggleCardMaximized');
  385. autosize($('.card-details'));
  386. },
  387. 'click .js-vote'(e) {
  388. const forIt = $(e.target).hasClass('js-vote-positive');
  389. let newState = null;
  390. if (
  391. this.data().voteState() === null ||
  392. (this.data().voteState() === false && forIt) ||
  393. (this.data().voteState() === true && !forIt)
  394. ) {
  395. newState = forIt;
  396. }
  397. this.data().setVote(Meteor.userId(), newState);
  398. },
  399. 'click .js-poker'(e) {
  400. let newState = null;
  401. if ($(e.target).hasClass('js-poker-vote-one')) {
  402. newState = 'one';
  403. this.data().setPoker(Meteor.userId(), newState);
  404. }
  405. if ($(e.target).hasClass('js-poker-vote-two')) {
  406. newState = 'two';
  407. this.data().setPoker(Meteor.userId(), newState);
  408. }
  409. if ($(e.target).hasClass('js-poker-vote-three')) {
  410. newState = 'three';
  411. this.data().setPoker(Meteor.userId(), newState);
  412. }
  413. if ($(e.target).hasClass('js-poker-vote-five')) {
  414. newState = 'five';
  415. this.data().setPoker(Meteor.userId(), newState);
  416. }
  417. if ($(e.target).hasClass('js-poker-vote-eight')) {
  418. newState = 'eight';
  419. this.data().setPoker(Meteor.userId(), newState);
  420. }
  421. if ($(e.target).hasClass('js-poker-vote-thirteen')) {
  422. newState = 'thirteen';
  423. this.data().setPoker(Meteor.userId(), newState);
  424. }
  425. if ($(e.target).hasClass('js-poker-vote-twenty')) {
  426. newState = 'twenty';
  427. this.data().setPoker(Meteor.userId(), newState);
  428. }
  429. if ($(e.target).hasClass('js-poker-vote-forty')) {
  430. newState = 'forty';
  431. this.data().setPoker(Meteor.userId(), newState);
  432. }
  433. if ($(e.target).hasClass('js-poker-vote-one-hundred')) {
  434. newState = 'oneHundred';
  435. this.data().setPoker(Meteor.userId(), newState);
  436. }
  437. if ($(e.target).hasClass('js-poker-vote-unsure')) {
  438. newState = 'unsure';
  439. this.data().setPoker(Meteor.userId(), newState);
  440. }
  441. },
  442. 'click .js-poker-finish'(e) {
  443. if ($(e.target).hasClass('js-poker-finish')) {
  444. e.preventDefault();
  445. const now = moment().format('YYYY-MM-DD HH:mm');
  446. this.data().setPokerEnd(now);
  447. }
  448. },
  449. 'click .js-poker-replay'(e) {
  450. if ($(e.target).hasClass('js-poker-replay')) {
  451. e.preventDefault();
  452. this.currentCard = this.currentData();
  453. this.currentCard.replayPoker();
  454. this.data().unsetPokerEnd();
  455. this.data().unsetPokerEstimation();
  456. }
  457. },
  458. 'click .js-poker-estimation'(event) {
  459. event.preventDefault();
  460. const ruleTitle = this.find('#pokerEstimation').value;
  461. if (ruleTitle !== undefined && ruleTitle !== '') {
  462. this.find('#pokerEstimation').value = '';
  463. if (ruleTitle) {
  464. this.data().setPokerEstimation(parseInt(ruleTitle, 10));
  465. } else {
  466. this.data().setPokerEstimation('');
  467. }
  468. }
  469. },
  470. },
  471. ];
  472. },
  473. }).register('cardDetails');
  474. BlazeComponent.extendComponent({
  475. template() {
  476. return 'exportCard';
  477. },
  478. withApi() {
  479. return Template.instance().apiEnabled.get();
  480. },
  481. exportUrlCardPDF() {
  482. const params = {
  483. boardId: Session.get('currentBoard'),
  484. listId: this.listId,
  485. cardId: this.cardId,
  486. };
  487. const queryParams = {
  488. authToken: Accounts._storedLoginToken(),
  489. };
  490. return FlowRouter.path(
  491. '/api/boards/:boardId/lists/:listId/cards/:cardId/exportPDF',
  492. params,
  493. queryParams,
  494. );
  495. },
  496. exportFilenameCardPDF() {
  497. //const boardId = Session.get('currentBoard');
  498. //return `export-card-pdf-${boardId}.xlsx`;
  499. return `export-card.pdf`;
  500. },
  501. }).register('exportCardPopup');
  502. // only allow number input
  503. Template.editCardSortOrderForm.onRendered(function() {
  504. this.$('input').on("keypress paste", function(event) {
  505. let keyCode = event.keyCode;
  506. let charCode = String.fromCharCode(keyCode);
  507. let regex = new RegExp('[-0-9.]');
  508. let ret = regex.test(charCode);
  509. // only working here, defining in events() doesn't handle the return value correctly
  510. return ret;
  511. });
  512. });
  513. // We extends the normal InlinedForm component to support UnsavedEdits draft
  514. // feature.
  515. (class extends InlinedForm {
  516. _getUnsavedEditKey() {
  517. return {
  518. fieldName: 'cardDescription',
  519. // XXX Recovering the currentCard identifier form a session variable is
  520. // fragile because this variable may change for instance if the route
  521. // change. We should use some component props instead.
  522. docId: Session.get('currentCard'),
  523. };
  524. }
  525. close(isReset = false) {
  526. if (this.isOpen.get() && !isReset) {
  527. const draft = this.getValue().trim();
  528. if (
  529. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  530. ) {
  531. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  532. }
  533. }
  534. super.close();
  535. }
  536. reset() {
  537. UnsavedEdits.reset(this._getUnsavedEditKey());
  538. this.close(true);
  539. }
  540. events() {
  541. const parentEvents = InlinedForm.prototype.events()[0];
  542. return [
  543. {
  544. ...parentEvents,
  545. 'click .js-close-inlined-form': this.reset,
  546. },
  547. ];
  548. }
  549. }.register('inlinedCardDescription'));
  550. Template.cardDetailsActionsPopup.helpers({
  551. isWatching() {
  552. return this.findWatcher(Meteor.userId());
  553. },
  554. isBoardAdmin() {
  555. return Meteor.user().isBoardAdmin();
  556. },
  557. canModifyCard() {
  558. return (
  559. Meteor.user() &&
  560. Meteor.user().isBoardMember() &&
  561. !Meteor.user().isCommentOnly()
  562. );
  563. },
  564. });
  565. Template.cardDetailsActionsPopup.events({
  566. 'click .js-export-card': Popup.open('exportCard'),
  567. 'click .js-members': Popup.open('cardMembers'),
  568. 'click .js-assignees': Popup.open('cardAssignees'),
  569. 'click .js-labels': Popup.open('cardLabels'),
  570. 'click .js-attachments': Popup.open('cardAttachments'),
  571. 'click .js-start-voting': Popup.open('cardStartVoting'),
  572. 'click .js-start-planning-poker': Popup.open('cardStartPlanningPoker'),
  573. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  574. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  575. 'click .js-start-date': Popup.open('editCardStartDate'),
  576. 'click .js-due-date': Popup.open('editCardDueDate'),
  577. 'click .js-end-date': Popup.open('editCardEndDate'),
  578. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  579. 'click .js-move-card': Popup.open('moveCard'),
  580. 'click .js-copy-card': Popup.open('copyCard'),
  581. 'click .js-convert-checklist-item-to-card': Popup.open('convertChecklistItemToCard'),
  582. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  583. 'click .js-set-card-color': Popup.open('setCardColor'),
  584. 'click .js-move-card-to-top'(event) {
  585. event.preventDefault();
  586. const minOrder = _.min(
  587. this.list()
  588. .cards(this.swimlaneId)
  589. .map((c) => c.sort),
  590. );
  591. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  592. },
  593. 'click .js-move-card-to-bottom'(event) {
  594. event.preventDefault();
  595. const maxOrder = _.max(
  596. this.list()
  597. .cards(this.swimlaneId)
  598. .map((c) => c.sort),
  599. );
  600. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  601. },
  602. 'click .js-archive'(event) {
  603. event.preventDefault();
  604. this.archive();
  605. Popup.close();
  606. },
  607. 'click .js-more': Popup.open('cardMore'),
  608. 'click .js-toggle-watch-card'() {
  609. const currentCard = this;
  610. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  611. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  612. if (!err && ret) Popup.close();
  613. });
  614. },
  615. });
  616. Template.editCardTitleForm.onRendered(function () {
  617. autosize(this.$('.js-edit-card-title'));
  618. });
  619. Template.editCardTitleForm.events({
  620. 'keydown .js-edit-card-title'(event) {
  621. // If enter key was pressed, submit the data
  622. // Unless the shift key is also being pressed
  623. if (event.keyCode === 13 && !event.shiftKey) {
  624. $('.js-submit-edit-card-title-form').click();
  625. }
  626. },
  627. });
  628. Template.editCardRequesterForm.onRendered(function () {
  629. autosize(this.$('.js-edit-card-requester'));
  630. });
  631. Template.editCardRequesterForm.events({
  632. 'keydown .js-edit-card-requester'(event) {
  633. // If enter key was pressed, submit the data
  634. if (event.keyCode === 13) {
  635. $('.js-submit-edit-card-requester-form').click();
  636. }
  637. },
  638. });
  639. Template.editCardAssignerForm.onRendered(function () {
  640. autosize(this.$('.js-edit-card-assigner'));
  641. });
  642. Template.editCardAssignerForm.events({
  643. 'keydown .js-edit-card-assigner'(event) {
  644. // If enter key was pressed, submit the data
  645. if (event.keyCode === 13) {
  646. $('.js-submit-edit-card-assigner-form').click();
  647. }
  648. },
  649. });
  650. Template.moveCardPopup.events({
  651. 'click .js-done'() {
  652. // XXX We should *not* get the currentCard from the global state, but
  653. // instead from a “component” state.
  654. const card = Cards.findOne(Session.get('currentCard'));
  655. const bSelect = $('.js-select-boards')[0];
  656. let boardId;
  657. // if we are a worker, we won't have a board select so we just use the
  658. // current boardId of the card.
  659. if (bSelect) boardId = bSelect.options[bSelect.selectedIndex].value;
  660. else boardId = card.boardId;
  661. const lSelect = $('.js-select-lists')[0];
  662. const listId = lSelect.options[lSelect.selectedIndex].value;
  663. const slSelect = $('.js-select-swimlanes')[0];
  664. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  665. card.move(boardId, swimlaneId, listId, 0);
  666. Popup.close();
  667. },
  668. });
  669. BlazeComponent.extendComponent({
  670. onCreated() {
  671. subManager.subscribe('board', Session.get('currentBoard'), false);
  672. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  673. },
  674. boards() {
  675. return Boards.find(
  676. {
  677. archived: false,
  678. 'members.userId': Meteor.userId(),
  679. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  680. },
  681. {
  682. sort: { sort: 1 /* boards default sorting */ },
  683. },
  684. );
  685. },
  686. swimlanes() {
  687. const board = Boards.findOne(this.selectedBoardId.get());
  688. return board.swimlanes();
  689. },
  690. aBoardLists() {
  691. const board = Boards.findOne(this.selectedBoardId.get());
  692. return board.lists();
  693. },
  694. events() {
  695. return [
  696. {
  697. 'change .js-select-boards'(event) {
  698. this.selectedBoardId.set($(event.currentTarget).val());
  699. subManager.subscribe('board', this.selectedBoardId.get(), false);
  700. },
  701. },
  702. ];
  703. },
  704. }).register('boardsAndLists');
  705. Template.copyCardPopup.events({
  706. 'click .js-done'() {
  707. const card = Cards.findOne(Session.get('currentCard'));
  708. const lSelect = $('.js-select-lists')[0];
  709. const listId = lSelect.options[lSelect.selectedIndex].value;
  710. const slSelect = $('.js-select-swimlanes')[0];
  711. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  712. const bSelect = $('.js-select-boards')[0];
  713. const boardId = bSelect.options[bSelect.selectedIndex].value;
  714. const textarea = $('#copy-card-title');
  715. const title = textarea.val().trim();
  716. // insert new card to the bottom of new list
  717. card.sort = Lists.findOne(card.listId).cards().count();
  718. if (title) {
  719. card.title = title;
  720. card.coverId = '';
  721. const _id = card.copy(boardId, swimlaneId, listId);
  722. // In case the filter is active we need to add the newly inserted card in
  723. // the list of exceptions -- cards that are not filtered. Otherwise the
  724. // card will disappear instantly.
  725. // See https://github.com/wekan/wekan/issues/80
  726. Filter.addException(_id);
  727. Popup.close();
  728. }
  729. },
  730. });
  731. Template.convertChecklistItemToCardPopup.events({
  732. 'click .js-done'() {
  733. const card = Cards.findOne(Session.get('currentCard'));
  734. const lSelect = $('.js-select-lists')[0];
  735. const listId = lSelect.options[lSelect.selectedIndex].value;
  736. const slSelect = $('.js-select-swimlanes')[0];
  737. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  738. const bSelect = $('.js-select-boards')[0];
  739. const boardId = bSelect.options[bSelect.selectedIndex].value;
  740. const textarea = $('#copy-card-title');
  741. const title = textarea.val().trim();
  742. if (title) {
  743. const _id = Cards.insert({
  744. title: title,
  745. listId: listId,
  746. boardId: boardId,
  747. swimlaneId: swimlaneId,
  748. sort: 0,
  749. });
  750. Filter.addException(_id);
  751. Popup.close();
  752. }
  753. },
  754. });
  755. Template.copyChecklistToManyCardsPopup.events({
  756. 'click .js-done'() {
  757. const card = Cards.findOne(Session.get('currentCard'));
  758. const oldId = card._id;
  759. card._id = null;
  760. const lSelect = $('.js-select-lists')[0];
  761. card.listId = lSelect.options[lSelect.selectedIndex].value;
  762. const slSelect = $('.js-select-swimlanes')[0];
  763. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  764. const bSelect = $('.js-select-boards')[0];
  765. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  766. const textarea = $('#copy-card-title');
  767. const titleEntry = textarea.val().trim();
  768. // insert new card to the bottom of new list
  769. card.sort = Lists.findOne(card.listId).cards().count();
  770. if (titleEntry) {
  771. const titleList = JSON.parse(titleEntry);
  772. for (let i = 0; i < titleList.length; i++) {
  773. const obj = titleList[i];
  774. card.title = obj.title;
  775. card.description = obj.description;
  776. card.coverId = '';
  777. const _id = Cards.insert(card);
  778. // In case the filter is active we need to add the newly inserted card in
  779. // the list of exceptions -- cards that are not filtered. Otherwise the
  780. // card will disappear instantly.
  781. // See https://github.com/wekan/wekan/issues/80
  782. Filter.addException(_id);
  783. // copy checklists
  784. Checklists.find({ cardId: oldId }).forEach((ch) => {
  785. ch.copy(_id);
  786. });
  787. // copy subtasks
  788. const cursor = Cards.find({ parentId: oldId });
  789. cursor.forEach(function () {
  790. 'use strict';
  791. const subtask = arguments[0];
  792. subtask.parentId = _id;
  793. subtask._id = null;
  794. /* const newSubtaskId = */ Cards.insert(subtask);
  795. });
  796. // copy card comments
  797. CardComments.find({ cardId: oldId }).forEach((cmt) => {
  798. cmt.copy(_id);
  799. });
  800. }
  801. Popup.close();
  802. }
  803. },
  804. });
  805. BlazeComponent.extendComponent({
  806. onCreated() {
  807. this.currentCard = this.currentData();
  808. this.currentColor = new ReactiveVar(this.currentCard.color);
  809. },
  810. colors() {
  811. return ALLOWED_COLORS.map((color) => ({ color, name: '' }));
  812. },
  813. isSelected(color) {
  814. if (this.currentColor.get() === null) {
  815. return color === 'white';
  816. }
  817. return this.currentColor.get() === color;
  818. },
  819. events() {
  820. return [
  821. {
  822. 'click .js-palette-color'() {
  823. this.currentColor.set(this.currentData().color);
  824. },
  825. 'click .js-submit'() {
  826. this.currentCard.setColor(this.currentColor.get());
  827. Popup.close();
  828. },
  829. 'click .js-remove-color'() {
  830. this.currentCard.setColor(null);
  831. Popup.close();
  832. },
  833. },
  834. ];
  835. },
  836. }).register('setCardColorPopup');
  837. BlazeComponent.extendComponent({
  838. onCreated() {
  839. this.currentCard = this.currentData();
  840. this.parentBoard = new ReactiveVar(null);
  841. this.parentCard = this.currentCard.parentCard();
  842. if (this.parentCard) {
  843. const list = $('.js-field-parent-card');
  844. list.val(this.parentCard._id);
  845. this.parentBoard.set(this.parentCard.board()._id);
  846. } else {
  847. this.parentBoard.set(null);
  848. }
  849. },
  850. boards() {
  851. return Boards.find(
  852. {
  853. archived: false,
  854. 'members.userId': Meteor.userId(),
  855. _id: {
  856. $ne: Meteor.user().getTemplatesBoardId(),
  857. },
  858. },
  859. {
  860. sort: { sort: 1 /* boards default sorting */ },
  861. },
  862. );
  863. },
  864. cards() {
  865. const currentId = Session.get('currentCard');
  866. if (this.parentBoard.get()) {
  867. return Cards.find({
  868. boardId: this.parentBoard.get(),
  869. _id: { $ne: currentId },
  870. });
  871. } else {
  872. return [];
  873. }
  874. },
  875. isParentBoard() {
  876. const board = this.currentData();
  877. if (this.parentBoard.get()) {
  878. return board._id === this.parentBoard.get();
  879. }
  880. return false;
  881. },
  882. isParentCard() {
  883. const card = this.currentData();
  884. if (this.parentCard) {
  885. return card._id === this.parentCard;
  886. }
  887. return false;
  888. },
  889. setParentCardId(cardId) {
  890. if (cardId) {
  891. this.parentCard = Cards.findOne(cardId);
  892. } else {
  893. this.parentCard = null;
  894. }
  895. this.currentCard.setParentId(cardId);
  896. },
  897. events() {
  898. return [
  899. {
  900. 'click .js-copy-card-link-to-clipboard'() {
  901. // Clipboard code from:
  902. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  903. const StringToCopyElement = document.getElementById('cardURL');
  904. StringToCopyElement.select();
  905. if (document.execCommand('copy')) {
  906. StringToCopyElement.blur();
  907. } else {
  908. document.getElementById('cardURL').selectionStart = 0;
  909. document.getElementById('cardURL').selectionEnd = 999;
  910. document.execCommand('copy');
  911. if (window.getSelection) {
  912. if (window.getSelection().empty) {
  913. // Chrome
  914. window.getSelection().empty();
  915. } else if (window.getSelection().removeAllRanges) {
  916. // Firefox
  917. window.getSelection().removeAllRanges();
  918. }
  919. } else if (document.selection) {
  920. // IE?
  921. document.selection.empty();
  922. }
  923. }
  924. },
  925. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  926. Popup.close();
  927. // verify that there are no linked cards
  928. if (Cards.find({ linkedId: this._id }).count() === 0) {
  929. Cards.remove(this._id);
  930. } else {
  931. // TODO: Maybe later we can list where the linked cards are.
  932. // Now here is popup with a hint that the card cannot be deleted
  933. // as there are linked cards.
  934. // Related:
  935. // client/components/lists/listHeader.js about line 248
  936. // https://github.com/wekan/wekan/issues/2785
  937. const message = `${TAPi18n.__(
  938. 'delete-linked-card-before-this-card',
  939. )} linkedId: ${
  940. this._id
  941. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  942. alert(message);
  943. }
  944. Utils.goBoardId(this.boardId);
  945. }),
  946. 'change .js-field-parent-board'(event) {
  947. const selection = $(event.currentTarget).val();
  948. const list = $('.js-field-parent-card');
  949. if (selection === 'none') {
  950. this.parentBoard.set(null);
  951. } else {
  952. subManager.subscribe('board', $(event.currentTarget).val(), false);
  953. this.parentBoard.set(selection);
  954. list.prop('disabled', false);
  955. }
  956. this.setParentCardId(null);
  957. },
  958. 'change .js-field-parent-card'(event) {
  959. const selection = $(event.currentTarget).val();
  960. this.setParentCardId(selection);
  961. },
  962. },
  963. ];
  964. },
  965. }).register('cardMorePopup');
  966. BlazeComponent.extendComponent({
  967. onCreated() {
  968. this.currentCard = this.currentData();
  969. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  970. },
  971. events() {
  972. return [
  973. {
  974. 'click .js-end-date': Popup.open('editVoteEndDate'),
  975. 'submit .edit-vote-question'(evt) {
  976. evt.preventDefault();
  977. const voteQuestion = evt.target.vote.value;
  978. const publicVote = $('#vote-public').hasClass('is-checked');
  979. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  980. 'is-checked',
  981. );
  982. const endString = this.currentCard.getVoteEnd();
  983. this.currentCard.setVoteQuestion(
  984. voteQuestion,
  985. publicVote,
  986. allowNonBoardMembers,
  987. );
  988. if (endString) {
  989. this.currentCard.setVoteEnd(endString);
  990. }
  991. Popup.close();
  992. },
  993. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  994. event.preventDefault();
  995. this.currentCard.unsetVote();
  996. Popup.close();
  997. }),
  998. 'click a.js-toggle-vote-public'(event) {
  999. event.preventDefault();
  1000. $('#vote-public').toggleClass('is-checked');
  1001. },
  1002. 'click a.js-toggle-vote-allow-non-members'(event) {
  1003. event.preventDefault();
  1004. $('#vote-allow-non-members').toggleClass('is-checked');
  1005. },
  1006. },
  1007. ];
  1008. },
  1009. }).register('cardStartVotingPopup');
  1010. // editVoteEndDatePopup
  1011. (class extends DatePicker {
  1012. onCreated() {
  1013. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1014. this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
  1015. }
  1016. events() {
  1017. return [
  1018. {
  1019. 'submit .edit-date'(evt) {
  1020. evt.preventDefault();
  1021. // if no time was given, init with 12:00
  1022. const time =
  1023. evt.target.time.value ||
  1024. moment(new Date().setHours(12, 0, 0)).format('LT');
  1025. const dateString = `${evt.target.date.value} ${time}`;
  1026. /*
  1027. const newDate = moment(dateString, 'L LT', true);
  1028. if (newDate.isValid()) {
  1029. // if active vote - store it
  1030. if (this.currentData().getVoteQuestion()) {
  1031. this._storeDate(newDate.toDate());
  1032. Popup.close();
  1033. } else {
  1034. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  1035. Popup.back();
  1036. }
  1037. */
  1038. // Try to parse different date formats of all languages.
  1039. // This code is same for vote and planning poker.
  1040. const usaDate = moment(dateString, 'L LT', true);
  1041. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1042. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1043. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1044. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1045. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1046. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1047. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1048. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1049. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1050. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1051. // greekDate does not work: el Greek Ελληνικά ,
  1052. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1053. // where MM is maybe some text like AM/PM ?
  1054. // Also some other languages that have non-ascii characters in dates
  1055. // do not work.
  1056. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1057. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1058. if (usaDate.isValid()) {
  1059. // if active poker - store it
  1060. if (this.currentData().getPokerQuestion()) {
  1061. this._storeDate(usaDate.toDate());
  1062. Popup.close();
  1063. } else {
  1064. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1065. Popup.back();
  1066. }
  1067. } else if (euroAmDate.isValid()) {
  1068. // if active poker - store it
  1069. if (this.currentData().getPokerQuestion()) {
  1070. this._storeDate(euroAmDate.toDate());
  1071. Popup.close();
  1072. } else {
  1073. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1074. Popup.back();
  1075. }
  1076. } else if (euro24hDate.isValid()) {
  1077. // if active poker - store it
  1078. if (this.currentData().getPokerQuestion()) {
  1079. this._storeDate(euro24hDate.toDate());
  1080. this.card.setPokerEnd(euro24hDate.toDate());
  1081. Popup.close();
  1082. } else {
  1083. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1084. Popup.back();
  1085. }
  1086. } else if (eurodotDate.isValid()) {
  1087. // if active poker - store it
  1088. if (this.currentData().getPokerQuestion()) {
  1089. this._storeDate(eurodotDate.toDate());
  1090. this.card.setPokerEnd(eurodotDate.toDate());
  1091. Popup.close();
  1092. } else {
  1093. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1094. Popup.back();
  1095. }
  1096. } else if (minusDate.isValid()) {
  1097. // if active poker - store it
  1098. if (this.currentData().getPokerQuestion()) {
  1099. this._storeDate(minusDate.toDate());
  1100. this.card.setPokerEnd(minusDate.toDate());
  1101. Popup.close();
  1102. } else {
  1103. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1104. Popup.back();
  1105. }
  1106. } else if (slashDate.isValid()) {
  1107. // if active poker - store it
  1108. if (this.currentData().getPokerQuestion()) {
  1109. this._storeDate(slashDate.toDate());
  1110. this.card.setPokerEnd(slashDate.toDate());
  1111. Popup.close();
  1112. } else {
  1113. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1114. Popup.back();
  1115. }
  1116. } else if (dotDate.isValid()) {
  1117. // if active poker - store it
  1118. if (this.currentData().getPokerQuestion()) {
  1119. this._storeDate(dotDate.toDate());
  1120. this.card.setPokerEnd(dotDate.toDate());
  1121. Popup.close();
  1122. } else {
  1123. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1124. Popup.back();
  1125. }
  1126. } else if (brezhonegDate.isValid()) {
  1127. // if active poker - store it
  1128. if (this.currentData().getPokerQuestion()) {
  1129. this._storeDate(brezhonegDate.toDate());
  1130. this.card.setPokerEnd(brezhonegDate.toDate());
  1131. Popup.close();
  1132. } else {
  1133. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1134. Popup.back();
  1135. }
  1136. } else if (hrvatskiDate.isValid()) {
  1137. // if active poker - store it
  1138. if (this.currentData().getPokerQuestion()) {
  1139. this._storeDate(hrvatskiDate.toDate());
  1140. this.card.setPokerEnd(hrvatskiDate.toDate());
  1141. Popup.close();
  1142. } else {
  1143. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1144. Popup.back();
  1145. }
  1146. } else if (latviaDate.isValid()) {
  1147. // if active poker - store it
  1148. if (this.currentData().getPokerQuestion()) {
  1149. this._storeDate(latviaDate.toDate());
  1150. this.card.setPokerEnd(latviaDate.toDate());
  1151. Popup.close();
  1152. } else {
  1153. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1154. Popup.back();
  1155. }
  1156. } else if (nederlandsDate.isValid()) {
  1157. // if active poker - store it
  1158. if (this.currentData().getPokerQuestion()) {
  1159. this._storeDate(nederlandsDate.toDate());
  1160. this.card.setPokerEnd(nederlandsDate.toDate());
  1161. Popup.close();
  1162. } else {
  1163. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1164. Popup.back();
  1165. }
  1166. } else if (greekDate.isValid()) {
  1167. // if active poker - store it
  1168. if (this.currentData().getPokerQuestion()) {
  1169. this._storeDate(greekDate.toDate());
  1170. this.card.setPokerEnd(greekDate.toDate());
  1171. Popup.close();
  1172. } else {
  1173. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1174. Popup.back();
  1175. }
  1176. } else if (macedonianDate.isValid()) {
  1177. // if active poker - store it
  1178. if (this.currentData().getPokerQuestion()) {
  1179. this._storeDate(macedonianDate.toDate());
  1180. this.card.setPokerEnd(macedonianDate.toDate());
  1181. Popup.close();
  1182. } else {
  1183. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1184. Popup.back();
  1185. }
  1186. } else {
  1187. this.error.set('invalid-date');
  1188. evt.target.date.focus();
  1189. }
  1190. },
  1191. 'click .js-delete-date'(evt) {
  1192. evt.preventDefault();
  1193. this._deleteDate();
  1194. Popup.close();
  1195. },
  1196. },
  1197. ];
  1198. }
  1199. _storeDate(newDate) {
  1200. this.card.setVoteEnd(newDate);
  1201. }
  1202. _deleteDate() {
  1203. this.card.unsetVoteEnd();
  1204. }
  1205. }.register('editVoteEndDatePopup'));
  1206. BlazeComponent.extendComponent({
  1207. onCreated() {
  1208. this.currentCard = this.currentData();
  1209. this.pokerQuestion = new ReactiveVar(this.currentCard.pokerQuestion);
  1210. },
  1211. events() {
  1212. return [
  1213. {
  1214. 'click .js-end-date': Popup.open('editPokerEndDate'),
  1215. 'submit .edit-poker-question'(evt) {
  1216. evt.preventDefault();
  1217. const pokerQuestion = true;
  1218. const allowNonBoardMembers = $('#poker-allow-non-members').hasClass(
  1219. 'is-checked',
  1220. );
  1221. const endString = this.currentCard.getPokerEnd();
  1222. this.currentCard.setPokerQuestion(
  1223. pokerQuestion,
  1224. allowNonBoardMembers,
  1225. );
  1226. if (endString) {
  1227. this.currentCard.setPokerEnd(endString);
  1228. }
  1229. Popup.close();
  1230. },
  1231. 'click .js-remove-poker': Popup.afterConfirm('deletePoker', (event) => {
  1232. this.currentCard.unsetPoker();
  1233. Popup.close();
  1234. }),
  1235. 'click a.js-toggle-poker-allow-non-members'(event) {
  1236. event.preventDefault();
  1237. $('#poker-allow-non-members').toggleClass('is-checked');
  1238. },
  1239. },
  1240. ];
  1241. },
  1242. }).register('cardStartPlanningPokerPopup');
  1243. // editPokerEndDatePopup
  1244. (class extends DatePicker {
  1245. onCreated() {
  1246. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1247. this.data().getPokerEnd() &&
  1248. this.date.set(moment(this.data().getPokerEnd()));
  1249. }
  1250. /*
  1251. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1252. to make detecting all date formats not necessary,
  1253. but got error "language mk does not exist".
  1254. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1255. datepicker format that could be used to detect date format?
  1256. dateFormat() {
  1257. return moment.localeData().longDateFormat('L');
  1258. }
  1259. timeFormat() {
  1260. return moment.localeData().longDateFormat('LT');
  1261. }
  1262. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1263. */
  1264. events() {
  1265. return [
  1266. {
  1267. 'submit .edit-date'(evt) {
  1268. evt.preventDefault();
  1269. // if no time was given, init with 12:00
  1270. const time =
  1271. evt.target.time.value ||
  1272. moment(new Date().setHours(12, 0, 0)).format('LT');
  1273. const dateString = `${evt.target.date.value} ${time}`;
  1274. /*
  1275. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1276. to make detecting all date formats not necessary,
  1277. but got error "language mk does not exist".
  1278. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1279. datepicker format that could be used to detect date format?
  1280. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1281. if (newDate.isValid()) {
  1282. // if active poker - store it
  1283. if (this.currentData().getPokerQuestion()) {
  1284. this._storeDate(newDate.toDate());
  1285. Popup.close();
  1286. } else {
  1287. this.currentData().poker = { end: newDate.toDate() }; // set poker end temp
  1288. Popup.back();
  1289. }
  1290. */
  1291. // Try to parse different date formats of all languages.
  1292. // This code is same for vote and planning poker.
  1293. const usaDate = moment(dateString, 'L LT', true);
  1294. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1295. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1296. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1297. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1298. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1299. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1300. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1301. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1302. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1303. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1304. // greekDate does not work: el Greek Ελληνικά ,
  1305. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1306. // where MM is maybe some text like AM/PM ?
  1307. // Also some other languages that have non-ascii characters in dates
  1308. // do not work.
  1309. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1310. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1311. if (usaDate.isValid()) {
  1312. // if active poker - store it
  1313. if (this.currentData().getPokerQuestion()) {
  1314. this._storeDate(usaDate.toDate());
  1315. Popup.close();
  1316. } else {
  1317. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1318. Popup.back();
  1319. }
  1320. } else if (euroAmDate.isValid()) {
  1321. // if active poker - store it
  1322. if (this.currentData().getPokerQuestion()) {
  1323. this._storeDate(euroAmDate.toDate());
  1324. Popup.close();
  1325. } else {
  1326. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1327. Popup.back();
  1328. }
  1329. } else if (euro24hDate.isValid()) {
  1330. // if active poker - store it
  1331. if (this.currentData().getPokerQuestion()) {
  1332. this._storeDate(euro24hDate.toDate());
  1333. this.card.setPokerEnd(euro24hDate.toDate());
  1334. Popup.close();
  1335. } else {
  1336. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1337. Popup.back();
  1338. }
  1339. } else if (eurodotDate.isValid()) {
  1340. // if active poker - store it
  1341. if (this.currentData().getPokerQuestion()) {
  1342. this._storeDate(eurodotDate.toDate());
  1343. this.card.setPokerEnd(eurodotDate.toDate());
  1344. Popup.close();
  1345. } else {
  1346. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1347. Popup.back();
  1348. }
  1349. } else if (minusDate.isValid()) {
  1350. // if active poker - store it
  1351. if (this.currentData().getPokerQuestion()) {
  1352. this._storeDate(minusDate.toDate());
  1353. this.card.setPokerEnd(minusDate.toDate());
  1354. Popup.close();
  1355. } else {
  1356. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1357. Popup.back();
  1358. }
  1359. } else if (slashDate.isValid()) {
  1360. // if active poker - store it
  1361. if (this.currentData().getPokerQuestion()) {
  1362. this._storeDate(slashDate.toDate());
  1363. this.card.setPokerEnd(slashDate.toDate());
  1364. Popup.close();
  1365. } else {
  1366. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1367. Popup.back();
  1368. }
  1369. } else if (dotDate.isValid()) {
  1370. // if active poker - store it
  1371. if (this.currentData().getPokerQuestion()) {
  1372. this._storeDate(dotDate.toDate());
  1373. this.card.setPokerEnd(dotDate.toDate());
  1374. Popup.close();
  1375. } else {
  1376. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1377. Popup.back();
  1378. }
  1379. } else if (brezhonegDate.isValid()) {
  1380. // if active poker - store it
  1381. if (this.currentData().getPokerQuestion()) {
  1382. this._storeDate(brezhonegDate.toDate());
  1383. this.card.setPokerEnd(brezhonegDate.toDate());
  1384. Popup.close();
  1385. } else {
  1386. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1387. Popup.back();
  1388. }
  1389. } else if (hrvatskiDate.isValid()) {
  1390. // if active poker - store it
  1391. if (this.currentData().getPokerQuestion()) {
  1392. this._storeDate(hrvatskiDate.toDate());
  1393. this.card.setPokerEnd(hrvatskiDate.toDate());
  1394. Popup.close();
  1395. } else {
  1396. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1397. Popup.back();
  1398. }
  1399. } else if (latviaDate.isValid()) {
  1400. // if active poker - store it
  1401. if (this.currentData().getPokerQuestion()) {
  1402. this._storeDate(latviaDate.toDate());
  1403. this.card.setPokerEnd(latviaDate.toDate());
  1404. Popup.close();
  1405. } else {
  1406. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1407. Popup.back();
  1408. }
  1409. } else if (nederlandsDate.isValid()) {
  1410. // if active poker - store it
  1411. if (this.currentData().getPokerQuestion()) {
  1412. this._storeDate(nederlandsDate.toDate());
  1413. this.card.setPokerEnd(nederlandsDate.toDate());
  1414. Popup.close();
  1415. } else {
  1416. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1417. Popup.back();
  1418. }
  1419. } else if (greekDate.isValid()) {
  1420. // if active poker - store it
  1421. if (this.currentData().getPokerQuestion()) {
  1422. this._storeDate(greekDate.toDate());
  1423. this.card.setPokerEnd(greekDate.toDate());
  1424. Popup.close();
  1425. } else {
  1426. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1427. Popup.back();
  1428. }
  1429. } else if (macedonianDate.isValid()) {
  1430. // if active poker - store it
  1431. if (this.currentData().getPokerQuestion()) {
  1432. this._storeDate(macedonianDate.toDate());
  1433. this.card.setPokerEnd(macedonianDate.toDate());
  1434. Popup.close();
  1435. } else {
  1436. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1437. Popup.back();
  1438. }
  1439. } else {
  1440. // this.error.set('invalid-date);
  1441. this.error.set('invalid-date' + ' ' + dateString);
  1442. evt.target.date.focus();
  1443. }
  1444. },
  1445. 'click .js-delete-date'(evt) {
  1446. evt.preventDefault();
  1447. this._deleteDate();
  1448. Popup.close();
  1449. },
  1450. },
  1451. ];
  1452. }
  1453. _storeDate(newDate) {
  1454. this.card.setPokerEnd(newDate);
  1455. }
  1456. _deleteDate() {
  1457. this.card.unsetPokerEnd();
  1458. }
  1459. }.register('editPokerEndDatePopup'));
  1460. // Close the card details pane by pressing escape
  1461. EscapeActions.register(
  1462. 'detailsPane',
  1463. () => {
  1464. if (Session.get('cardDetailsIsDragging')) {
  1465. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1466. Session.set('cardDetailsIsDragging', false);
  1467. Session.set('cardDetailsIsMouseDown', false);
  1468. } else {
  1469. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1470. Utils.goBoardId(Session.get('currentBoard'));
  1471. }
  1472. },
  1473. () => {
  1474. return !Session.equals('currentCard', null);
  1475. },
  1476. {
  1477. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1478. },
  1479. );
  1480. Template.cardAssigneesPopup.events({
  1481. 'click .js-select-assignee'(event) {
  1482. const card = Cards.findOne(Session.get('currentCard'));
  1483. const assigneeId = this.userId;
  1484. card.toggleAssignee(assigneeId);
  1485. event.preventDefault();
  1486. },
  1487. });
  1488. Template.cardAssigneesPopup.helpers({
  1489. isCardAssignee() {
  1490. const card = Template.parentData();
  1491. const cardAssignees = card.getAssignees();
  1492. return _.contains(cardAssignees, this.userId);
  1493. },
  1494. user() {
  1495. return Users.findOne(this.userId);
  1496. },
  1497. });
  1498. Template.cardAssigneePopup.helpers({
  1499. userData() {
  1500. // We need to handle a special case for the search results provided by the
  1501. // `matteodem:easy-search` package. Since these results gets published in a
  1502. // separate collection, and not in the standard Meteor.Users collection as
  1503. // expected, we use a component parameter ("property") to distinguish the
  1504. // two cases.
  1505. const userCollection = this.esSearch ? ESSearchResults : Users;
  1506. return userCollection.findOne(this.userId, {
  1507. fields: {
  1508. profile: 1,
  1509. username: 1,
  1510. },
  1511. });
  1512. },
  1513. memberType() {
  1514. const user = Users.findOne(this.userId);
  1515. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1516. },
  1517. presenceStatusClassName() {
  1518. const user = Users.findOne(this.userId);
  1519. const userPresence = presences.findOne({ userId: this.userId });
  1520. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1521. else if (!userPresence) return 'disconnected';
  1522. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1523. return 'active';
  1524. else return 'idle';
  1525. },
  1526. isCardAssignee() {
  1527. const card = Template.parentData();
  1528. const cardAssignees = card.getAssignees();
  1529. return _.contains(cardAssignees, this.userId);
  1530. },
  1531. user() {
  1532. return Users.findOne(this.userId);
  1533. },
  1534. });
  1535. Template.cardAssigneePopup.events({
  1536. 'click .js-remove-assignee'() {
  1537. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1538. Popup.close();
  1539. },
  1540. 'click .js-edit-profile': Popup.open('editProfile'),
  1541. });