cardDetails.js 66 KB

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