cardDetails.js 58 KB

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