cardDetails.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  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. const $checklistsDom = this.$('.card-checklist-items');
  187. $checklistsDom.sortable({
  188. tolerance: 'pointer',
  189. helper: 'clone',
  190. handle: '.checklist-title',
  191. items: '.js-checklist',
  192. placeholder: 'checklist placeholder',
  193. distance: 7,
  194. start(evt, ui) {
  195. ui.placeholder.height(ui.helper.height());
  196. EscapeActions.clickExecute(evt.target, 'inlinedForm');
  197. },
  198. stop(evt, ui) {
  199. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  200. if (prevChecklist) {
  201. prevChecklist = Blaze.getData(prevChecklist).checklist;
  202. }
  203. let nextChecklist = ui.item.next('.js-checklist').get(0);
  204. if (nextChecklist) {
  205. nextChecklist = Blaze.getData(nextChecklist).checklist;
  206. }
  207. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  208. $checklistsDom.sortable('cancel');
  209. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  210. Checklists.update(checklist._id, {
  211. $set: {
  212. sort: sortIndex.base,
  213. },
  214. });
  215. },
  216. });
  217. const $subtasksDom = this.$('.card-subtasks-items');
  218. $subtasksDom.sortable({
  219. tolerance: 'pointer',
  220. helper: 'clone',
  221. handle: '.subtask-title',
  222. items: '.js-subtasks',
  223. placeholder: 'subtasks placeholder',
  224. distance: 7,
  225. start(evt, ui) {
  226. ui.placeholder.height(ui.helper.height());
  227. EscapeActions.executeUpTo('popup-close');
  228. },
  229. stop(evt, ui) {
  230. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  231. if (prevChecklist) {
  232. prevChecklist = Blaze.getData(prevChecklist).subtask;
  233. }
  234. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  235. if (nextChecklist) {
  236. nextChecklist = Blaze.getData(nextChecklist).subtask;
  237. }
  238. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  239. $subtasksDom.sortable('cancel');
  240. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  241. Subtasks.update(subtask._id, {
  242. $set: {
  243. subtaskSort: sortIndex.base,
  244. },
  245. });
  246. },
  247. });
  248. function userIsMember() {
  249. return Meteor.user() && Meteor.user().isBoardMember();
  250. }
  251. // Disable sorting if the current user is not a board member
  252. this.autorun(() => {
  253. const disabled = !userIsMember();
  254. if (
  255. $checklistsDom.data('uiSortable') ||
  256. $checklistsDom.data('sortable')
  257. ) {
  258. $checklistsDom.sortable('option', 'disabled', disabled);
  259. if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
  260. $checklistsDom.sortable({ handle: '.checklist-handle' });
  261. }
  262. }
  263. if ($subtasksDom.data('uiSortable') || $subtasksDom.data('sortable')) {
  264. $subtasksDom.sortable('option', 'disabled', disabled);
  265. }
  266. });
  267. },
  268. onDestroyed() {
  269. if (this.parentComponent() === null) return;
  270. const parentComponent = this.parentComponent().parentComponent();
  271. //on mobile view parent is Board, not board body.
  272. if (parentComponent === null) return;
  273. parentComponent.showOverlay.set(false);
  274. },
  275. events() {
  276. const events = {
  277. [`${CSSEvents.transitionend} .js-card-details`]() {
  278. this.isLoaded.set(true);
  279. },
  280. [`${CSSEvents.animationend} .js-card-details`]() {
  281. this.isLoaded.set(true);
  282. },
  283. };
  284. return [
  285. {
  286. ...events,
  287. 'click .js-close-card-details'() {
  288. Utils.goBoardId(this.data().boardId);
  289. },
  290. 'click .js-copy-link'(event) {
  291. event.preventDefault();
  292. const promise = Utils.copyTextToClipboard(event.target.href);
  293. const $tooltip = this.$('.card-details-header .copied-tooltip');
  294. Utils.showCopied(promise, $tooltip);
  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. 'keydown input.js-edit-card-sort'(evt) {
  330. // enter = save
  331. if (evt.keyCode === 13) {
  332. this.find('button[type=submit]').click();
  333. }
  334. },
  335. 'submit .js-card-details-sort'(event) {
  336. event.preventDefault();
  337. const sort = parseFloat(this.currentComponent()
  338. .getValue()
  339. .trim());
  340. if (!Number.isNaN(sort)) {
  341. let card = this.data();
  342. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  343. }
  344. },
  345. 'change .js-select-card-details-lists'(event) {
  346. let card = this.data();
  347. const listSelect = this.$('.js-select-card-details-lists')[0];
  348. const listId = listSelect.options[listSelect.selectedIndex].value;
  349. const minOrder = card.getMinSort(listId, card.swimlaneId);
  350. card.move(card.boardId, card.swimlaneId, listId, minOrder - 1);
  351. },
  352. 'click .js-go-to-linked-card'() {
  353. Utils.goCardId(this.data().linkedId);
  354. },
  355. 'click .js-member': Popup.open('cardMember'),
  356. 'click .js-add-members': Popup.open('cardMembers'),
  357. 'click .js-assignee': Popup.open('cardAssignee'),
  358. 'click .js-add-assignees': Popup.open('cardAssignees'),
  359. 'click .js-add-labels': Popup.open('cardLabels'),
  360. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  361. 'click .js-start-date': Popup.open('editCardStartDate'),
  362. 'click .js-due-date': Popup.open('editCardDueDate'),
  363. 'click .js-end-date': Popup.open('editCardEndDate'),
  364. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  365. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  366. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  367. 'mouseenter .js-card-details'() {
  368. if (this.parentComponent() === null) return;
  369. const parentComponent = this.parentComponent().parentComponent();
  370. //on mobile view parent is Board, not BoardBody.
  371. if (parentComponent === null) return;
  372. parentComponent.showOverlay.set(true);
  373. parentComponent.mouseHasEnterCardDetails = true;
  374. },
  375. 'mousedown .js-card-details'() {
  376. Session.set('cardDetailsIsDragging', false);
  377. Session.set('cardDetailsIsMouseDown', true);
  378. },
  379. 'mousemove .js-card-details'() {
  380. if (Session.get('cardDetailsIsMouseDown')) {
  381. Session.set('cardDetailsIsDragging', true);
  382. }
  383. },
  384. 'mouseup .js-card-details'() {
  385. Session.set('cardDetailsIsDragging', false);
  386. Session.set('cardDetailsIsMouseDown', false);
  387. },
  388. 'click #toggleButton'() {
  389. Meteor.call('toggleSystemMessages');
  390. },
  391. 'click #toggleCustomFieldsGridButton'() {
  392. Meteor.call('toggleCustomFieldsGrid');
  393. },
  394. 'click .js-maximize-card-details'() {
  395. Meteor.call('toggleCardMaximized');
  396. autosize($('.card-details'));
  397. if (!Utils.isMiniScreen()) {
  398. Meteor.setTimeout(() => {
  399. this.scrollParentContainer();
  400. }, 500);
  401. }
  402. },
  403. 'click .js-minimize-card-details'() {
  404. Meteor.call('toggleCardMaximized');
  405. autosize($('.card-details'));
  406. if (!Utils.isMiniScreen()) {
  407. Meteor.setTimeout(() => {
  408. this.scrollParentContainer();
  409. }, 500);
  410. }
  411. },
  412. 'click .js-vote'(e) {
  413. const forIt = $(e.target).hasClass('js-vote-positive');
  414. let newState = null;
  415. if (
  416. this.data().voteState() === null ||
  417. (this.data().voteState() === false && forIt) ||
  418. (this.data().voteState() === true && !forIt)
  419. ) {
  420. newState = forIt;
  421. }
  422. this.data().setVote(Meteor.userId(), newState);
  423. },
  424. 'click .js-poker'(e) {
  425. let newState = null;
  426. if ($(e.target).hasClass('js-poker-vote-one')) {
  427. newState = 'one';
  428. this.data().setPoker(Meteor.userId(), newState);
  429. }
  430. if ($(e.target).hasClass('js-poker-vote-two')) {
  431. newState = 'two';
  432. this.data().setPoker(Meteor.userId(), newState);
  433. }
  434. if ($(e.target).hasClass('js-poker-vote-three')) {
  435. newState = 'three';
  436. this.data().setPoker(Meteor.userId(), newState);
  437. }
  438. if ($(e.target).hasClass('js-poker-vote-five')) {
  439. newState = 'five';
  440. this.data().setPoker(Meteor.userId(), newState);
  441. }
  442. if ($(e.target).hasClass('js-poker-vote-eight')) {
  443. newState = 'eight';
  444. this.data().setPoker(Meteor.userId(), newState);
  445. }
  446. if ($(e.target).hasClass('js-poker-vote-thirteen')) {
  447. newState = 'thirteen';
  448. this.data().setPoker(Meteor.userId(), newState);
  449. }
  450. if ($(e.target).hasClass('js-poker-vote-twenty')) {
  451. newState = 'twenty';
  452. this.data().setPoker(Meteor.userId(), newState);
  453. }
  454. if ($(e.target).hasClass('js-poker-vote-forty')) {
  455. newState = 'forty';
  456. this.data().setPoker(Meteor.userId(), newState);
  457. }
  458. if ($(e.target).hasClass('js-poker-vote-one-hundred')) {
  459. newState = 'oneHundred';
  460. this.data().setPoker(Meteor.userId(), newState);
  461. }
  462. if ($(e.target).hasClass('js-poker-vote-unsure')) {
  463. newState = 'unsure';
  464. this.data().setPoker(Meteor.userId(), newState);
  465. }
  466. },
  467. 'click .js-poker-finish'(e) {
  468. if ($(e.target).hasClass('js-poker-finish')) {
  469. e.preventDefault();
  470. const now = moment().format('YYYY-MM-DD HH:mm');
  471. this.data().setPokerEnd(now);
  472. }
  473. },
  474. 'click .js-poker-replay'(e) {
  475. if ($(e.target).hasClass('js-poker-replay')) {
  476. e.preventDefault();
  477. this.currentCard = this.currentData();
  478. this.currentCard.replayPoker();
  479. this.data().unsetPokerEnd();
  480. this.data().unsetPokerEstimation();
  481. }
  482. },
  483. 'click .js-poker-estimation'(event) {
  484. event.preventDefault();
  485. const ruleTitle = this.find('#pokerEstimation').value;
  486. if (ruleTitle !== undefined && ruleTitle !== '') {
  487. this.find('#pokerEstimation').value = '';
  488. if (ruleTitle) {
  489. this.data().setPokerEstimation(parseInt(ruleTitle, 10));
  490. } else {
  491. this.data().setPokerEstimation('');
  492. }
  493. }
  494. },
  495. },
  496. ];
  497. },
  498. }).register('cardDetails');
  499. Template.cardDetails.helpers({
  500. isPopup() {
  501. let ret = !!Utils.getPopupCardId();
  502. return ret;
  503. }
  504. });
  505. Template.cardDetailsPopup.onDestroyed(() => {
  506. Session.delete('popupCardId');
  507. Session.delete('popupCardBoardId');
  508. });
  509. Template.cardDetailsPopup.helpers({
  510. popupCard() {
  511. const ret = Utils.getPopupCard();
  512. return ret;
  513. },
  514. });
  515. BlazeComponent.extendComponent({
  516. template() {
  517. return 'exportCard';
  518. },
  519. withApi() {
  520. return Template.instance().apiEnabled.get();
  521. },
  522. exportUrlCardPDF() {
  523. const params = {
  524. boardId: Session.get('currentBoard'),
  525. listId: this.listId,
  526. cardId: this.cardId,
  527. };
  528. const queryParams = {
  529. authToken: Accounts._storedLoginToken(),
  530. };
  531. return FlowRouter.path(
  532. '/api/boards/:boardId/lists/:listId/cards/:cardId/exportPDF',
  533. params,
  534. queryParams,
  535. );
  536. },
  537. exportFilenameCardPDF() {
  538. //const boardId = Session.get('currentBoard');
  539. //return `export-card-pdf-${boardId}.xlsx`;
  540. return `export-card.pdf`;
  541. },
  542. }).register('exportCardPopup');
  543. // only allow number input
  544. Template.editCardSortOrderForm.onRendered(function () {
  545. this.$('input').on("keypress paste", function (event) {
  546. let keyCode = event.keyCode;
  547. let charCode = String.fromCharCode(keyCode);
  548. let regex = new RegExp('[-0-9.]');
  549. let ret = regex.test(charCode);
  550. // only working here, defining in events() doesn't handle the return value correctly
  551. return ret;
  552. });
  553. });
  554. // We extends the normal InlinedForm component to support UnsavedEdits draft
  555. // feature.
  556. (class extends InlinedForm {
  557. _getUnsavedEditKey() {
  558. return {
  559. fieldName: 'cardDescription',
  560. // XXX Recovering the currentCard identifier form a session variable is
  561. // fragile because this variable may change for instance if the route
  562. // change. We should use some component props instead.
  563. docId: Utils.getCurrentCardId(),
  564. };
  565. }
  566. close(isReset = false) {
  567. if (this.isOpen.get() && !isReset) {
  568. const draft = this.getValue().trim();
  569. let card = Utils.getCurrentCard();
  570. if (card && draft !== card.getDescription()) {
  571. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  572. }
  573. }
  574. super.close();
  575. }
  576. reset() {
  577. UnsavedEdits.reset(this._getUnsavedEditKey());
  578. this.close(true);
  579. }
  580. events() {
  581. const parentEvents = InlinedForm.prototype.events()[0];
  582. return [
  583. {
  584. ...parentEvents,
  585. 'click .js-close-inlined-form': this.reset,
  586. },
  587. ];
  588. }
  589. }.register('inlinedCardDescription'));
  590. Template.cardDetailsActionsPopup.helpers({
  591. isWatching() {
  592. return this.findWatcher(Meteor.userId());
  593. },
  594. isBoardAdmin() {
  595. return Meteor.user().isBoardAdmin();
  596. },
  597. canModifyCard() {
  598. return (
  599. Meteor.user() &&
  600. Meteor.user().isBoardMember() &&
  601. !Meteor.user().isCommentOnly()
  602. );
  603. },
  604. });
  605. Template.cardDetailsActionsPopup.events({
  606. 'click .js-export-card': Popup.open('exportCard'),
  607. 'click .js-members': Popup.open('cardMembers'),
  608. 'click .js-assignees': Popup.open('cardAssignees'),
  609. 'click .js-attachments': Popup.open('cardAttachments'),
  610. 'click .js-start-voting': Popup.open('cardStartVoting'),
  611. 'click .js-start-planning-poker': Popup.open('cardStartPlanningPoker'),
  612. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  613. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  614. 'click .js-start-date': Popup.open('editCardStartDate'),
  615. 'click .js-due-date': Popup.open('editCardDueDate'),
  616. 'click .js-end-date': Popup.open('editCardEndDate'),
  617. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  618. 'click .js-move-card': Popup.open('moveCard'),
  619. 'click .js-copy-card': Popup.open('copyCard'),
  620. 'click .js-convert-checklist-item-to-card': Popup.open('convertChecklistItemToCard'),
  621. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  622. 'click .js-set-card-color': Popup.open('setCardColor'),
  623. 'click .js-move-card-to-top'(event) {
  624. event.preventDefault();
  625. const minOrder = this.getMinSort();
  626. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  627. Popup.back();
  628. },
  629. 'click .js-move-card-to-bottom'(event) {
  630. event.preventDefault();
  631. const maxOrder = this.getMaxSort();
  632. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  633. Popup.back();
  634. },
  635. 'click .js-archive': Popup.afterConfirm('cardArchive', function () {
  636. Popup.close();
  637. this.archive();
  638. Utils.goBoardId(this.boardId);
  639. }),
  640. 'click .js-more': Popup.open('cardMore'),
  641. 'click .js-toggle-watch-card'() {
  642. const currentCard = this;
  643. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  644. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  645. if (!err && ret) Popup.close();
  646. });
  647. },
  648. });
  649. BlazeComponent.extendComponent({
  650. onRendered() {
  651. autosize(this.$('textarea.js-edit-card-title'));
  652. },
  653. events() {
  654. return [
  655. {
  656. 'click a.fa.fa-copy'(event) {
  657. const $editor = this.$('textarea');
  658. const promise = Utils.copyTextToClipboard($editor[0].value);
  659. const $tooltip = this.$('.copied-tooltip');
  660. Utils.showCopied(promise, $tooltip);
  661. },
  662. 'keydown .js-edit-card-title'(event) {
  663. // If enter key was pressed, submit the data
  664. // Unless the shift key is also being pressed
  665. if (event.keyCode === 13 && !event.shiftKey) {
  666. $('.js-submit-edit-card-title-form').click();
  667. }
  668. },
  669. }
  670. ];
  671. }
  672. }).register('editCardTitleForm');
  673. Template.cardMembersPopup.onCreated(function () {
  674. let currBoard = Boards.findOne(Session.get('currentBoard'));
  675. let members = currBoard.activeMembers();
  676. // let query = {
  677. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  678. // };
  679. // let boardTeamUsers = Users.find(query, {
  680. // sort: { sort: 1 },
  681. // });
  682. // members = currBoard.activeMembers2(members, boardTeamUsers);
  683. this.members = new ReactiveVar(members);
  684. });
  685. Template.cardMembersPopup.events({
  686. 'keyup .card-members-filter'(event) {
  687. const members = filterMembers(event.target.value);
  688. Template.instance().members.set(members);
  689. }
  690. });
  691. Template.cardMembersPopup.helpers({
  692. members() {
  693. return Template.instance().members.get();
  694. },
  695. });
  696. const filterMembers = (filterTerm) => {
  697. let currBoard = Boards.findOne(Session.get('currentBoard'));
  698. let members = currBoard.activeMembers();
  699. // let query = {
  700. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  701. // };
  702. // let boardTeamUsers = Users.find(query, {
  703. // sort: { sort: 1 },
  704. // });
  705. // members = currBoard.activeMembers2(members, boardTeamUsers);
  706. if (filterTerm) {
  707. members = members
  708. .map(member => ({
  709. member,
  710. user: Users.findOne(member.userId)
  711. }))
  712. .filter(({ user }) =>
  713. (user.profile.fullname !== undefined && user.profile.fullname.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  714. || user.profile.fullname === undefined && user.profile.username !== undefined && user.profile.username.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  715. .map(({ member }) => member);
  716. }
  717. return members;
  718. }
  719. Template.editCardRequesterForm.onRendered(function () {
  720. autosize(this.$('.js-edit-card-requester'));
  721. });
  722. Template.editCardRequesterForm.events({
  723. 'keydown .js-edit-card-requester'(event) {
  724. // If enter key was pressed, submit the data
  725. if (event.keyCode === 13) {
  726. $('.js-submit-edit-card-requester-form').click();
  727. }
  728. },
  729. });
  730. Template.editCardAssignerForm.onRendered(function () {
  731. autosize(this.$('.js-edit-card-assigner'));
  732. });
  733. Template.editCardAssignerForm.events({
  734. 'keydown .js-edit-card-assigner'(event) {
  735. // If enter key was pressed, submit the data
  736. if (event.keyCode === 13) {
  737. $('.js-submit-edit-card-assigner-form').click();
  738. }
  739. },
  740. });
  741. Template.moveCardPopup.events({
  742. 'click .js-done'() {
  743. const card = Cards.findOne(this._id);
  744. const bSelect = $('.js-select-boards')[0];
  745. let boardId;
  746. // if we are a worker, we won't have a board select so we just use the
  747. // current boardId of the card.
  748. if (bSelect) {
  749. boardId = bSelect.options[bSelect.selectedIndex].value;
  750. } else {
  751. boardId = card.boardId;
  752. }
  753. const lSelect = $('.js-select-lists')[0];
  754. const listId = lSelect.options[lSelect.selectedIndex].value;
  755. const slSelect = $('.js-select-swimlanes')[0];
  756. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  757. const minOrder = card.getMinSort(listId, swimlaneId);
  758. card.move(boardId, swimlaneId, listId, minOrder - 1);
  759. // set new id's to card object in case the card is moved to top by the comment "moveCard" after this command (.js-move-card)
  760. this.boardId = boardId;
  761. this.swimlaneId = swimlaneId;
  762. this.listId = listId;
  763. Popup.back();
  764. },
  765. });
  766. BlazeComponent.extendComponent({
  767. onCreated() {
  768. this.currentBoardId = Utils.getCurrentBoardId();
  769. this.selectedBoardId = new ReactiveVar(this.currentBoardId);
  770. this.setMoveAndCopyDialogOption(this.currentBoardId);
  771. },
  772. /** set the last confirmed dialog field values
  773. * @param boardId the current board id
  774. */
  775. setMoveAndCopyDialogOption(boardId) {
  776. this.moveAndCopyDialogOption = {
  777. 'boardId' : "",
  778. 'swimlaneId' : "",
  779. 'listId' : "",
  780. }
  781. let currentOptions = Meteor.user().getMoveAndCopyDialogOptions();
  782. if (currentOptions && boardId && currentOptions[boardId]) {
  783. this.moveAndCopyDialogOption = currentOptions[boardId];
  784. if (this.moveAndCopyDialogOption.boardId) {
  785. this.selectedBoardId.set(this.moveAndCopyDialogOption.boardId)
  786. }
  787. }
  788. subManager.subscribe('board', this.selectedBoardId.get(), false);
  789. },
  790. /** returns if the board id was the last confirmed one
  791. * @param boardId check this board id
  792. * @return if the board id was the last confirmed one
  793. */
  794. isMoveAndCopyDialogOptionBoardId(boardId) {
  795. let ret = this.moveAndCopyDialogOption.boardId == boardId;
  796. return ret;
  797. },
  798. /** returns if the swimlane id was the last confirmed one
  799. * @param swimlaneId check this swimlane id
  800. * @return if the swimlane id was the last confirmed one
  801. */
  802. isMoveAndCopyDialogOptionSwimlaneId(swimlaneId) {
  803. let ret = this.moveAndCopyDialogOption.swimlaneId == swimlaneId;
  804. return ret;
  805. },
  806. /** returns if the list id was the last confirmed one
  807. * @param listId check this list id
  808. * @return if the list id was the last confirmed one
  809. */
  810. isMoveAndCopyDialogOptionListId(listId) {
  811. let ret = this.moveAndCopyDialogOption.listId == listId;
  812. return ret;
  813. },
  814. boards() {
  815. return Boards.find(
  816. {
  817. archived: false,
  818. 'members.userId': Meteor.userId(),
  819. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  820. },
  821. {
  822. sort: { sort: 1 /* boards default sorting */ },
  823. },
  824. );
  825. },
  826. swimlanes() {
  827. const board = Boards.findOne(this.selectedBoardId.get());
  828. return board.swimlanes();
  829. },
  830. aBoardLists() {
  831. const board = Boards.findOne(this.selectedBoardId.get());
  832. return board.lists();
  833. },
  834. events() {
  835. return [
  836. {
  837. 'click .js-done'() {
  838. const boardSelect = this.$('.js-select-boards')[0];
  839. const boardId = boardSelect.options[boardSelect.selectedIndex].value;
  840. const listSelect = this.$('.js-select-lists')[0];
  841. const listId = listSelect.options[listSelect.selectedIndex].value;
  842. const swimlaneSelect = this.$('.js-select-swimlanes')[0];
  843. const swimlaneId = swimlaneSelect.options[swimlaneSelect.selectedIndex].value;
  844. const options = {
  845. 'boardId' : boardId,
  846. 'swimlaneId' : swimlaneId,
  847. 'listId' : listId,
  848. }
  849. Meteor.user().setMoveAndCopyDialogOption(this.currentBoardId, options);
  850. },
  851. 'change .js-select-boards'(event) {
  852. const boardId = $(event.currentTarget).val();
  853. this.selectedBoardId.set(boardId);
  854. subManager.subscribe('board', boardId, false);
  855. },
  856. },
  857. ];
  858. },
  859. }).register('boardsAndLists');
  860. Template.copyCardPopup.events({
  861. 'click .js-done'() {
  862. const card = Utils.getCurrentCard();
  863. const lSelect = $('.js-select-lists')[0];
  864. const listId = lSelect.options[lSelect.selectedIndex].value;
  865. const slSelect = $('.js-select-swimlanes')[0];
  866. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  867. const bSelect = $('.js-select-boards')[0];
  868. const boardId = bSelect.options[bSelect.selectedIndex].value;
  869. const textarea = $('#copy-card-title');
  870. const title = textarea.val().trim();
  871. // insert new card to the top of new list
  872. const minOrder = card.getMinSort(listId, swimlaneId);
  873. card.sort = minOrder - 1;
  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. });