cardDetails.js 60 KB

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