cardDetails.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  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) {
  736. boardId = bSelect.options[bSelect.selectedIndex].value;
  737. } else {
  738. boardId = card.boardId;
  739. }
  740. const lSelect = $('.js-select-lists')[0];
  741. const listId = lSelect.options[lSelect.selectedIndex].value;
  742. const slSelect = $('.js-select-swimlanes')[0];
  743. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  744. card.move(boardId, swimlaneId, listId, 0);
  745. // 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)
  746. this.boardId = boardId;
  747. this.swimlaneId = swimlaneId;
  748. this.listId = listId;
  749. Popup.back();
  750. },
  751. });
  752. BlazeComponent.extendComponent({
  753. onCreated() {
  754. this.currentBoardId = Utils.getCurrentBoardId();
  755. this.selectedBoardId = new ReactiveVar(this.currentBoardId);
  756. this.setMoveAndCopyDialogOption(this.currentBoardId);
  757. },
  758. /** set the last confirmed dialog field values
  759. * @param boardId the current board id
  760. */
  761. setMoveAndCopyDialogOption(boardId) {
  762. this.moveAndCopyDialogOption = {
  763. 'boardId' : "",
  764. 'swimlaneId' : "",
  765. 'listId' : "",
  766. }
  767. let currentOptions = Meteor.user().getMoveAndCopyDialogOptions();
  768. if (currentOptions && boardId && currentOptions[boardId]) {
  769. this.moveAndCopyDialogOption = currentOptions[boardId];
  770. if (this.moveAndCopyDialogOption.boardId) {
  771. this.selectedBoardId.set(this.moveAndCopyDialogOption.boardId)
  772. }
  773. }
  774. subManager.subscribe('board', this.selectedBoardId.get(), false);
  775. },
  776. /** returns if the board id was the last confirmed one
  777. * @param boardId check this board id
  778. * @return if the board id was the last confirmed one
  779. */
  780. isMoveAndCopyDialogOptionBoardId(boardId) {
  781. let ret = this.moveAndCopyDialogOption.boardId == boardId;
  782. return ret;
  783. },
  784. /** returns if the swimlane id was the last confirmed one
  785. * @param swimlaneId check this swimlane id
  786. * @return if the swimlane id was the last confirmed one
  787. */
  788. isMoveAndCopyDialogOptionSwimlaneId(swimlaneId) {
  789. let ret = this.moveAndCopyDialogOption.swimlaneId == swimlaneId;
  790. return ret;
  791. },
  792. /** returns if the list id was the last confirmed one
  793. * @param listId check this list id
  794. * @return if the list id was the last confirmed one
  795. */
  796. isMoveAndCopyDialogOptionListId(listId) {
  797. let ret = this.moveAndCopyDialogOption.listId == listId;
  798. return ret;
  799. },
  800. boards() {
  801. return Boards.find(
  802. {
  803. archived: false,
  804. 'members.userId': Meteor.userId(),
  805. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  806. },
  807. {
  808. sort: { sort: 1 /* boards default sorting */ },
  809. },
  810. );
  811. },
  812. swimlanes() {
  813. const board = Boards.findOne(this.selectedBoardId.get());
  814. return board.swimlanes();
  815. },
  816. aBoardLists() {
  817. const board = Boards.findOne(this.selectedBoardId.get());
  818. return board.lists();
  819. },
  820. events() {
  821. return [
  822. {
  823. 'click .js-done'() {
  824. const boardSelect = this.$('.js-select-boards')[0];
  825. const boardId = boardSelect.options[boardSelect.selectedIndex].value;
  826. const listSelect = this.$('.js-select-lists')[0];
  827. const listId = listSelect.options[listSelect.selectedIndex].value;
  828. const swimlaneSelect = this.$('.js-select-swimlanes')[0];
  829. const swimlaneId = swimlaneSelect.options[swimlaneSelect.selectedIndex].value;
  830. const options = {
  831. 'boardId' : boardId,
  832. 'swimlaneId' : swimlaneId,
  833. 'listId' : listId,
  834. }
  835. Meteor.user().setMoveAndCopyDialogOption(this.currentBoardId, options);
  836. },
  837. 'change .js-select-boards'(event) {
  838. const boardId = $(event.currentTarget).val();
  839. this.selectedBoardId.set(boardId);
  840. subManager.subscribe('board', boardId, false);
  841. },
  842. },
  843. ];
  844. },
  845. }).register('boardsAndLists');
  846. Template.copyCardPopup.events({
  847. 'click .js-done'() {
  848. const card = Utils.getCurrentCard();
  849. const lSelect = $('.js-select-lists')[0];
  850. const listId = lSelect.options[lSelect.selectedIndex].value;
  851. const slSelect = $('.js-select-swimlanes')[0];
  852. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  853. const bSelect = $('.js-select-boards')[0];
  854. const boardId = bSelect.options[bSelect.selectedIndex].value;
  855. const textarea = $('#copy-card-title');
  856. const title = textarea.val().trim();
  857. // insert new card to the bottom of new list
  858. card.sort = Lists.findOne(card.listId).cards().count();
  859. if (title) {
  860. card.title = title;
  861. card.coverId = '';
  862. const _id = card.copy(boardId, swimlaneId, listId);
  863. // In case the filter is active we need to add the newly inserted card in
  864. // the list of exceptions -- cards that are not filtered. Otherwise the
  865. // card will disappear instantly.
  866. // See https://github.com/wekan/wekan/issues/80
  867. Filter.addException(_id);
  868. Popup.back();
  869. }
  870. },
  871. });
  872. Template.convertChecklistItemToCardPopup.events({
  873. 'click .js-done'() {
  874. const card = Utils.getCurrentCard();
  875. const lSelect = $('.js-select-lists')[0];
  876. const listId = lSelect.options[lSelect.selectedIndex].value;
  877. const slSelect = $('.js-select-swimlanes')[0];
  878. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  879. const bSelect = $('.js-select-boards')[0];
  880. const boardId = bSelect.options[bSelect.selectedIndex].value;
  881. const textarea = $('#copy-card-title');
  882. const title = textarea.val().trim();
  883. if (title) {
  884. const _id = Cards.insert({
  885. title: title,
  886. listId: listId,
  887. boardId: boardId,
  888. swimlaneId: swimlaneId,
  889. sort: 0,
  890. });
  891. Filter.addException(_id);
  892. Popup.back();
  893. }
  894. },
  895. });
  896. Template.copyChecklistToManyCardsPopup.events({
  897. 'click .js-done'() {
  898. const card = Utils.getCurrentCard();
  899. const oldId = card._id;
  900. card._id = null;
  901. const lSelect = $('.js-select-lists')[0];
  902. card.listId = lSelect.options[lSelect.selectedIndex].value;
  903. const slSelect = $('.js-select-swimlanes')[0];
  904. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  905. const bSelect = $('.js-select-boards')[0];
  906. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  907. const textarea = $('#copy-card-title');
  908. const titleEntry = textarea.val().trim();
  909. // insert new card to the bottom of new list
  910. card.sort = Lists.findOne(card.listId).cards().count();
  911. if (titleEntry) {
  912. const titleList = JSON.parse(titleEntry);
  913. for (let i = 0; i < titleList.length; i++) {
  914. const obj = titleList[i];
  915. card.title = obj.title;
  916. card.description = obj.description;
  917. card.coverId = '';
  918. const _id = Cards.insert(card);
  919. // In case the filter is active we need to add the newly inserted card in
  920. // the list of exceptions -- cards that are not filtered. Otherwise the
  921. // card will disappear instantly.
  922. // See https://github.com/wekan/wekan/issues/80
  923. Filter.addException(_id);
  924. // copy checklists
  925. Checklists.find({ cardId: oldId }).forEach((ch) => {
  926. ch.copy(_id);
  927. });
  928. // copy subtasks
  929. const cursor = Cards.find({ parentId: oldId });
  930. cursor.forEach(function () {
  931. 'use strict';
  932. const subtask = arguments[0];
  933. subtask.parentId = _id;
  934. subtask._id = null;
  935. /* const newSubtaskId = */ Cards.insert(subtask);
  936. });
  937. // copy card comments
  938. CardComments.find({ cardId: oldId }).forEach((cmt) => {
  939. cmt.copy(_id);
  940. });
  941. }
  942. Popup.back();
  943. }
  944. },
  945. });
  946. BlazeComponent.extendComponent({
  947. onCreated() {
  948. this.currentCard = this.currentData();
  949. this.currentColor = new ReactiveVar(this.currentCard.color);
  950. },
  951. colors() {
  952. return ALLOWED_COLORS.map((color) => ({ color, name: '' }));
  953. },
  954. isSelected(color) {
  955. if (this.currentColor.get() === null) {
  956. return color === 'white';
  957. }
  958. return this.currentColor.get() === color;
  959. },
  960. events() {
  961. return [
  962. {
  963. 'click .js-palette-color'() {
  964. this.currentColor.set(this.currentData().color);
  965. },
  966. 'click .js-submit'() {
  967. this.currentCard.setColor(this.currentColor.get());
  968. Popup.close();
  969. },
  970. 'click .js-remove-color'() {
  971. this.currentCard.setColor(null);
  972. Popup.close();
  973. },
  974. },
  975. ];
  976. },
  977. }).register('setCardColorPopup');
  978. BlazeComponent.extendComponent({
  979. onCreated() {
  980. this.currentCard = this.currentData();
  981. this.parentBoard = new ReactiveVar(null);
  982. this.parentCard = this.currentCard.parentCard();
  983. if (this.parentCard) {
  984. const list = $('.js-field-parent-card');
  985. list.val(this.parentCard._id);
  986. this.parentBoard.set(this.parentCard.board()._id);
  987. } else {
  988. this.parentBoard.set(null);
  989. }
  990. },
  991. boards() {
  992. return Boards.find(
  993. {
  994. archived: false,
  995. 'members.userId': Meteor.userId(),
  996. _id: {
  997. $ne: Meteor.user().getTemplatesBoardId(),
  998. },
  999. },
  1000. {
  1001. sort: { sort: 1 /* boards default sorting */ },
  1002. },
  1003. );
  1004. },
  1005. cards() {
  1006. const currentId = Utils.getCurrentCardId();
  1007. if (this.parentBoard.get()) {
  1008. return Cards.find({
  1009. boardId: this.parentBoard.get(),
  1010. _id: { $ne: currentId },
  1011. });
  1012. } else {
  1013. return [];
  1014. }
  1015. },
  1016. isParentBoard() {
  1017. const board = this.currentData();
  1018. if (this.parentBoard.get()) {
  1019. return board._id === this.parentBoard.get();
  1020. }
  1021. return false;
  1022. },
  1023. isParentCard() {
  1024. const card = this.currentData();
  1025. if (this.parentCard) {
  1026. return card._id === this.parentCard;
  1027. }
  1028. return false;
  1029. },
  1030. setParentCardId(cardId) {
  1031. if (cardId) {
  1032. this.parentCard = Cards.findOne(cardId);
  1033. } else {
  1034. this.parentCard = null;
  1035. }
  1036. this.currentCard.setParentId(cardId);
  1037. },
  1038. events() {
  1039. return [
  1040. {
  1041. 'click .js-copy-card-link-to-clipboard'(event) {
  1042. const promise = Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value);
  1043. const $tooltip = this.$('.copied-tooltip');
  1044. Utils.showCopied(promise, $tooltip);
  1045. },
  1046. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  1047. Popup.close();
  1048. // verify that there are no linked cards
  1049. if (Cards.find({ linkedId: this._id }).count() === 0) {
  1050. Cards.remove(this._id);
  1051. } else {
  1052. // TODO: Maybe later we can list where the linked cards are.
  1053. // Now here is popup with a hint that the card cannot be deleted
  1054. // as there are linked cards.
  1055. // Related:
  1056. // client/components/lists/listHeader.js about line 248
  1057. // https://github.com/wekan/wekan/issues/2785
  1058. const message = `${TAPi18n.__(
  1059. 'delete-linked-card-before-this-card',
  1060. )} linkedId: ${this._id
  1061. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  1062. alert(message);
  1063. }
  1064. Utils.goBoardId(this.boardId);
  1065. }),
  1066. 'change .js-field-parent-board'(event) {
  1067. const selection = $(event.currentTarget).val();
  1068. const list = $('.js-field-parent-card');
  1069. if (selection === 'none') {
  1070. this.parentBoard.set(null);
  1071. } else {
  1072. subManager.subscribe('board', $(event.currentTarget).val(), false);
  1073. this.parentBoard.set(selection);
  1074. list.prop('disabled', false);
  1075. }
  1076. this.setParentCardId(null);
  1077. },
  1078. 'change .js-field-parent-card'(event) {
  1079. const selection = $(event.currentTarget).val();
  1080. this.setParentCardId(selection);
  1081. },
  1082. },
  1083. ];
  1084. },
  1085. }).register('cardMorePopup');
  1086. BlazeComponent.extendComponent({
  1087. onCreated() {
  1088. this.currentCard = this.currentData();
  1089. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  1090. },
  1091. events() {
  1092. return [
  1093. {
  1094. 'click .js-end-date': Popup.open('editVoteEndDate'),
  1095. 'submit .edit-vote-question'(evt) {
  1096. evt.preventDefault();
  1097. const voteQuestion = evt.target.vote.value;
  1098. const publicVote = $('#vote-public').hasClass('is-checked');
  1099. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  1100. 'is-checked',
  1101. );
  1102. const endString = this.currentCard.getVoteEnd();
  1103. this.currentCard.setVoteQuestion(
  1104. voteQuestion,
  1105. publicVote,
  1106. allowNonBoardMembers,
  1107. );
  1108. if (endString) {
  1109. this.currentCard.setVoteEnd(endString);
  1110. }
  1111. Popup.back();
  1112. },
  1113. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  1114. event.preventDefault();
  1115. this.currentCard.unsetVote();
  1116. Popup.back();
  1117. }),
  1118. 'click a.js-toggle-vote-public'(event) {
  1119. event.preventDefault();
  1120. $('#vote-public').toggleClass('is-checked');
  1121. },
  1122. 'click a.js-toggle-vote-allow-non-members'(event) {
  1123. event.preventDefault();
  1124. $('#vote-allow-non-members').toggleClass('is-checked');
  1125. },
  1126. },
  1127. ];
  1128. },
  1129. }).register('cardStartVotingPopup');
  1130. // editVoteEndDatePopup
  1131. (class extends DatePicker {
  1132. onCreated() {
  1133. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1134. this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
  1135. }
  1136. events() {
  1137. return [
  1138. {
  1139. 'submit .edit-date'(evt) {
  1140. evt.preventDefault();
  1141. // if no time was given, init with 12:00
  1142. const time =
  1143. evt.target.time.value ||
  1144. moment(new Date().setHours(12, 0, 0)).format('LT');
  1145. const dateString = `${evt.target.date.value} ${time}`;
  1146. /*
  1147. const newDate = moment(dateString, 'L LT', true);
  1148. if (newDate.isValid()) {
  1149. // if active vote - store it
  1150. if (this.currentData().getVoteQuestion()) {
  1151. this._storeDate(newDate.toDate());
  1152. Popup.back();
  1153. } else {
  1154. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  1155. Popup.back();
  1156. }
  1157. */
  1158. // Try to parse different date formats of all languages.
  1159. // This code is same for vote and planning poker.
  1160. const usaDate = moment(dateString, 'L LT', true);
  1161. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1162. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1163. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1164. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1165. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1166. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1167. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1168. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1169. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1170. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1171. // greekDate does not work: el Greek Ελληνικά ,
  1172. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1173. // where MM is maybe some text like AM/PM ?
  1174. // Also some other languages that have non-ascii characters in dates
  1175. // do not work.
  1176. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1177. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1178. if (usaDate.isValid()) {
  1179. // if active poker - store it
  1180. if (this.currentData().getPokerQuestion()) {
  1181. this._storeDate(usaDate.toDate());
  1182. } else {
  1183. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1184. }
  1185. Popup.back();
  1186. } else if (euroAmDate.isValid()) {
  1187. // if active poker - store it
  1188. if (this.currentData().getPokerQuestion()) {
  1189. this._storeDate(euroAmDate.toDate());
  1190. } else {
  1191. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1192. }
  1193. Popup.back();
  1194. } else if (euro24hDate.isValid()) {
  1195. // if active poker - store it
  1196. if (this.currentData().getPokerQuestion()) {
  1197. this._storeDate(euro24hDate.toDate());
  1198. this.card.setPokerEnd(euro24hDate.toDate());
  1199. } else {
  1200. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1201. }
  1202. Popup.back();
  1203. } else if (eurodotDate.isValid()) {
  1204. // if active poker - store it
  1205. if (this.currentData().getPokerQuestion()) {
  1206. this._storeDate(eurodotDate.toDate());
  1207. this.card.setPokerEnd(eurodotDate.toDate());
  1208. } else {
  1209. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1210. }
  1211. Popup.back();
  1212. } else if (minusDate.isValid()) {
  1213. // if active poker - store it
  1214. if (this.currentData().getPokerQuestion()) {
  1215. this._storeDate(minusDate.toDate());
  1216. this.card.setPokerEnd(minusDate.toDate());
  1217. } else {
  1218. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1219. }
  1220. Popup.back();
  1221. } else if (slashDate.isValid()) {
  1222. // if active poker - store it
  1223. if (this.currentData().getPokerQuestion()) {
  1224. this._storeDate(slashDate.toDate());
  1225. this.card.setPokerEnd(slashDate.toDate());
  1226. } else {
  1227. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1228. }
  1229. Popup.back();
  1230. } else if (dotDate.isValid()) {
  1231. // if active poker - store it
  1232. if (this.currentData().getPokerQuestion()) {
  1233. this._storeDate(dotDate.toDate());
  1234. this.card.setPokerEnd(dotDate.toDate());
  1235. } else {
  1236. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1237. }
  1238. Popup.back();
  1239. } else if (brezhonegDate.isValid()) {
  1240. // if active poker - store it
  1241. if (this.currentData().getPokerQuestion()) {
  1242. this._storeDate(brezhonegDate.toDate());
  1243. this.card.setPokerEnd(brezhonegDate.toDate());
  1244. } else {
  1245. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1246. }
  1247. Popup.back();
  1248. } else if (hrvatskiDate.isValid()) {
  1249. // if active poker - store it
  1250. if (this.currentData().getPokerQuestion()) {
  1251. this._storeDate(hrvatskiDate.toDate());
  1252. this.card.setPokerEnd(hrvatskiDate.toDate());
  1253. } else {
  1254. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1255. Popup.back();
  1256. }
  1257. } else if (latviaDate.isValid()) {
  1258. // if active poker - store it
  1259. if (this.currentData().getPokerQuestion()) {
  1260. this._storeDate(latviaDate.toDate());
  1261. this.card.setPokerEnd(latviaDate.toDate());
  1262. } else {
  1263. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1264. }
  1265. Popup.back();
  1266. } else if (nederlandsDate.isValid()) {
  1267. // if active poker - store it
  1268. if (this.currentData().getPokerQuestion()) {
  1269. this._storeDate(nederlandsDate.toDate());
  1270. this.card.setPokerEnd(nederlandsDate.toDate());
  1271. } else {
  1272. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1273. }
  1274. Popup.back();
  1275. } else if (greekDate.isValid()) {
  1276. // if active poker - store it
  1277. if (this.currentData().getPokerQuestion()) {
  1278. this._storeDate(greekDate.toDate());
  1279. this.card.setPokerEnd(greekDate.toDate());
  1280. } else {
  1281. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1282. }
  1283. Popup.back();
  1284. } else if (macedonianDate.isValid()) {
  1285. // if active poker - store it
  1286. if (this.currentData().getPokerQuestion()) {
  1287. this._storeDate(macedonianDate.toDate());
  1288. this.card.setPokerEnd(macedonianDate.toDate());
  1289. } else {
  1290. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1291. }
  1292. Popup.back();
  1293. } else {
  1294. this.error.set('invalid-date');
  1295. evt.target.date.focus();
  1296. }
  1297. },
  1298. 'click .js-delete-date'(evt) {
  1299. evt.preventDefault();
  1300. this._deleteDate();
  1301. Popup.back();
  1302. },
  1303. },
  1304. ];
  1305. }
  1306. _storeDate(newDate) {
  1307. this.card.setVoteEnd(newDate);
  1308. }
  1309. _deleteDate() {
  1310. this.card.unsetVoteEnd();
  1311. }
  1312. }.register('editVoteEndDatePopup'));
  1313. BlazeComponent.extendComponent({
  1314. onCreated() {
  1315. this.currentCard = this.currentData();
  1316. this.pokerQuestion = new ReactiveVar(this.currentCard.pokerQuestion);
  1317. },
  1318. events() {
  1319. return [
  1320. {
  1321. 'click .js-end-date': Popup.open('editPokerEndDate'),
  1322. 'submit .edit-poker-question'(evt) {
  1323. evt.preventDefault();
  1324. const pokerQuestion = true;
  1325. const allowNonBoardMembers = $('#poker-allow-non-members').hasClass(
  1326. 'is-checked',
  1327. );
  1328. const endString = this.currentCard.getPokerEnd();
  1329. this.currentCard.setPokerQuestion(
  1330. pokerQuestion,
  1331. allowNonBoardMembers,
  1332. );
  1333. if (endString) {
  1334. this.currentCard.setPokerEnd(endString);
  1335. }
  1336. Popup.back();
  1337. },
  1338. 'click .js-remove-poker': Popup.afterConfirm('deletePoker', (event) => {
  1339. this.currentCard.unsetPoker();
  1340. Popup.back();
  1341. }),
  1342. 'click a.js-toggle-poker-allow-non-members'(event) {
  1343. event.preventDefault();
  1344. $('#poker-allow-non-members').toggleClass('is-checked');
  1345. },
  1346. },
  1347. ];
  1348. },
  1349. }).register('cardStartPlanningPokerPopup');
  1350. // editPokerEndDatePopup
  1351. (class extends DatePicker {
  1352. onCreated() {
  1353. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1354. this.data().getPokerEnd() &&
  1355. this.date.set(moment(this.data().getPokerEnd()));
  1356. }
  1357. /*
  1358. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1359. to make detecting all date formats not necessary,
  1360. but got error "language mk does not exist".
  1361. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1362. datepicker format that could be used to detect date format?
  1363. dateFormat() {
  1364. return moment.localeData().longDateFormat('L');
  1365. }
  1366. timeFormat() {
  1367. return moment.localeData().longDateFormat('LT');
  1368. }
  1369. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1370. */
  1371. events() {
  1372. return [
  1373. {
  1374. 'submit .edit-date'(evt) {
  1375. evt.preventDefault();
  1376. // if no time was given, init with 12:00
  1377. const time =
  1378. evt.target.time.value ||
  1379. moment(new Date().setHours(12, 0, 0)).format('LT');
  1380. const dateString = `${evt.target.date.value} ${time}`;
  1381. /*
  1382. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1383. to make detecting all date formats not necessary,
  1384. but got error "language mk does not exist".
  1385. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1386. datepicker format that could be used to detect date format?
  1387. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1388. if (newDate.isValid()) {
  1389. // if active poker - store it
  1390. if (this.currentData().getPokerQuestion()) {
  1391. this._storeDate(newDate.toDate());
  1392. Popup.back();
  1393. } else {
  1394. this.currentData().poker = { end: newDate.toDate() }; // set poker end temp
  1395. Popup.back();
  1396. }
  1397. */
  1398. // Try to parse different date formats of all languages.
  1399. // This code is same for vote and planning poker.
  1400. const usaDate = moment(dateString, 'L LT', true);
  1401. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1402. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1403. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1404. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1405. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1406. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1407. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1408. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1409. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1410. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1411. // greekDate does not work: el Greek Ελληνικά ,
  1412. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1413. // where MM is maybe some text like AM/PM ?
  1414. // Also some other languages that have non-ascii characters in dates
  1415. // do not work.
  1416. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1417. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1418. if (usaDate.isValid()) {
  1419. // if active poker - store it
  1420. if (this.currentData().getPokerQuestion()) {
  1421. this._storeDate(usaDate.toDate());
  1422. } else {
  1423. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1424. }
  1425. Popup.back();
  1426. } else if (euroAmDate.isValid()) {
  1427. // if active poker - store it
  1428. if (this.currentData().getPokerQuestion()) {
  1429. this._storeDate(euroAmDate.toDate());
  1430. } else {
  1431. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1432. }
  1433. Popup.back();
  1434. } else if (euro24hDate.isValid()) {
  1435. // if active poker - store it
  1436. if (this.currentData().getPokerQuestion()) {
  1437. this._storeDate(euro24hDate.toDate());
  1438. this.card.setPokerEnd(euro24hDate.toDate());
  1439. } else {
  1440. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1441. }
  1442. Popup.back();
  1443. } else if (eurodotDate.isValid()) {
  1444. // if active poker - store it
  1445. if (this.currentData().getPokerQuestion()) {
  1446. this._storeDate(eurodotDate.toDate());
  1447. this.card.setPokerEnd(eurodotDate.toDate());
  1448. } else {
  1449. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1450. }
  1451. Popup.back();
  1452. } else if (minusDate.isValid()) {
  1453. // if active poker - store it
  1454. if (this.currentData().getPokerQuestion()) {
  1455. this._storeDate(minusDate.toDate());
  1456. this.card.setPokerEnd(minusDate.toDate());
  1457. } else {
  1458. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1459. }
  1460. Popup.back();
  1461. } else if (slashDate.isValid()) {
  1462. // if active poker - store it
  1463. if (this.currentData().getPokerQuestion()) {
  1464. this._storeDate(slashDate.toDate());
  1465. this.card.setPokerEnd(slashDate.toDate());
  1466. } else {
  1467. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1468. }
  1469. Popup.back();
  1470. } else if (dotDate.isValid()) {
  1471. // if active poker - store it
  1472. if (this.currentData().getPokerQuestion()) {
  1473. this._storeDate(dotDate.toDate());
  1474. this.card.setPokerEnd(dotDate.toDate());
  1475. } else {
  1476. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1477. }
  1478. Popup.back();
  1479. } else if (brezhonegDate.isValid()) {
  1480. // if active poker - store it
  1481. if (this.currentData().getPokerQuestion()) {
  1482. this._storeDate(brezhonegDate.toDate());
  1483. this.card.setPokerEnd(brezhonegDate.toDate());
  1484. } else {
  1485. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1486. }
  1487. Popup.back();
  1488. } else if (hrvatskiDate.isValid()) {
  1489. // if active poker - store it
  1490. if (this.currentData().getPokerQuestion()) {
  1491. this._storeDate(hrvatskiDate.toDate());
  1492. this.card.setPokerEnd(hrvatskiDate.toDate());
  1493. } else {
  1494. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1495. }
  1496. Popup.back();
  1497. } else if (latviaDate.isValid()) {
  1498. // if active poker - store it
  1499. if (this.currentData().getPokerQuestion()) {
  1500. this._storeDate(latviaDate.toDate());
  1501. this.card.setPokerEnd(latviaDate.toDate());
  1502. } else {
  1503. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1504. }
  1505. Popup.back();
  1506. } else if (nederlandsDate.isValid()) {
  1507. // if active poker - store it
  1508. if (this.currentData().getPokerQuestion()) {
  1509. this._storeDate(nederlandsDate.toDate());
  1510. this.card.setPokerEnd(nederlandsDate.toDate());
  1511. } else {
  1512. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1513. }
  1514. Popup.back();
  1515. } else if (greekDate.isValid()) {
  1516. // if active poker - store it
  1517. if (this.currentData().getPokerQuestion()) {
  1518. this._storeDate(greekDate.toDate());
  1519. this.card.setPokerEnd(greekDate.toDate());
  1520. } else {
  1521. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1522. }
  1523. Popup.back();
  1524. } else if (macedonianDate.isValid()) {
  1525. // if active poker - store it
  1526. if (this.currentData().getPokerQuestion()) {
  1527. this._storeDate(macedonianDate.toDate());
  1528. this.card.setPokerEnd(macedonianDate.toDate());
  1529. } else {
  1530. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1531. }
  1532. Popup.back();
  1533. } else {
  1534. // this.error.set('invalid-date);
  1535. this.error.set('invalid-date' + ' ' + dateString);
  1536. evt.target.date.focus();
  1537. }
  1538. },
  1539. 'click .js-delete-date'(evt) {
  1540. evt.preventDefault();
  1541. this._deleteDate();
  1542. Popup.back();
  1543. },
  1544. },
  1545. ];
  1546. }
  1547. _storeDate(newDate) {
  1548. this.card.setPokerEnd(newDate);
  1549. }
  1550. _deleteDate() {
  1551. this.card.unsetPokerEnd();
  1552. }
  1553. }.register('editPokerEndDatePopup'));
  1554. // Close the card details pane by pressing escape
  1555. EscapeActions.register(
  1556. 'detailsPane',
  1557. () => {
  1558. if (Session.get('cardDetailsIsDragging')) {
  1559. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1560. Session.set('cardDetailsIsDragging', false);
  1561. Session.set('cardDetailsIsMouseDown', false);
  1562. } else {
  1563. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1564. Utils.goBoardId(Session.get('currentBoard'));
  1565. }
  1566. },
  1567. () => {
  1568. return !Session.equals('currentCard', null);
  1569. },
  1570. {
  1571. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1572. },
  1573. );
  1574. Template.cardAssigneesPopup.onCreated(function () {
  1575. let currBoard = Boards.findOne(Session.get('currentBoard'));
  1576. let members = currBoard.activeMembers();
  1577. // let query = {
  1578. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  1579. // };
  1580. // let boardTeamUsers = Users.find(query, {
  1581. // sort: { sort: 1 },
  1582. // });
  1583. // members = currBoard.activeMembers2(members, boardTeamUsers);
  1584. this.members = new ReactiveVar(members);
  1585. });
  1586. Template.cardAssigneesPopup.events({
  1587. 'click .js-select-assignee'(event) {
  1588. const card = Utils.getCurrentCard();
  1589. const assigneeId = this.userId;
  1590. card.toggleAssignee(assigneeId);
  1591. event.preventDefault();
  1592. },
  1593. 'keyup .card-assignees-filter'(event) {
  1594. const members = filterMembers(event.target.value);
  1595. Template.instance().members.set(members);
  1596. },
  1597. });
  1598. Template.cardAssigneesPopup.helpers({
  1599. isCardAssignee() {
  1600. const card = Template.parentData();
  1601. const cardAssignees = card.getAssignees();
  1602. return _.contains(cardAssignees, this.userId);
  1603. },
  1604. members() {
  1605. return Template.instance().members.get();
  1606. },
  1607. user() {
  1608. return Users.findOne(this.userId);
  1609. },
  1610. });
  1611. Template.cardAssigneePopup.helpers({
  1612. userData() {
  1613. // We need to handle a special case for the search results provided by the
  1614. // `matteodem:easy-search` package. Since these results gets published in a
  1615. // separate collection, and not in the standard Meteor.Users collection as
  1616. // expected, we use a component parameter ("property") to distinguish the
  1617. // two cases.
  1618. const userCollection = this.esSearch ? ESSearchResults : Users;
  1619. return userCollection.findOne(this.userId, {
  1620. fields: {
  1621. profile: 1,
  1622. username: 1,
  1623. },
  1624. });
  1625. },
  1626. memberType() {
  1627. const user = Users.findOne(this.userId);
  1628. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1629. },
  1630. presenceStatusClassName() {
  1631. const user = Users.findOne(this.userId);
  1632. const userPresence = presences.findOne({ userId: this.userId });
  1633. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1634. else if (!userPresence) return 'disconnected';
  1635. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1636. return 'active';
  1637. else return 'idle';
  1638. },
  1639. isCardAssignee() {
  1640. const card = Template.parentData();
  1641. const cardAssignees = card.getAssignees();
  1642. return _.contains(cardAssignees, this.userId);
  1643. },
  1644. user() {
  1645. return Users.findOne(this.userId);
  1646. },
  1647. });
  1648. Template.cardAssigneePopup.events({
  1649. 'click .js-remove-assignee'() {
  1650. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1651. Popup.back();
  1652. },
  1653. 'click .js-edit-profile': Popup.open('editProfile'),
  1654. });