cardDetails.js 58 KB

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