cardDetails.js 55 KB

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