cardDetails.js 58 KB

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