cardDetails.js 60 KB

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