cardDetails.js 54 KB

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