cardDetails.js 58 KB

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