cardDetails.js 56 KB

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