cardDetails.js 53 KB

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