cardDetails.js 59 KB

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