cardDetails.js 53 KB

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