cardDetails.js 57 KB

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