cardDetails.js 58 KB

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