2
0

cardDetails.js 57 KB

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