cardDetails.js 57 KB

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