cardDetails.js 56 KB

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