cardDetails.js 56 KB

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