cardDetails.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  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. .cardsUnfiltered(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. .cardsUnfiltered(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. BlazeComponent.extendComponent({
  637. onRendered() {
  638. autosize(this.$('textarea.js-edit-card-title'));
  639. },
  640. events() {
  641. return [
  642. {
  643. 'click a.fa.fa-copy'(event) {
  644. const $editor = this.$('textarea');
  645. const promise = Utils.copyTextToClipboard($editor[0].value);
  646. const $tooltip = this.$('.copied-tooltip');
  647. Utils.showCopied(promise, $tooltip);
  648. },
  649. 'keydown .js-edit-card-title'(event) {
  650. // If enter key was pressed, submit the data
  651. // Unless the shift key is also being pressed
  652. if (event.keyCode === 13 && !event.shiftKey) {
  653. $('.js-submit-edit-card-title-form').click();
  654. }
  655. },
  656. }
  657. ];
  658. }
  659. }).register('editCardTitleForm');
  660. Template.cardMembersPopup.onCreated(function () {
  661. let currBoard = Boards.findOne(Session.get('currentBoard'));
  662. let members = currBoard.activeMembers();
  663. // let query = {
  664. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  665. // };
  666. // let boardTeamUsers = Users.find(query, {
  667. // sort: { sort: 1 },
  668. // });
  669. // members = currBoard.activeMembers2(members, boardTeamUsers);
  670. this.members = new ReactiveVar(members);
  671. });
  672. Template.cardMembersPopup.events({
  673. 'keyup .card-members-filter'(event) {
  674. const members = filterMembers(event.target.value);
  675. Template.instance().members.set(members);
  676. }
  677. });
  678. Template.cardMembersPopup.helpers({
  679. members() {
  680. return Template.instance().members.get();
  681. },
  682. });
  683. const filterMembers = (filterTerm) => {
  684. let currBoard = Boards.findOne(Session.get('currentBoard'));
  685. let members = currBoard.activeMembers();
  686. // let query = {
  687. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  688. // };
  689. // let boardTeamUsers = Users.find(query, {
  690. // sort: { sort: 1 },
  691. // });
  692. // members = currBoard.activeMembers2(members, boardTeamUsers);
  693. if (filterTerm) {
  694. members = members
  695. .map(member => ({
  696. member,
  697. user: Users.findOne(member.userId)
  698. }))
  699. .filter(({ user }) =>
  700. (user.profile.fullname !== undefined && user.profile.fullname.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  701. || user.profile.fullname === undefined && user.profile.username !== undefined && user.profile.username.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  702. .map(({ member }) => member);
  703. }
  704. return members;
  705. }
  706. Template.editCardRequesterForm.onRendered(function () {
  707. autosize(this.$('.js-edit-card-requester'));
  708. });
  709. Template.editCardRequesterForm.events({
  710. 'keydown .js-edit-card-requester'(event) {
  711. // If enter key was pressed, submit the data
  712. if (event.keyCode === 13) {
  713. $('.js-submit-edit-card-requester-form').click();
  714. }
  715. },
  716. });
  717. Template.editCardAssignerForm.onRendered(function () {
  718. autosize(this.$('.js-edit-card-assigner'));
  719. });
  720. Template.editCardAssignerForm.events({
  721. 'keydown .js-edit-card-assigner'(event) {
  722. // If enter key was pressed, submit the data
  723. if (event.keyCode === 13) {
  724. $('.js-submit-edit-card-assigner-form').click();
  725. }
  726. },
  727. });
  728. Template.moveCardPopup.events({
  729. 'click .js-done'() {
  730. // XXX We should *not* get the currentCard from the global state, but
  731. // instead from a “component” state.
  732. const card = Utils.getCurrentCard();
  733. const bSelect = $('.js-select-boards')[0];
  734. let boardId;
  735. // if we are a worker, we won't have a board select so we just use the
  736. // current boardId of the card.
  737. if (bSelect) boardId = bSelect.options[bSelect.selectedIndex].value;
  738. else boardId = card.boardId;
  739. const lSelect = $('.js-select-lists')[0];
  740. const listId = lSelect.options[lSelect.selectedIndex].value;
  741. const slSelect = $('.js-select-swimlanes')[0];
  742. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  743. card.move(boardId, swimlaneId, listId, 0);
  744. // 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)
  745. this.boardId = boardId;
  746. this.swimlaneId = swimlaneId;
  747. this.listId = listId;
  748. Popup.back();
  749. },
  750. });
  751. BlazeComponent.extendComponent({
  752. onCreated() {
  753. subManager.subscribe('board', Session.get('currentBoard'), false);
  754. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  755. },
  756. boards() {
  757. return Boards.find(
  758. {
  759. archived: false,
  760. 'members.userId': Meteor.userId(),
  761. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  762. },
  763. {
  764. sort: { sort: 1 /* boards default sorting */ },
  765. },
  766. );
  767. },
  768. swimlanes() {
  769. const board = Boards.findOne(this.selectedBoardId.get());
  770. return board.swimlanes();
  771. },
  772. aBoardLists() {
  773. const board = Boards.findOne(this.selectedBoardId.get());
  774. return board.lists();
  775. },
  776. events() {
  777. return [
  778. {
  779. 'change .js-select-boards'(event) {
  780. this.selectedBoardId.set($(event.currentTarget).val());
  781. subManager.subscribe('board', this.selectedBoardId.get(), false);
  782. },
  783. },
  784. ];
  785. },
  786. }).register('boardsAndLists');
  787. Template.copyCardPopup.events({
  788. 'click .js-done'() {
  789. const card = Utils.getCurrentCard();
  790. const lSelect = $('.js-select-lists')[0];
  791. const listId = lSelect.options[lSelect.selectedIndex].value;
  792. const slSelect = $('.js-select-swimlanes')[0];
  793. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  794. const bSelect = $('.js-select-boards')[0];
  795. const boardId = bSelect.options[bSelect.selectedIndex].value;
  796. const textarea = $('#copy-card-title');
  797. const title = textarea.val().trim();
  798. // insert new card to the bottom of new list
  799. card.sort = Lists.findOne(card.listId).cards().count();
  800. if (title) {
  801. card.title = title;
  802. card.coverId = '';
  803. const _id = card.copy(boardId, swimlaneId, listId);
  804. // In case the filter is active we need to add the newly inserted card in
  805. // the list of exceptions -- cards that are not filtered. Otherwise the
  806. // card will disappear instantly.
  807. // See https://github.com/wekan/wekan/issues/80
  808. Filter.addException(_id);
  809. Popup.back();
  810. }
  811. },
  812. });
  813. Template.convertChecklistItemToCardPopup.events({
  814. 'click .js-done'() {
  815. const card = Utils.getCurrentCard();
  816. const lSelect = $('.js-select-lists')[0];
  817. const listId = lSelect.options[lSelect.selectedIndex].value;
  818. const slSelect = $('.js-select-swimlanes')[0];
  819. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  820. const bSelect = $('.js-select-boards')[0];
  821. const boardId = bSelect.options[bSelect.selectedIndex].value;
  822. const textarea = $('#copy-card-title');
  823. const title = textarea.val().trim();
  824. if (title) {
  825. const _id = Cards.insert({
  826. title: title,
  827. listId: listId,
  828. boardId: boardId,
  829. swimlaneId: swimlaneId,
  830. sort: 0,
  831. });
  832. Filter.addException(_id);
  833. Popup.back();
  834. }
  835. },
  836. });
  837. Template.copyChecklistToManyCardsPopup.events({
  838. 'click .js-done'() {
  839. const card = Utils.getCurrentCard();
  840. const oldId = card._id;
  841. card._id = null;
  842. const lSelect = $('.js-select-lists')[0];
  843. card.listId = lSelect.options[lSelect.selectedIndex].value;
  844. const slSelect = $('.js-select-swimlanes')[0];
  845. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  846. const bSelect = $('.js-select-boards')[0];
  847. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  848. const textarea = $('#copy-card-title');
  849. const titleEntry = textarea.val().trim();
  850. // insert new card to the bottom of new list
  851. card.sort = Lists.findOne(card.listId).cards().count();
  852. if (titleEntry) {
  853. const titleList = JSON.parse(titleEntry);
  854. for (let i = 0; i < titleList.length; i++) {
  855. const obj = titleList[i];
  856. card.title = obj.title;
  857. card.description = obj.description;
  858. card.coverId = '';
  859. const _id = Cards.insert(card);
  860. // In case the filter is active we need to add the newly inserted card in
  861. // the list of exceptions -- cards that are not filtered. Otherwise the
  862. // card will disappear instantly.
  863. // See https://github.com/wekan/wekan/issues/80
  864. Filter.addException(_id);
  865. // copy checklists
  866. Checklists.find({ cardId: oldId }).forEach((ch) => {
  867. ch.copy(_id);
  868. });
  869. // copy subtasks
  870. const cursor = Cards.find({ parentId: oldId });
  871. cursor.forEach(function () {
  872. 'use strict';
  873. const subtask = arguments[0];
  874. subtask.parentId = _id;
  875. subtask._id = null;
  876. /* const newSubtaskId = */ Cards.insert(subtask);
  877. });
  878. // copy card comments
  879. CardComments.find({ cardId: oldId }).forEach((cmt) => {
  880. cmt.copy(_id);
  881. });
  882. }
  883. Popup.back();
  884. }
  885. },
  886. });
  887. BlazeComponent.extendComponent({
  888. onCreated() {
  889. this.currentCard = this.currentData();
  890. this.currentColor = new ReactiveVar(this.currentCard.color);
  891. },
  892. colors() {
  893. return ALLOWED_COLORS.map((color) => ({ color, name: '' }));
  894. },
  895. isSelected(color) {
  896. if (this.currentColor.get() === null) {
  897. return color === 'white';
  898. }
  899. return this.currentColor.get() === color;
  900. },
  901. events() {
  902. return [
  903. {
  904. 'click .js-palette-color'() {
  905. this.currentColor.set(this.currentData().color);
  906. },
  907. 'click .js-submit'() {
  908. this.currentCard.setColor(this.currentColor.get());
  909. Popup.close();
  910. },
  911. 'click .js-remove-color'() {
  912. this.currentCard.setColor(null);
  913. Popup.close();
  914. },
  915. },
  916. ];
  917. },
  918. }).register('setCardColorPopup');
  919. BlazeComponent.extendComponent({
  920. onCreated() {
  921. this.currentCard = this.currentData();
  922. this.parentBoard = new ReactiveVar(null);
  923. this.parentCard = this.currentCard.parentCard();
  924. if (this.parentCard) {
  925. const list = $('.js-field-parent-card');
  926. list.val(this.parentCard._id);
  927. this.parentBoard.set(this.parentCard.board()._id);
  928. } else {
  929. this.parentBoard.set(null);
  930. }
  931. },
  932. boards() {
  933. return Boards.find(
  934. {
  935. archived: false,
  936. 'members.userId': Meteor.userId(),
  937. _id: {
  938. $ne: Meteor.user().getTemplatesBoardId(),
  939. },
  940. },
  941. {
  942. sort: { sort: 1 /* boards default sorting */ },
  943. },
  944. );
  945. },
  946. cards() {
  947. const currentId = Utils.getCurrentCardId();
  948. if (this.parentBoard.get()) {
  949. return Cards.find({
  950. boardId: this.parentBoard.get(),
  951. _id: { $ne: currentId },
  952. });
  953. } else {
  954. return [];
  955. }
  956. },
  957. isParentBoard() {
  958. const board = this.currentData();
  959. if (this.parentBoard.get()) {
  960. return board._id === this.parentBoard.get();
  961. }
  962. return false;
  963. },
  964. isParentCard() {
  965. const card = this.currentData();
  966. if (this.parentCard) {
  967. return card._id === this.parentCard;
  968. }
  969. return false;
  970. },
  971. setParentCardId(cardId) {
  972. if (cardId) {
  973. this.parentCard = Cards.findOne(cardId);
  974. } else {
  975. this.parentCard = null;
  976. }
  977. this.currentCard.setParentId(cardId);
  978. },
  979. events() {
  980. return [
  981. {
  982. 'click .js-copy-card-link-to-clipboard'(event) {
  983. const promise = Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value);
  984. const $tooltip = this.$('.copied-tooltip');
  985. Utils.showCopied(promise, $tooltip);
  986. },
  987. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  988. Popup.close();
  989. // verify that there are no linked cards
  990. if (Cards.find({ linkedId: this._id }).count() === 0) {
  991. Cards.remove(this._id);
  992. } else {
  993. // TODO: Maybe later we can list where the linked cards are.
  994. // Now here is popup with a hint that the card cannot be deleted
  995. // as there are linked cards.
  996. // Related:
  997. // client/components/lists/listHeader.js about line 248
  998. // https://github.com/wekan/wekan/issues/2785
  999. const message = `${TAPi18n.__(
  1000. 'delete-linked-card-before-this-card',
  1001. )} linkedId: ${this._id
  1002. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  1003. alert(message);
  1004. }
  1005. Utils.goBoardId(this.boardId);
  1006. }),
  1007. 'change .js-field-parent-board'(event) {
  1008. const selection = $(event.currentTarget).val();
  1009. const list = $('.js-field-parent-card');
  1010. if (selection === 'none') {
  1011. this.parentBoard.set(null);
  1012. } else {
  1013. subManager.subscribe('board', $(event.currentTarget).val(), false);
  1014. this.parentBoard.set(selection);
  1015. list.prop('disabled', false);
  1016. }
  1017. this.setParentCardId(null);
  1018. },
  1019. 'change .js-field-parent-card'(event) {
  1020. const selection = $(event.currentTarget).val();
  1021. this.setParentCardId(selection);
  1022. },
  1023. },
  1024. ];
  1025. },
  1026. }).register('cardMorePopup');
  1027. BlazeComponent.extendComponent({
  1028. onCreated() {
  1029. this.currentCard = this.currentData();
  1030. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  1031. },
  1032. events() {
  1033. return [
  1034. {
  1035. 'click .js-end-date': Popup.open('editVoteEndDate'),
  1036. 'submit .edit-vote-question'(evt) {
  1037. evt.preventDefault();
  1038. const voteQuestion = evt.target.vote.value;
  1039. const publicVote = $('#vote-public').hasClass('is-checked');
  1040. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  1041. 'is-checked',
  1042. );
  1043. const endString = this.currentCard.getVoteEnd();
  1044. this.currentCard.setVoteQuestion(
  1045. voteQuestion,
  1046. publicVote,
  1047. allowNonBoardMembers,
  1048. );
  1049. if (endString) {
  1050. this.currentCard.setVoteEnd(endString);
  1051. }
  1052. Popup.back();
  1053. },
  1054. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  1055. event.preventDefault();
  1056. this.currentCard.unsetVote();
  1057. Popup.back();
  1058. }),
  1059. 'click a.js-toggle-vote-public'(event) {
  1060. event.preventDefault();
  1061. $('#vote-public').toggleClass('is-checked');
  1062. },
  1063. 'click a.js-toggle-vote-allow-non-members'(event) {
  1064. event.preventDefault();
  1065. $('#vote-allow-non-members').toggleClass('is-checked');
  1066. },
  1067. },
  1068. ];
  1069. },
  1070. }).register('cardStartVotingPopup');
  1071. // editVoteEndDatePopup
  1072. (class extends DatePicker {
  1073. onCreated() {
  1074. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1075. this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
  1076. }
  1077. events() {
  1078. return [
  1079. {
  1080. 'submit .edit-date'(evt) {
  1081. evt.preventDefault();
  1082. // if no time was given, init with 12:00
  1083. const time =
  1084. evt.target.time.value ||
  1085. moment(new Date().setHours(12, 0, 0)).format('LT');
  1086. const dateString = `${evt.target.date.value} ${time}`;
  1087. /*
  1088. const newDate = moment(dateString, 'L LT', true);
  1089. if (newDate.isValid()) {
  1090. // if active vote - store it
  1091. if (this.currentData().getVoteQuestion()) {
  1092. this._storeDate(newDate.toDate());
  1093. Popup.back();
  1094. } else {
  1095. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  1096. Popup.back();
  1097. }
  1098. */
  1099. // Try to parse different date formats of all languages.
  1100. // This code is same for vote and planning poker.
  1101. const usaDate = moment(dateString, 'L LT', true);
  1102. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1103. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1104. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1105. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1106. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1107. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1108. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1109. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1110. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1111. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1112. // greekDate does not work: el Greek Ελληνικά ,
  1113. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1114. // where MM is maybe some text like AM/PM ?
  1115. // Also some other languages that have non-ascii characters in dates
  1116. // do not work.
  1117. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1118. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1119. if (usaDate.isValid()) {
  1120. // if active poker - store it
  1121. if (this.currentData().getPokerQuestion()) {
  1122. this._storeDate(usaDate.toDate());
  1123. } else {
  1124. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1125. }
  1126. Popup.back();
  1127. } else if (euroAmDate.isValid()) {
  1128. // if active poker - store it
  1129. if (this.currentData().getPokerQuestion()) {
  1130. this._storeDate(euroAmDate.toDate());
  1131. } else {
  1132. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1133. }
  1134. Popup.back();
  1135. } else if (euro24hDate.isValid()) {
  1136. // if active poker - store it
  1137. if (this.currentData().getPokerQuestion()) {
  1138. this._storeDate(euro24hDate.toDate());
  1139. this.card.setPokerEnd(euro24hDate.toDate());
  1140. } else {
  1141. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1142. }
  1143. Popup.back();
  1144. } else if (eurodotDate.isValid()) {
  1145. // if active poker - store it
  1146. if (this.currentData().getPokerQuestion()) {
  1147. this._storeDate(eurodotDate.toDate());
  1148. this.card.setPokerEnd(eurodotDate.toDate());
  1149. } else {
  1150. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1151. }
  1152. Popup.back();
  1153. } else if (minusDate.isValid()) {
  1154. // if active poker - store it
  1155. if (this.currentData().getPokerQuestion()) {
  1156. this._storeDate(minusDate.toDate());
  1157. this.card.setPokerEnd(minusDate.toDate());
  1158. } else {
  1159. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1160. }
  1161. Popup.back();
  1162. } else if (slashDate.isValid()) {
  1163. // if active poker - store it
  1164. if (this.currentData().getPokerQuestion()) {
  1165. this._storeDate(slashDate.toDate());
  1166. this.card.setPokerEnd(slashDate.toDate());
  1167. } else {
  1168. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1169. }
  1170. Popup.back();
  1171. } else if (dotDate.isValid()) {
  1172. // if active poker - store it
  1173. if (this.currentData().getPokerQuestion()) {
  1174. this._storeDate(dotDate.toDate());
  1175. this.card.setPokerEnd(dotDate.toDate());
  1176. } else {
  1177. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1178. }
  1179. Popup.back();
  1180. } else if (brezhonegDate.isValid()) {
  1181. // if active poker - store it
  1182. if (this.currentData().getPokerQuestion()) {
  1183. this._storeDate(brezhonegDate.toDate());
  1184. this.card.setPokerEnd(brezhonegDate.toDate());
  1185. } else {
  1186. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1187. }
  1188. Popup.back();
  1189. } else if (hrvatskiDate.isValid()) {
  1190. // if active poker - store it
  1191. if (this.currentData().getPokerQuestion()) {
  1192. this._storeDate(hrvatskiDate.toDate());
  1193. this.card.setPokerEnd(hrvatskiDate.toDate());
  1194. } else {
  1195. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1196. Popup.back();
  1197. }
  1198. } else if (latviaDate.isValid()) {
  1199. // if active poker - store it
  1200. if (this.currentData().getPokerQuestion()) {
  1201. this._storeDate(latviaDate.toDate());
  1202. this.card.setPokerEnd(latviaDate.toDate());
  1203. } else {
  1204. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1205. }
  1206. Popup.back();
  1207. } else if (nederlandsDate.isValid()) {
  1208. // if active poker - store it
  1209. if (this.currentData().getPokerQuestion()) {
  1210. this._storeDate(nederlandsDate.toDate());
  1211. this.card.setPokerEnd(nederlandsDate.toDate());
  1212. } else {
  1213. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1214. }
  1215. Popup.back();
  1216. } else if (greekDate.isValid()) {
  1217. // if active poker - store it
  1218. if (this.currentData().getPokerQuestion()) {
  1219. this._storeDate(greekDate.toDate());
  1220. this.card.setPokerEnd(greekDate.toDate());
  1221. } else {
  1222. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1223. }
  1224. Popup.back();
  1225. } else if (macedonianDate.isValid()) {
  1226. // if active poker - store it
  1227. if (this.currentData().getPokerQuestion()) {
  1228. this._storeDate(macedonianDate.toDate());
  1229. this.card.setPokerEnd(macedonianDate.toDate());
  1230. } else {
  1231. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1232. }
  1233. Popup.back();
  1234. } else {
  1235. this.error.set('invalid-date');
  1236. evt.target.date.focus();
  1237. }
  1238. },
  1239. 'click .js-delete-date'(evt) {
  1240. evt.preventDefault();
  1241. this._deleteDate();
  1242. Popup.back();
  1243. },
  1244. },
  1245. ];
  1246. }
  1247. _storeDate(newDate) {
  1248. this.card.setVoteEnd(newDate);
  1249. }
  1250. _deleteDate() {
  1251. this.card.unsetVoteEnd();
  1252. }
  1253. }.register('editVoteEndDatePopup'));
  1254. BlazeComponent.extendComponent({
  1255. onCreated() {
  1256. this.currentCard = this.currentData();
  1257. this.pokerQuestion = new ReactiveVar(this.currentCard.pokerQuestion);
  1258. },
  1259. events() {
  1260. return [
  1261. {
  1262. 'click .js-end-date': Popup.open('editPokerEndDate'),
  1263. 'submit .edit-poker-question'(evt) {
  1264. evt.preventDefault();
  1265. const pokerQuestion = true;
  1266. const allowNonBoardMembers = $('#poker-allow-non-members').hasClass(
  1267. 'is-checked',
  1268. );
  1269. const endString = this.currentCard.getPokerEnd();
  1270. this.currentCard.setPokerQuestion(
  1271. pokerQuestion,
  1272. allowNonBoardMembers,
  1273. );
  1274. if (endString) {
  1275. this.currentCard.setPokerEnd(endString);
  1276. }
  1277. Popup.back();
  1278. },
  1279. 'click .js-remove-poker': Popup.afterConfirm('deletePoker', (event) => {
  1280. this.currentCard.unsetPoker();
  1281. Popup.back();
  1282. }),
  1283. 'click a.js-toggle-poker-allow-non-members'(event) {
  1284. event.preventDefault();
  1285. $('#poker-allow-non-members').toggleClass('is-checked');
  1286. },
  1287. },
  1288. ];
  1289. },
  1290. }).register('cardStartPlanningPokerPopup');
  1291. // editPokerEndDatePopup
  1292. (class extends DatePicker {
  1293. onCreated() {
  1294. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1295. this.data().getPokerEnd() &&
  1296. this.date.set(moment(this.data().getPokerEnd()));
  1297. }
  1298. /*
  1299. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1300. to make detecting all date formats not necessary,
  1301. but got error "language mk does not exist".
  1302. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1303. datepicker format that could be used to detect date format?
  1304. dateFormat() {
  1305. return moment.localeData().longDateFormat('L');
  1306. }
  1307. timeFormat() {
  1308. return moment.localeData().longDateFormat('LT');
  1309. }
  1310. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1311. */
  1312. events() {
  1313. return [
  1314. {
  1315. 'submit .edit-date'(evt) {
  1316. evt.preventDefault();
  1317. // if no time was given, init with 12:00
  1318. const time =
  1319. evt.target.time.value ||
  1320. moment(new Date().setHours(12, 0, 0)).format('LT');
  1321. const dateString = `${evt.target.date.value} ${time}`;
  1322. /*
  1323. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1324. to make detecting all date formats not necessary,
  1325. but got error "language mk does not exist".
  1326. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1327. datepicker format that could be used to detect date format?
  1328. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1329. if (newDate.isValid()) {
  1330. // if active poker - store it
  1331. if (this.currentData().getPokerQuestion()) {
  1332. this._storeDate(newDate.toDate());
  1333. Popup.back();
  1334. } else {
  1335. this.currentData().poker = { end: newDate.toDate() }; // set poker end temp
  1336. Popup.back();
  1337. }
  1338. */
  1339. // Try to parse different date formats of all languages.
  1340. // This code is same for vote and planning poker.
  1341. const usaDate = moment(dateString, 'L LT', true);
  1342. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1343. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1344. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1345. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1346. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1347. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1348. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1349. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1350. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1351. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1352. // greekDate does not work: el Greek Ελληνικά ,
  1353. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1354. // where MM is maybe some text like AM/PM ?
  1355. // Also some other languages that have non-ascii characters in dates
  1356. // do not work.
  1357. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1358. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1359. if (usaDate.isValid()) {
  1360. // if active poker - store it
  1361. if (this.currentData().getPokerQuestion()) {
  1362. this._storeDate(usaDate.toDate());
  1363. } else {
  1364. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1365. }
  1366. Popup.back();
  1367. } else if (euroAmDate.isValid()) {
  1368. // if active poker - store it
  1369. if (this.currentData().getPokerQuestion()) {
  1370. this._storeDate(euroAmDate.toDate());
  1371. } else {
  1372. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1373. }
  1374. Popup.back();
  1375. } else if (euro24hDate.isValid()) {
  1376. // if active poker - store it
  1377. if (this.currentData().getPokerQuestion()) {
  1378. this._storeDate(euro24hDate.toDate());
  1379. this.card.setPokerEnd(euro24hDate.toDate());
  1380. } else {
  1381. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1382. }
  1383. Popup.back();
  1384. } else if (eurodotDate.isValid()) {
  1385. // if active poker - store it
  1386. if (this.currentData().getPokerQuestion()) {
  1387. this._storeDate(eurodotDate.toDate());
  1388. this.card.setPokerEnd(eurodotDate.toDate());
  1389. } else {
  1390. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1391. }
  1392. Popup.back();
  1393. } else if (minusDate.isValid()) {
  1394. // if active poker - store it
  1395. if (this.currentData().getPokerQuestion()) {
  1396. this._storeDate(minusDate.toDate());
  1397. this.card.setPokerEnd(minusDate.toDate());
  1398. } else {
  1399. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1400. }
  1401. Popup.back();
  1402. } else if (slashDate.isValid()) {
  1403. // if active poker - store it
  1404. if (this.currentData().getPokerQuestion()) {
  1405. this._storeDate(slashDate.toDate());
  1406. this.card.setPokerEnd(slashDate.toDate());
  1407. } else {
  1408. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1409. }
  1410. Popup.back();
  1411. } else if (dotDate.isValid()) {
  1412. // if active poker - store it
  1413. if (this.currentData().getPokerQuestion()) {
  1414. this._storeDate(dotDate.toDate());
  1415. this.card.setPokerEnd(dotDate.toDate());
  1416. } else {
  1417. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1418. }
  1419. Popup.back();
  1420. } else if (brezhonegDate.isValid()) {
  1421. // if active poker - store it
  1422. if (this.currentData().getPokerQuestion()) {
  1423. this._storeDate(brezhonegDate.toDate());
  1424. this.card.setPokerEnd(brezhonegDate.toDate());
  1425. } else {
  1426. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1427. }
  1428. Popup.back();
  1429. } else if (hrvatskiDate.isValid()) {
  1430. // if active poker - store it
  1431. if (this.currentData().getPokerQuestion()) {
  1432. this._storeDate(hrvatskiDate.toDate());
  1433. this.card.setPokerEnd(hrvatskiDate.toDate());
  1434. } else {
  1435. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1436. }
  1437. Popup.back();
  1438. } else if (latviaDate.isValid()) {
  1439. // if active poker - store it
  1440. if (this.currentData().getPokerQuestion()) {
  1441. this._storeDate(latviaDate.toDate());
  1442. this.card.setPokerEnd(latviaDate.toDate());
  1443. } else {
  1444. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1445. }
  1446. Popup.back();
  1447. } else if (nederlandsDate.isValid()) {
  1448. // if active poker - store it
  1449. if (this.currentData().getPokerQuestion()) {
  1450. this._storeDate(nederlandsDate.toDate());
  1451. this.card.setPokerEnd(nederlandsDate.toDate());
  1452. } else {
  1453. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1454. }
  1455. Popup.back();
  1456. } else if (greekDate.isValid()) {
  1457. // if active poker - store it
  1458. if (this.currentData().getPokerQuestion()) {
  1459. this._storeDate(greekDate.toDate());
  1460. this.card.setPokerEnd(greekDate.toDate());
  1461. } else {
  1462. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1463. }
  1464. Popup.back();
  1465. } else if (macedonianDate.isValid()) {
  1466. // if active poker - store it
  1467. if (this.currentData().getPokerQuestion()) {
  1468. this._storeDate(macedonianDate.toDate());
  1469. this.card.setPokerEnd(macedonianDate.toDate());
  1470. } else {
  1471. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1472. }
  1473. Popup.back();
  1474. } else {
  1475. // this.error.set('invalid-date);
  1476. this.error.set('invalid-date' + ' ' + dateString);
  1477. evt.target.date.focus();
  1478. }
  1479. },
  1480. 'click .js-delete-date'(evt) {
  1481. evt.preventDefault();
  1482. this._deleteDate();
  1483. Popup.back();
  1484. },
  1485. },
  1486. ];
  1487. }
  1488. _storeDate(newDate) {
  1489. this.card.setPokerEnd(newDate);
  1490. }
  1491. _deleteDate() {
  1492. this.card.unsetPokerEnd();
  1493. }
  1494. }.register('editPokerEndDatePopup'));
  1495. // Close the card details pane by pressing escape
  1496. EscapeActions.register(
  1497. 'detailsPane',
  1498. () => {
  1499. if (Session.get('cardDetailsIsDragging')) {
  1500. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1501. Session.set('cardDetailsIsDragging', false);
  1502. Session.set('cardDetailsIsMouseDown', false);
  1503. } else {
  1504. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1505. Utils.goBoardId(Session.get('currentBoard'));
  1506. }
  1507. },
  1508. () => {
  1509. return !Session.equals('currentCard', null);
  1510. },
  1511. {
  1512. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1513. },
  1514. );
  1515. Template.cardAssigneesPopup.onCreated(function () {
  1516. let currBoard = Boards.findOne(Session.get('currentBoard'));
  1517. let members = currBoard.activeMembers();
  1518. // let query = {
  1519. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  1520. // };
  1521. // let boardTeamUsers = Users.find(query, {
  1522. // sort: { sort: 1 },
  1523. // });
  1524. // members = currBoard.activeMembers2(members, boardTeamUsers);
  1525. this.members = new ReactiveVar(members);
  1526. });
  1527. Template.cardAssigneesPopup.events({
  1528. 'click .js-select-assignee'(event) {
  1529. const card = Utils.getCurrentCard();
  1530. const assigneeId = this.userId;
  1531. card.toggleAssignee(assigneeId);
  1532. event.preventDefault();
  1533. },
  1534. 'keyup .card-assignees-filter'(event) {
  1535. const members = filterMembers(event.target.value);
  1536. Template.instance().members.set(members);
  1537. },
  1538. });
  1539. Template.cardAssigneesPopup.helpers({
  1540. isCardAssignee() {
  1541. const card = Template.parentData();
  1542. const cardAssignees = card.getAssignees();
  1543. return _.contains(cardAssignees, this.userId);
  1544. },
  1545. members() {
  1546. return Template.instance().members.get();
  1547. },
  1548. user() {
  1549. return Users.findOne(this.userId);
  1550. },
  1551. });
  1552. Template.cardAssigneePopup.helpers({
  1553. userData() {
  1554. // We need to handle a special case for the search results provided by the
  1555. // `matteodem:easy-search` package. Since these results gets published in a
  1556. // separate collection, and not in the standard Meteor.Users collection as
  1557. // expected, we use a component parameter ("property") to distinguish the
  1558. // two cases.
  1559. const userCollection = this.esSearch ? ESSearchResults : Users;
  1560. return userCollection.findOne(this.userId, {
  1561. fields: {
  1562. profile: 1,
  1563. username: 1,
  1564. },
  1565. });
  1566. },
  1567. memberType() {
  1568. const user = Users.findOne(this.userId);
  1569. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1570. },
  1571. presenceStatusClassName() {
  1572. const user = Users.findOne(this.userId);
  1573. const userPresence = presences.findOne({ userId: this.userId });
  1574. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1575. else if (!userPresence) return 'disconnected';
  1576. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1577. return 'active';
  1578. else return 'idle';
  1579. },
  1580. isCardAssignee() {
  1581. const card = Template.parentData();
  1582. const cardAssignees = card.getAssignees();
  1583. return _.contains(cardAssignees, this.userId);
  1584. },
  1585. user() {
  1586. return Users.findOne(this.userId);
  1587. },
  1588. });
  1589. Template.cardAssigneePopup.events({
  1590. 'click .js-remove-assignee'() {
  1591. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1592. Popup.back();
  1593. },
  1594. 'click .js-edit-profile': Popup.open('editProfile'),
  1595. });