cardDetails.js 59 KB

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