cardDetails.js 53 KB

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