cardDetails.js 59 KB

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