cardDetails.js 58 KB

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