cardDetails.js 57 KB

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