cardDetails.js 56 KB

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