cardDetails.js 53 KB

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