cardDetails.js 55 KB

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