cardDetails.js 53 KB

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