cardDetails.js 58 KB

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