cardDetails.js 55 KB

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