cardDetails.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588
  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. 'submit .js-card-details-sort'(event) {
  330. event.preventDefault();
  331. const sort = parseFloat(this.currentComponent()
  332. .getValue()
  333. .trim());
  334. if (sort) {
  335. let card = this.data();
  336. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  337. }
  338. },
  339. 'keypress/paste input.js-edit-card-sort'() {
  340. let keyCode = event.keyCode;
  341. let charCode = String.fromCharCode(keyCode);
  342. let regex = new RegExp('[0-9.]');
  343. let ret = regex.test(charCode);
  344. return ret;
  345. },
  346. 'click .js-go-to-linked-card'() {
  347. Utils.goCardId(this.data().linkedId);
  348. },
  349. 'click .js-member': Popup.open('cardMember'),
  350. 'click .js-add-members': Popup.open('cardMembers'),
  351. 'click .js-assignee': Popup.open('cardAssignee'),
  352. 'click .js-add-assignees': Popup.open('cardAssignees'),
  353. 'click .js-add-labels': Popup.open('cardLabels'),
  354. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  355. 'click .js-start-date': Popup.open('editCardStartDate'),
  356. 'click .js-due-date': Popup.open('editCardDueDate'),
  357. 'click .js-end-date': Popup.open('editCardEndDate'),
  358. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  359. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  360. 'mouseenter .js-card-details'() {
  361. const parentComponent = this.parentComponent().parentComponent();
  362. //on mobile view parent is Board, not BoardBody.
  363. if (parentComponent === null) return;
  364. parentComponent.showOverlay.set(true);
  365. parentComponent.mouseHasEnterCardDetails = true;
  366. },
  367. 'mousedown .js-card-details'() {
  368. Session.set('cardDetailsIsDragging', false);
  369. Session.set('cardDetailsIsMouseDown', true);
  370. },
  371. 'mousemove .js-card-details'() {
  372. if (Session.get('cardDetailsIsMouseDown')) {
  373. Session.set('cardDetailsIsDragging', true);
  374. }
  375. },
  376. 'mouseup .js-card-details'() {
  377. Session.set('cardDetailsIsDragging', false);
  378. Session.set('cardDetailsIsMouseDown', false);
  379. },
  380. 'click #toggleButton'() {
  381. Meteor.call('toggleSystemMessages');
  382. },
  383. 'click .js-vote'(e) {
  384. const forIt = $(e.target).hasClass('js-vote-positive');
  385. let newState = null;
  386. if (
  387. this.data().voteState() === null ||
  388. (this.data().voteState() === false && forIt) ||
  389. (this.data().voteState() === true && !forIt)
  390. ) {
  391. newState = forIt;
  392. }
  393. this.data().setVote(Meteor.userId(), newState);
  394. },
  395. 'click .js-poker'(e) {
  396. let newState = null;
  397. if ($(e.target).hasClass('js-poker-vote-one')) {
  398. newState = 'one';
  399. this.data().setPoker(Meteor.userId(), newState);
  400. }
  401. if ($(e.target).hasClass('js-poker-vote-two')) {
  402. newState = 'two';
  403. this.data().setPoker(Meteor.userId(), newState);
  404. }
  405. if ($(e.target).hasClass('js-poker-vote-three')) {
  406. newState = 'three';
  407. this.data().setPoker(Meteor.userId(), newState);
  408. }
  409. if ($(e.target).hasClass('js-poker-vote-five')) {
  410. newState = 'five';
  411. this.data().setPoker(Meteor.userId(), newState);
  412. }
  413. if ($(e.target).hasClass('js-poker-vote-eight')) {
  414. newState = 'eight';
  415. this.data().setPoker(Meteor.userId(), newState);
  416. }
  417. if ($(e.target).hasClass('js-poker-vote-thirteen')) {
  418. newState = 'thirteen';
  419. this.data().setPoker(Meteor.userId(), newState);
  420. }
  421. if ($(e.target).hasClass('js-poker-vote-twenty')) {
  422. newState = 'twenty';
  423. this.data().setPoker(Meteor.userId(), newState);
  424. }
  425. if ($(e.target).hasClass('js-poker-vote-forty')) {
  426. newState = 'forty';
  427. this.data().setPoker(Meteor.userId(), newState);
  428. }
  429. if ($(e.target).hasClass('js-poker-vote-one-hundred')) {
  430. newState = 'oneHundred';
  431. this.data().setPoker(Meteor.userId(), newState);
  432. }
  433. if ($(e.target).hasClass('js-poker-vote-unsure')) {
  434. newState = 'unsure';
  435. this.data().setPoker(Meteor.userId(), newState);
  436. }
  437. },
  438. 'click .js-poker-finish'(e) {
  439. if ($(e.target).hasClass('js-poker-finish')) {
  440. e.preventDefault();
  441. const now = moment().format('YYYY-MM-DD HH:mm');
  442. this.data().setPokerEnd(now);
  443. }
  444. },
  445. 'click .js-poker-replay'(e) {
  446. if ($(e.target).hasClass('js-poker-replay')) {
  447. e.preventDefault();
  448. this.currentCard = this.currentData();
  449. this.currentCard.replayPoker();
  450. this.data().unsetPokerEnd();
  451. this.data().unsetPokerEstimation();
  452. }
  453. },
  454. 'click .js-poker-estimation'(event) {
  455. event.preventDefault();
  456. const ruleTitle = this.find('#pokerEstimation').value;
  457. if (ruleTitle !== undefined && ruleTitle !== '') {
  458. this.find('#pokerEstimation').value = '';
  459. if (ruleTitle) {
  460. this.data().setPokerEstimation(parseInt(ruleTitle, 10));
  461. } else {
  462. this.data().setPokerEstimation('');
  463. }
  464. }
  465. },
  466. },
  467. ];
  468. },
  469. }).register('cardDetails');
  470. // We extends the normal InlinedForm component to support UnsavedEdits draft
  471. // feature.
  472. (class extends InlinedForm {
  473. _getUnsavedEditKey() {
  474. return {
  475. fieldName: 'cardDescription',
  476. // XXX Recovering the currentCard identifier form a session variable is
  477. // fragile because this variable may change for instance if the route
  478. // change. We should use some component props instead.
  479. docId: Session.get('currentCard'),
  480. };
  481. }
  482. close(isReset = false) {
  483. if (this.isOpen.get() && !isReset) {
  484. const draft = this.getValue().trim();
  485. if (
  486. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  487. ) {
  488. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  489. }
  490. }
  491. super.close();
  492. }
  493. reset() {
  494. UnsavedEdits.reset(this._getUnsavedEditKey());
  495. this.close(true);
  496. }
  497. events() {
  498. const parentEvents = InlinedForm.prototype.events()[0];
  499. return [
  500. {
  501. ...parentEvents,
  502. 'click .js-close-inlined-form': this.reset,
  503. },
  504. ];
  505. }
  506. }.register('inlinedCardDescription'));
  507. Template.cardDetailsActionsPopup.helpers({
  508. isWatching() {
  509. return this.findWatcher(Meteor.userId());
  510. },
  511. isBoardAdmin() {
  512. return Meteor.user().isBoardAdmin();
  513. },
  514. canModifyCard() {
  515. return (
  516. Meteor.user() &&
  517. Meteor.user().isBoardMember() &&
  518. !Meteor.user().isCommentOnly()
  519. );
  520. },
  521. });
  522. Template.cardDetailsActionsPopup.events({
  523. 'click .js-members': Popup.open('cardMembers'),
  524. 'click .js-assignees': Popup.open('cardAssignees'),
  525. 'click .js-labels': Popup.open('cardLabels'),
  526. 'click .js-attachments': Popup.open('cardAttachments'),
  527. 'click .js-start-voting': Popup.open('cardStartVoting'),
  528. 'click .js-start-planning-poker': Popup.open('cardStartPlanningPoker'),
  529. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  530. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  531. 'click .js-start-date': Popup.open('editCardStartDate'),
  532. 'click .js-due-date': Popup.open('editCardDueDate'),
  533. 'click .js-end-date': Popup.open('editCardEndDate'),
  534. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  535. 'click .js-move-card': Popup.open('moveCard'),
  536. 'click .js-copy-card': Popup.open('copyCard'),
  537. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  538. 'click .js-set-card-color': Popup.open('setCardColor'),
  539. 'click .js-move-card-to-top'(event) {
  540. event.preventDefault();
  541. const minOrder = _.min(
  542. this.list()
  543. .cards(this.swimlaneId)
  544. .map((c) => c.sort),
  545. );
  546. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  547. },
  548. 'click .js-move-card-to-bottom'(event) {
  549. event.preventDefault();
  550. const maxOrder = _.max(
  551. this.list()
  552. .cards(this.swimlaneId)
  553. .map((c) => c.sort),
  554. );
  555. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  556. },
  557. 'click .js-archive'(event) {
  558. event.preventDefault();
  559. this.archive();
  560. Popup.close();
  561. },
  562. 'click .js-more': Popup.open('cardMore'),
  563. 'click .js-toggle-watch-card'() {
  564. const currentCard = this;
  565. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  566. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  567. if (!err && ret) Popup.close();
  568. });
  569. },
  570. });
  571. Template.editCardTitleForm.onRendered(function () {
  572. autosize(this.$('.js-edit-card-title'));
  573. });
  574. Template.editCardTitleForm.events({
  575. 'keydown .js-edit-card-title'(event) {
  576. // If enter key was pressed, submit the data
  577. // Unless the shift key is also being pressed
  578. if (event.keyCode === 13 && !event.shiftKey) {
  579. $('.js-submit-edit-card-title-form').click();
  580. }
  581. },
  582. });
  583. Template.editCardRequesterForm.onRendered(function () {
  584. autosize(this.$('.js-edit-card-requester'));
  585. });
  586. Template.editCardRequesterForm.events({
  587. 'keydown .js-edit-card-requester'(event) {
  588. // If enter key was pressed, submit the data
  589. if (event.keyCode === 13) {
  590. $('.js-submit-edit-card-requester-form').click();
  591. }
  592. },
  593. });
  594. Template.editCardAssignerForm.onRendered(function () {
  595. autosize(this.$('.js-edit-card-assigner'));
  596. });
  597. Template.editCardAssignerForm.events({
  598. 'keydown .js-edit-card-assigner'(event) {
  599. // If enter key was pressed, submit the data
  600. if (event.keyCode === 13) {
  601. $('.js-submit-edit-card-assigner-form').click();
  602. }
  603. },
  604. });
  605. Template.moveCardPopup.events({
  606. 'click .js-done'() {
  607. // XXX We should *not* get the currentCard from the global state, but
  608. // instead from a “component” state.
  609. const card = Cards.findOne(Session.get('currentCard'));
  610. const bSelect = $('.js-select-boards')[0];
  611. let boardId;
  612. // if we are a worker, we won't have a board select so we just use the
  613. // current boardId of the card.
  614. if (bSelect) boardId = bSelect.options[bSelect.selectedIndex].value;
  615. else boardId = card.boardId;
  616. const lSelect = $('.js-select-lists')[0];
  617. const listId = lSelect.options[lSelect.selectedIndex].value;
  618. const slSelect = $('.js-select-swimlanes')[0];
  619. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  620. card.move(boardId, swimlaneId, listId, 0);
  621. Popup.close();
  622. },
  623. });
  624. BlazeComponent.extendComponent({
  625. onCreated() {
  626. subManager.subscribe('board', Session.get('currentBoard'), false);
  627. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  628. },
  629. boards() {
  630. return Boards.find(
  631. {
  632. archived: false,
  633. 'members.userId': Meteor.userId(),
  634. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  635. },
  636. {
  637. sort: { sort: 1 /* boards default sorting */ },
  638. },
  639. );
  640. },
  641. swimlanes() {
  642. const board = Boards.findOne(this.selectedBoardId.get());
  643. return board.swimlanes();
  644. },
  645. aBoardLists() {
  646. const board = Boards.findOne(this.selectedBoardId.get());
  647. return board.lists();
  648. },
  649. events() {
  650. return [
  651. {
  652. 'change .js-select-boards'(event) {
  653. this.selectedBoardId.set($(event.currentTarget).val());
  654. subManager.subscribe('board', this.selectedBoardId.get(), false);
  655. },
  656. },
  657. ];
  658. },
  659. }).register('boardsAndLists');
  660. Template.copyCardPopup.events({
  661. 'click .js-done'() {
  662. const card = Cards.findOne(Session.get('currentCard'));
  663. const lSelect = $('.js-select-lists')[0];
  664. const listId = lSelect.options[lSelect.selectedIndex].value;
  665. const slSelect = $('.js-select-swimlanes')[0];
  666. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  667. const bSelect = $('.js-select-boards')[0];
  668. const boardId = bSelect.options[bSelect.selectedIndex].value;
  669. const textarea = $('#copy-card-title');
  670. const title = textarea.val().trim();
  671. // insert new card to the bottom of new list
  672. card.sort = Lists.findOne(card.listId).cards().count();
  673. if (title) {
  674. card.title = title;
  675. card.coverId = '';
  676. const _id = card.copy(boardId, swimlaneId, listId);
  677. // In case the filter is active we need to add the newly inserted card in
  678. // the list of exceptions -- cards that are not filtered. Otherwise the
  679. // card will disappear instantly.
  680. // See https://github.com/wekan/wekan/issues/80
  681. Filter.addException(_id);
  682. Popup.close();
  683. }
  684. },
  685. });
  686. Template.copyChecklistToManyCardsPopup.events({
  687. 'click .js-done'() {
  688. const card = Cards.findOne(Session.get('currentCard'));
  689. const oldId = card._id;
  690. card._id = null;
  691. const lSelect = $('.js-select-lists')[0];
  692. card.listId = lSelect.options[lSelect.selectedIndex].value;
  693. const slSelect = $('.js-select-swimlanes')[0];
  694. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  695. const bSelect = $('.js-select-boards')[0];
  696. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  697. const textarea = $('#copy-card-title');
  698. const titleEntry = textarea.val().trim();
  699. // insert new card to the bottom of new list
  700. card.sort = Lists.findOne(card.listId).cards().count();
  701. if (titleEntry) {
  702. const titleList = JSON.parse(titleEntry);
  703. for (let i = 0; i < titleList.length; i++) {
  704. const obj = titleList[i];
  705. card.title = obj.title;
  706. card.description = obj.description;
  707. card.coverId = '';
  708. const _id = Cards.insert(card);
  709. // In case the filter is active we need to add the newly inserted card in
  710. // the list of exceptions -- cards that are not filtered. Otherwise the
  711. // card will disappear instantly.
  712. // See https://github.com/wekan/wekan/issues/80
  713. Filter.addException(_id);
  714. // copy checklists
  715. Checklists.find({ cardId: oldId }).forEach((ch) => {
  716. ch.copy(_id);
  717. });
  718. // copy subtasks
  719. const cursor = Cards.find({ parentId: oldId });
  720. cursor.forEach(function () {
  721. 'use strict';
  722. const subtask = arguments[0];
  723. subtask.parentId = _id;
  724. subtask._id = null;
  725. /* const newSubtaskId = */ Cards.insert(subtask);
  726. });
  727. // copy card comments
  728. CardComments.find({ cardId: oldId }).forEach((cmt) => {
  729. cmt.copy(_id);
  730. });
  731. }
  732. Popup.close();
  733. }
  734. },
  735. });
  736. BlazeComponent.extendComponent({
  737. onCreated() {
  738. this.currentCard = this.currentData();
  739. this.currentColor = new ReactiveVar(this.currentCard.color);
  740. },
  741. colors() {
  742. return ALLOWED_COLORS.map((color) => ({ color, name: '' }));
  743. },
  744. isSelected(color) {
  745. if (this.currentColor.get() === null) {
  746. return color === 'white';
  747. }
  748. return this.currentColor.get() === color;
  749. },
  750. events() {
  751. return [
  752. {
  753. 'click .js-palette-color'() {
  754. this.currentColor.set(this.currentData().color);
  755. },
  756. 'click .js-submit'() {
  757. this.currentCard.setColor(this.currentColor.get());
  758. Popup.close();
  759. },
  760. 'click .js-remove-color'() {
  761. this.currentCard.setColor(null);
  762. Popup.close();
  763. },
  764. },
  765. ];
  766. },
  767. }).register('setCardColorPopup');
  768. BlazeComponent.extendComponent({
  769. onCreated() {
  770. this.currentCard = this.currentData();
  771. this.parentBoard = new ReactiveVar(null);
  772. this.parentCard = this.currentCard.parentCard();
  773. if (this.parentCard) {
  774. const list = $('.js-field-parent-card');
  775. list.val(this.parentCard._id);
  776. this.parentBoard.set(this.parentCard.board()._id);
  777. } else {
  778. this.parentBoard.set(null);
  779. }
  780. },
  781. boards() {
  782. return Boards.find(
  783. {
  784. archived: false,
  785. 'members.userId': Meteor.userId(),
  786. _id: {
  787. $ne: Meteor.user().getTemplatesBoardId(),
  788. },
  789. },
  790. {
  791. sort: { sort: 1 /* boards default sorting */ },
  792. },
  793. );
  794. },
  795. cards() {
  796. const currentId = Session.get('currentCard');
  797. if (this.parentBoard.get()) {
  798. return Cards.find({
  799. boardId: this.parentBoard.get(),
  800. _id: { $ne: currentId },
  801. });
  802. } else {
  803. return [];
  804. }
  805. },
  806. isParentBoard() {
  807. const board = this.currentData();
  808. if (this.parentBoard.get()) {
  809. return board._id === this.parentBoard.get();
  810. }
  811. return false;
  812. },
  813. isParentCard() {
  814. const card = this.currentData();
  815. if (this.parentCard) {
  816. return card._id === this.parentCard;
  817. }
  818. return false;
  819. },
  820. setParentCardId(cardId) {
  821. if (cardId) {
  822. this.parentCard = Cards.findOne(cardId);
  823. } else {
  824. this.parentCard = null;
  825. }
  826. this.currentCard.setParentId(cardId);
  827. },
  828. events() {
  829. return [
  830. {
  831. 'click .js-copy-card-link-to-clipboard'() {
  832. // Clipboard code from:
  833. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  834. const StringToCopyElement = document.getElementById('cardURL');
  835. StringToCopyElement.select();
  836. if (document.execCommand('copy')) {
  837. StringToCopyElement.blur();
  838. } else {
  839. document.getElementById('cardURL').selectionStart = 0;
  840. document.getElementById('cardURL').selectionEnd = 999;
  841. document.execCommand('copy');
  842. if (window.getSelection) {
  843. if (window.getSelection().empty) {
  844. // Chrome
  845. window.getSelection().empty();
  846. } else if (window.getSelection().removeAllRanges) {
  847. // Firefox
  848. window.getSelection().removeAllRanges();
  849. }
  850. } else if (document.selection) {
  851. // IE?
  852. document.selection.empty();
  853. }
  854. }
  855. },
  856. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  857. Popup.close();
  858. // verify that there are no linked cards
  859. if (Cards.find({ linkedId: this._id }).count() === 0) {
  860. Cards.remove(this._id);
  861. } else {
  862. // TODO: Maybe later we can list where the linked cards are.
  863. // Now here is popup with a hint that the card cannot be deleted
  864. // as there are linked cards.
  865. // Related:
  866. // client/components/lists/listHeader.js about line 248
  867. // https://github.com/wekan/wekan/issues/2785
  868. const message = `${TAPi18n.__(
  869. 'delete-linked-card-before-this-card',
  870. )} linkedId: ${
  871. this._id
  872. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  873. alert(message);
  874. }
  875. Utils.goBoardId(this.boardId);
  876. }),
  877. 'change .js-field-parent-board'(event) {
  878. const selection = $(event.currentTarget).val();
  879. const list = $('.js-field-parent-card');
  880. if (selection === 'none') {
  881. this.parentBoard.set(null);
  882. } else {
  883. subManager.subscribe('board', $(event.currentTarget).val(), false);
  884. this.parentBoard.set(selection);
  885. list.prop('disabled', false);
  886. }
  887. this.setParentCardId(null);
  888. },
  889. 'change .js-field-parent-card'(event) {
  890. const selection = $(event.currentTarget).val();
  891. this.setParentCardId(selection);
  892. },
  893. },
  894. ];
  895. },
  896. }).register('cardMorePopup');
  897. BlazeComponent.extendComponent({
  898. onCreated() {
  899. this.currentCard = this.currentData();
  900. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  901. },
  902. events() {
  903. return [
  904. {
  905. 'click .js-end-date': Popup.open('editVoteEndDate'),
  906. 'submit .edit-vote-question'(evt) {
  907. evt.preventDefault();
  908. const voteQuestion = evt.target.vote.value;
  909. const publicVote = $('#vote-public').hasClass('is-checked');
  910. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  911. 'is-checked',
  912. );
  913. const endString = this.currentCard.getVoteEnd();
  914. this.currentCard.setVoteQuestion(
  915. voteQuestion,
  916. publicVote,
  917. allowNonBoardMembers,
  918. );
  919. if (endString) {
  920. this.currentCard.setVoteEnd(endString);
  921. }
  922. Popup.close();
  923. },
  924. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  925. event.preventDefault();
  926. this.currentCard.unsetVote();
  927. Popup.close();
  928. }),
  929. 'click a.js-toggle-vote-public'(event) {
  930. event.preventDefault();
  931. $('#vote-public').toggleClass('is-checked');
  932. },
  933. 'click a.js-toggle-vote-allow-non-members'(event) {
  934. event.preventDefault();
  935. $('#vote-allow-non-members').toggleClass('is-checked');
  936. },
  937. },
  938. ];
  939. },
  940. }).register('cardStartVotingPopup');
  941. // editVoteEndDatePopup
  942. (class extends DatePicker {
  943. onCreated() {
  944. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  945. this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
  946. }
  947. events() {
  948. return [
  949. {
  950. 'submit .edit-date'(evt) {
  951. evt.preventDefault();
  952. // if no time was given, init with 12:00
  953. const time =
  954. evt.target.time.value ||
  955. moment(new Date().setHours(12, 0, 0)).format('LT');
  956. const dateString = `${evt.target.date.value} ${time}`;
  957. /*
  958. const newDate = moment(dateString, 'L LT', true);
  959. if (newDate.isValid()) {
  960. // if active vote - store it
  961. if (this.currentData().getVoteQuestion()) {
  962. this._storeDate(newDate.toDate());
  963. Popup.close();
  964. } else {
  965. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  966. Popup.back();
  967. }
  968. */
  969. // Try to parse different date formats of all languages.
  970. // This code is same for vote and planning poker.
  971. const usaDate = moment(dateString, 'L LT', true);
  972. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  973. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  974. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  975. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  976. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  977. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  978. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  979. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  980. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  981. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  982. // greekDate does not work: el Greek Ελληνικά ,
  983. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  984. // where MM is maybe some text like AM/PM ?
  985. // Also some other languages that have non-ascii characters in dates
  986. // do not work.
  987. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  988. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  989. if (usaDate.isValid()) {
  990. // if active poker - store it
  991. if (this.currentData().getPokerQuestion()) {
  992. this._storeDate(usaDate.toDate());
  993. Popup.close();
  994. } else {
  995. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  996. Popup.back();
  997. }
  998. } else if (euroAmDate.isValid()) {
  999. // if active poker - store it
  1000. if (this.currentData().getPokerQuestion()) {
  1001. this._storeDate(euroAmDate.toDate());
  1002. Popup.close();
  1003. } else {
  1004. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1005. Popup.back();
  1006. }
  1007. } else if (euro24hDate.isValid()) {
  1008. // if active poker - store it
  1009. if (this.currentData().getPokerQuestion()) {
  1010. this._storeDate(euro24hDate.toDate());
  1011. this.card.setPokerEnd(euro24hDate.toDate());
  1012. Popup.close();
  1013. } else {
  1014. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1015. Popup.back();
  1016. }
  1017. } else if (eurodotDate.isValid()) {
  1018. // if active poker - store it
  1019. if (this.currentData().getPokerQuestion()) {
  1020. this._storeDate(eurodotDate.toDate());
  1021. this.card.setPokerEnd(eurodotDate.toDate());
  1022. Popup.close();
  1023. } else {
  1024. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1025. Popup.back();
  1026. }
  1027. } else if (minusDate.isValid()) {
  1028. // if active poker - store it
  1029. if (this.currentData().getPokerQuestion()) {
  1030. this._storeDate(minusDate.toDate());
  1031. this.card.setPokerEnd(minusDate.toDate());
  1032. Popup.close();
  1033. } else {
  1034. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1035. Popup.back();
  1036. }
  1037. } else if (slashDate.isValid()) {
  1038. // if active poker - store it
  1039. if (this.currentData().getPokerQuestion()) {
  1040. this._storeDate(slashDate.toDate());
  1041. this.card.setPokerEnd(slashDate.toDate());
  1042. Popup.close();
  1043. } else {
  1044. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1045. Popup.back();
  1046. }
  1047. } else if (dotDate.isValid()) {
  1048. // if active poker - store it
  1049. if (this.currentData().getPokerQuestion()) {
  1050. this._storeDate(dotDate.toDate());
  1051. this.card.setPokerEnd(dotDate.toDate());
  1052. Popup.close();
  1053. } else {
  1054. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1055. Popup.back();
  1056. }
  1057. } else if (brezhonegDate.isValid()) {
  1058. // if active poker - store it
  1059. if (this.currentData().getPokerQuestion()) {
  1060. this._storeDate(brezhonegDate.toDate());
  1061. this.card.setPokerEnd(brezhonegDate.toDate());
  1062. Popup.close();
  1063. } else {
  1064. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1065. Popup.back();
  1066. }
  1067. } else if (hrvatskiDate.isValid()) {
  1068. // if active poker - store it
  1069. if (this.currentData().getPokerQuestion()) {
  1070. this._storeDate(hrvatskiDate.toDate());
  1071. this.card.setPokerEnd(hrvatskiDate.toDate());
  1072. Popup.close();
  1073. } else {
  1074. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1075. Popup.back();
  1076. }
  1077. } else if (latviaDate.isValid()) {
  1078. // if active poker - store it
  1079. if (this.currentData().getPokerQuestion()) {
  1080. this._storeDate(latviaDate.toDate());
  1081. this.card.setPokerEnd(latviaDate.toDate());
  1082. Popup.close();
  1083. } else {
  1084. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1085. Popup.back();
  1086. }
  1087. } else if (nederlandsDate.isValid()) {
  1088. // if active poker - store it
  1089. if (this.currentData().getPokerQuestion()) {
  1090. this._storeDate(nederlandsDate.toDate());
  1091. this.card.setPokerEnd(nederlandsDate.toDate());
  1092. Popup.close();
  1093. } else {
  1094. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1095. Popup.back();
  1096. }
  1097. } else if (greekDate.isValid()) {
  1098. // if active poker - store it
  1099. if (this.currentData().getPokerQuestion()) {
  1100. this._storeDate(greekDate.toDate());
  1101. this.card.setPokerEnd(greekDate.toDate());
  1102. Popup.close();
  1103. } else {
  1104. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1105. Popup.back();
  1106. }
  1107. } else if (macedonianDate.isValid()) {
  1108. // if active poker - store it
  1109. if (this.currentData().getPokerQuestion()) {
  1110. this._storeDate(macedonianDate.toDate());
  1111. this.card.setPokerEnd(macedonianDate.toDate());
  1112. Popup.close();
  1113. } else {
  1114. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1115. Popup.back();
  1116. }
  1117. } else {
  1118. this.error.set('invalid-date');
  1119. evt.target.date.focus();
  1120. }
  1121. },
  1122. 'click .js-delete-date'(evt) {
  1123. evt.preventDefault();
  1124. this._deleteDate();
  1125. Popup.close();
  1126. },
  1127. },
  1128. ];
  1129. }
  1130. _storeDate(newDate) {
  1131. this.card.setVoteEnd(newDate);
  1132. }
  1133. _deleteDate() {
  1134. this.card.unsetVoteEnd();
  1135. }
  1136. }.register('editVoteEndDatePopup'));
  1137. BlazeComponent.extendComponent({
  1138. onCreated() {
  1139. this.currentCard = this.currentData();
  1140. this.pokerQuestion = new ReactiveVar(this.currentCard.pokerQuestion);
  1141. },
  1142. events() {
  1143. return [
  1144. {
  1145. 'click .js-end-date': Popup.open('editPokerEndDate'),
  1146. 'submit .edit-poker-question'(evt) {
  1147. evt.preventDefault();
  1148. const pokerQuestion = true;
  1149. const allowNonBoardMembers = $('#poker-allow-non-members').hasClass(
  1150. 'is-checked',
  1151. );
  1152. const endString = this.currentCard.getPokerEnd();
  1153. this.currentCard.setPokerQuestion(
  1154. pokerQuestion,
  1155. allowNonBoardMembers,
  1156. );
  1157. if (endString) {
  1158. this.currentCard.setPokerEnd(endString);
  1159. }
  1160. Popup.close();
  1161. },
  1162. 'click .js-remove-poker': Popup.afterConfirm('deletePoker', (event) => {
  1163. event.preventDefault();
  1164. this.currentCard.unsetPoker();
  1165. Popup.close();
  1166. }),
  1167. 'click a.js-toggle-poker-allow-non-members'(event) {
  1168. event.preventDefault();
  1169. $('#poker-allow-non-members').toggleClass('is-checked');
  1170. },
  1171. },
  1172. ];
  1173. },
  1174. }).register('cardStartPlanningPokerPopup');
  1175. // editPokerEndDatePopup
  1176. (class extends DatePicker {
  1177. onCreated() {
  1178. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  1179. this.data().getPokerEnd() &&
  1180. this.date.set(moment(this.data().getPokerEnd()));
  1181. }
  1182. /*
  1183. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1184. to make detecting all date formats not necessary,
  1185. but got error "language mk does not exist".
  1186. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1187. datepicker format that could be used to detect date format?
  1188. dateFormat() {
  1189. return moment.localeData().longDateFormat('L');
  1190. }
  1191. timeFormat() {
  1192. return moment.localeData().longDateFormat('LT');
  1193. }
  1194. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1195. */
  1196. events() {
  1197. return [
  1198. {
  1199. 'submit .edit-date'(evt) {
  1200. evt.preventDefault();
  1201. // if no time was given, init with 12:00
  1202. const time =
  1203. evt.target.time.value ||
  1204. moment(new Date().setHours(12, 0, 0)).format('LT');
  1205. const dateString = `${evt.target.date.value} ${time}`;
  1206. /*
  1207. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1208. to make detecting all date formats not necessary,
  1209. but got error "language mk does not exist".
  1210. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1211. datepicker format that could be used to detect date format?
  1212. const newDate = moment(dateString, dateformat() + ' ' + timeformat(), true);
  1213. if (newDate.isValid()) {
  1214. // if active poker - store it
  1215. if (this.currentData().getPokerQuestion()) {
  1216. this._storeDate(newDate.toDate());
  1217. Popup.close();
  1218. } else {
  1219. this.currentData().poker = { end: newDate.toDate() }; // set poker end temp
  1220. Popup.back();
  1221. }
  1222. */
  1223. // Try to parse different date formats of all languages.
  1224. // This code is same for vote and planning poker.
  1225. const usaDate = moment(dateString, 'L LT', true);
  1226. const euroAmDate = moment(dateString, 'DD.MM.YYYY LT', true);
  1227. const euro24hDate = moment(dateString, 'DD.MM.YYYY HH.mm', true);
  1228. const eurodotDate = moment(dateString, 'DD.MM.YYYY HH:mm', true);
  1229. const minusDate = moment(dateString, 'YYYY-MM-DD HH:mm', true);
  1230. const slashDate = moment(dateString, 'DD/MM/YYYY HH.mm', true);
  1231. const dotDate = moment(dateString, 'DD/MM/YYYY HH:mm', true);
  1232. const brezhonegDate = moment(dateString, 'DD/MM/YYYY h[e]mm A', true);
  1233. const hrvatskiDate = moment(dateString, 'DD. MM. YYYY H:mm', true);
  1234. const latviaDate = moment(dateString, 'YYYY.MM.DD. H:mm', true);
  1235. const nederlandsDate = moment(dateString, 'DD-MM-YYYY HH:mm', true);
  1236. // greekDate does not work: el Greek Ελληνικά ,
  1237. // it has date format DD/MM/YYYY h:mm MM like 20/06/2021 11:15 MM
  1238. // where MM is maybe some text like AM/PM ?
  1239. // Also some other languages that have non-ascii characters in dates
  1240. // do not work.
  1241. const greekDate = moment(dateString, 'DD/MM/YYYY h:mm A', true);
  1242. const macedonianDate = moment(dateString, 'D.MM.YYYY H:mm', true);
  1243. if (usaDate.isValid()) {
  1244. // if active poker - store it
  1245. if (this.currentData().getPokerQuestion()) {
  1246. this._storeDate(usaDate.toDate());
  1247. Popup.close();
  1248. } else {
  1249. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1250. Popup.back();
  1251. }
  1252. } else if (euroAmDate.isValid()) {
  1253. // if active poker - store it
  1254. if (this.currentData().getPokerQuestion()) {
  1255. this._storeDate(euroAmDate.toDate());
  1256. Popup.close();
  1257. } else {
  1258. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1259. Popup.back();
  1260. }
  1261. } else if (euro24hDate.isValid()) {
  1262. // if active poker - store it
  1263. if (this.currentData().getPokerQuestion()) {
  1264. this._storeDate(euro24hDate.toDate());
  1265. this.card.setPokerEnd(euro24hDate.toDate());
  1266. Popup.close();
  1267. } else {
  1268. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1269. Popup.back();
  1270. }
  1271. } else if (eurodotDate.isValid()) {
  1272. // if active poker - store it
  1273. if (this.currentData().getPokerQuestion()) {
  1274. this._storeDate(eurodotDate.toDate());
  1275. this.card.setPokerEnd(eurodotDate.toDate());
  1276. Popup.close();
  1277. } else {
  1278. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1279. Popup.back();
  1280. }
  1281. } else if (minusDate.isValid()) {
  1282. // if active poker - store it
  1283. if (this.currentData().getPokerQuestion()) {
  1284. this._storeDate(minusDate.toDate());
  1285. this.card.setPokerEnd(minusDate.toDate());
  1286. Popup.close();
  1287. } else {
  1288. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1289. Popup.back();
  1290. }
  1291. } else if (slashDate.isValid()) {
  1292. // if active poker - store it
  1293. if (this.currentData().getPokerQuestion()) {
  1294. this._storeDate(slashDate.toDate());
  1295. this.card.setPokerEnd(slashDate.toDate());
  1296. Popup.close();
  1297. } else {
  1298. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1299. Popup.back();
  1300. }
  1301. } else if (dotDate.isValid()) {
  1302. // if active poker - store it
  1303. if (this.currentData().getPokerQuestion()) {
  1304. this._storeDate(dotDate.toDate());
  1305. this.card.setPokerEnd(dotDate.toDate());
  1306. Popup.close();
  1307. } else {
  1308. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1309. Popup.back();
  1310. }
  1311. } else if (brezhonegDate.isValid()) {
  1312. // if active poker - store it
  1313. if (this.currentData().getPokerQuestion()) {
  1314. this._storeDate(brezhonegDate.toDate());
  1315. this.card.setPokerEnd(brezhonegDate.toDate());
  1316. Popup.close();
  1317. } else {
  1318. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1319. Popup.back();
  1320. }
  1321. } else if (hrvatskiDate.isValid()) {
  1322. // if active poker - store it
  1323. if (this.currentData().getPokerQuestion()) {
  1324. this._storeDate(hrvatskiDate.toDate());
  1325. this.card.setPokerEnd(hrvatskiDate.toDate());
  1326. Popup.close();
  1327. } else {
  1328. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1329. Popup.back();
  1330. }
  1331. } else if (latviaDate.isValid()) {
  1332. // if active poker - store it
  1333. if (this.currentData().getPokerQuestion()) {
  1334. this._storeDate(latviaDate.toDate());
  1335. this.card.setPokerEnd(latviaDate.toDate());
  1336. Popup.close();
  1337. } else {
  1338. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1339. Popup.back();
  1340. }
  1341. } else if (nederlandsDate.isValid()) {
  1342. // if active poker - store it
  1343. if (this.currentData().getPokerQuestion()) {
  1344. this._storeDate(nederlandsDate.toDate());
  1345. this.card.setPokerEnd(nederlandsDate.toDate());
  1346. Popup.close();
  1347. } else {
  1348. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1349. Popup.back();
  1350. }
  1351. } else if (greekDate.isValid()) {
  1352. // if active poker - store it
  1353. if (this.currentData().getPokerQuestion()) {
  1354. this._storeDate(greekDate.toDate());
  1355. this.card.setPokerEnd(greekDate.toDate());
  1356. Popup.close();
  1357. } else {
  1358. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1359. Popup.back();
  1360. }
  1361. } else if (macedonianDate.isValid()) {
  1362. // if active poker - store it
  1363. if (this.currentData().getPokerQuestion()) {
  1364. this._storeDate(macedonianDate.toDate());
  1365. this.card.setPokerEnd(macedonianDate.toDate());
  1366. Popup.close();
  1367. } else {
  1368. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1369. Popup.back();
  1370. }
  1371. } else {
  1372. // this.error.set('invalid-date);
  1373. this.error.set('invalid-date' + ' ' + dateString);
  1374. evt.target.date.focus();
  1375. }
  1376. },
  1377. 'click .js-delete-date'(evt) {
  1378. evt.preventDefault();
  1379. this._deleteDate();
  1380. Popup.close();
  1381. },
  1382. },
  1383. ];
  1384. }
  1385. _storeDate(newDate) {
  1386. this.card.setPokerEnd(newDate);
  1387. }
  1388. _deleteDate() {
  1389. this.card.unsetPokerEnd();
  1390. }
  1391. }.register('editPokerEndDatePopup'));
  1392. // Close the card details pane by pressing escape
  1393. EscapeActions.register(
  1394. 'detailsPane',
  1395. () => {
  1396. if (Session.get('cardDetailsIsDragging')) {
  1397. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1398. Session.set('cardDetailsIsDragging', false);
  1399. Session.set('cardDetailsIsMouseDown', false);
  1400. } else {
  1401. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1402. Utils.goBoardId(Session.get('currentBoard'));
  1403. }
  1404. },
  1405. () => {
  1406. return !Session.equals('currentCard', null);
  1407. },
  1408. {
  1409. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1410. },
  1411. );
  1412. Template.cardAssigneesPopup.events({
  1413. 'click .js-select-assignee'(event) {
  1414. const card = Cards.findOne(Session.get('currentCard'));
  1415. const assigneeId = this.userId;
  1416. card.toggleAssignee(assigneeId);
  1417. event.preventDefault();
  1418. },
  1419. });
  1420. Template.cardAssigneesPopup.helpers({
  1421. isCardAssignee() {
  1422. const card = Template.parentData();
  1423. const cardAssignees = card.getAssignees();
  1424. return _.contains(cardAssignees, this.userId);
  1425. },
  1426. user() {
  1427. return Users.findOne(this.userId);
  1428. },
  1429. });
  1430. Template.cardAssigneePopup.helpers({
  1431. userData() {
  1432. // We need to handle a special case for the search results provided by the
  1433. // `matteodem:easy-search` package. Since these results gets published in a
  1434. // separate collection, and not in the standard Meteor.Users collection as
  1435. // expected, we use a component parameter ("property") to distinguish the
  1436. // two cases.
  1437. const userCollection = this.esSearch ? ESSearchResults : Users;
  1438. return userCollection.findOne(this.userId, {
  1439. fields: {
  1440. profile: 1,
  1441. username: 1,
  1442. },
  1443. });
  1444. },
  1445. memberType() {
  1446. const user = Users.findOne(this.userId);
  1447. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1448. },
  1449. presenceStatusClassName() {
  1450. const user = Users.findOne(this.userId);
  1451. const userPresence = presences.findOne({ userId: this.userId });
  1452. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1453. else if (!userPresence) return 'disconnected';
  1454. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1455. return 'active';
  1456. else return 'idle';
  1457. },
  1458. isCardAssignee() {
  1459. const card = Template.parentData();
  1460. const cardAssignees = card.getAssignees();
  1461. return _.contains(cardAssignees, this.userId);
  1462. },
  1463. user() {
  1464. return Users.findOne(this.userId);
  1465. },
  1466. });
  1467. Template.cardAssigneePopup.events({
  1468. 'click .js-remove-assignee'() {
  1469. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1470. Popup.close();
  1471. },
  1472. 'click .js-edit-profile': Popup.open('editProfile'),
  1473. });