cardDetails.js 56 KB

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