cardDetails.js 57 KB

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