cardDetails.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  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. // Only prevent default for file drags to avoid interfering with other drag operations
  469. const dataTransfer = event.originalEvent.dataTransfer;
  470. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  471. event.preventDefault();
  472. event.stopPropagation();
  473. }
  474. },
  475. 'dragenter .js-card-details'(event) {
  476. const dataTransfer = event.originalEvent.dataTransfer;
  477. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  478. event.preventDefault();
  479. event.stopPropagation();
  480. const card = this.data();
  481. const board = card.board();
  482. // Only allow drag-and-drop if user can modify card and board allows attachments
  483. if (Utils.canModifyCard() && board && board.allowsAttachments) {
  484. $(event.currentTarget).addClass('is-dragging-over');
  485. }
  486. }
  487. },
  488. 'dragleave .js-card-details'(event) {
  489. const dataTransfer = event.originalEvent.dataTransfer;
  490. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  491. event.preventDefault();
  492. event.stopPropagation();
  493. $(event.currentTarget).removeClass('is-dragging-over');
  494. }
  495. },
  496. 'drop .js-card-details'(event) {
  497. const dataTransfer = event.originalEvent.dataTransfer;
  498. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  499. event.preventDefault();
  500. event.stopPropagation();
  501. $(event.currentTarget).removeClass('is-dragging-over');
  502. const card = this.data();
  503. const board = card.board();
  504. // Check permissions
  505. if (!Utils.canModifyCard() || !board || !board.allowsAttachments) {
  506. return;
  507. }
  508. // Check if this is a file drop (not a checklist item reorder)
  509. if (!dataTransfer.files || dataTransfer.files.length === 0) {
  510. return;
  511. }
  512. const files = dataTransfer.files;
  513. if (files && files.length > 0) {
  514. handleFileUpload(card, files);
  515. }
  516. }
  517. },
  518. },
  519. ];
  520. },
  521. }).register('cardDetails');
  522. Template.cardDetails.helpers({
  523. isPopup() {
  524. let ret = !!Utils.getPopupCardId();
  525. return ret;
  526. },
  527. // Upload progress helpers
  528. hasActiveUploads() {
  529. return uploadProgressManager.hasActiveUploads(this._id);
  530. },
  531. uploads() {
  532. return uploadProgressManager.getUploadsForCard(this._id);
  533. },
  534. uploadCount() {
  535. return uploadProgressManager.getUploadCountForCard(this._id);
  536. }
  537. });
  538. Template.cardDetailsPopup.onDestroyed(() => {
  539. Session.delete('popupCardId');
  540. Session.delete('popupCardBoardId');
  541. });
  542. Template.cardDetailsPopup.helpers({
  543. popupCard() {
  544. const ret = Utils.getPopupCard();
  545. return ret;
  546. },
  547. });
  548. BlazeComponent.extendComponent({
  549. template() {
  550. return 'exportCard';
  551. },
  552. withApi() {
  553. return Template.instance().apiEnabled.get();
  554. },
  555. exportUrlCardPDF() {
  556. const params = {
  557. boardId: Session.get('currentBoard'),
  558. listId: this.listId,
  559. cardId: this.cardId,
  560. };
  561. const queryParams = {
  562. authToken: Accounts._storedLoginToken(),
  563. };
  564. return FlowRouter.path(
  565. '/api/boards/:boardId/lists/:listId/cards/:cardId/exportPDF',
  566. params,
  567. queryParams,
  568. );
  569. },
  570. exportFilenameCardPDF() {
  571. //const boardId = Session.get('currentBoard');
  572. //return `export-card-pdf-${boardId}.xlsx`;
  573. return `export-card.pdf`;
  574. },
  575. }).register('exportCardPopup');
  576. // only allow number input
  577. Template.editCardSortOrderForm.onRendered(function () {
  578. this.$('input').on("keypress paste", function (event) {
  579. let keyCode = event.keyCode;
  580. let charCode = String.fromCharCode(keyCode);
  581. let regex = new RegExp('[-0-9.]');
  582. let ret = regex.test(charCode);
  583. // only working here, defining in events() doesn't handle the return value correctly
  584. return ret;
  585. });
  586. });
  587. // We extends the normal InlinedForm component to support UnsavedEdits draft
  588. // feature.
  589. (class extends InlinedForm {
  590. _getUnsavedEditKey() {
  591. return {
  592. fieldName: 'cardDescription',
  593. // XXX Recovering the currentCard identifier form a session variable is
  594. // fragile because this variable may change for instance if the route
  595. // change. We should use some component props instead.
  596. docId: Utils.getCurrentCardId(),
  597. };
  598. }
  599. close(isReset = false) {
  600. if (this.isOpen.get() && !isReset) {
  601. const draft = this.getValue().trim();
  602. let card = Utils.getCurrentCard();
  603. if (card && draft !== card.getDescription()) {
  604. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  605. }
  606. }
  607. super.close();
  608. }
  609. reset() {
  610. UnsavedEdits.reset(this._getUnsavedEditKey());
  611. this.close(true);
  612. }
  613. events() {
  614. const parentEvents = InlinedForm.prototype.events()[0];
  615. return [
  616. {
  617. ...parentEvents,
  618. 'click .js-close-inlined-form': this.reset,
  619. },
  620. ];
  621. }
  622. }.register('inlinedCardDescription'));
  623. Template.cardDetailsActionsPopup.helpers({
  624. isWatching() {
  625. return this.findWatcher(Meteor.userId());
  626. },
  627. isBoardAdmin() {
  628. return ReactiveCache.getCurrentUser().isBoardAdmin();
  629. },
  630. showListOnMinicard() {
  631. return this.showListOnMinicard;
  632. },
  633. });
  634. Template.cardDetailsActionsPopup.events({
  635. 'click .js-export-card': Popup.open('exportCard'),
  636. 'click .js-members': Popup.open('cardMembers'),
  637. 'click .js-assignees': Popup.open('cardAssignees'),
  638. 'click .js-attachments': Popup.open('cardAttachments'),
  639. 'click .js-start-voting': Popup.open('cardStartVoting'),
  640. 'click .js-start-planning-poker': Popup.open('cardStartPlanningPoker'),
  641. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  642. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  643. 'click .js-start-date': Popup.open('editCardStartDate'),
  644. 'click .js-due-date': Popup.open('editCardDueDate'),
  645. 'click .js-end-date': Popup.open('editCardEndDate'),
  646. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  647. 'click .js-move-card': Popup.open('moveCard'),
  648. 'click .js-copy-card': Popup.open('copyCard'),
  649. 'click .js-convert-checklist-item-to-card': Popup.open('convertChecklistItemToCard'),
  650. 'click .js-copy-checklist-cards': Popup.open('copyManyCards'),
  651. 'click .js-set-card-color': Popup.open('setCardColor'),
  652. 'click .js-move-card-to-top'(event) {
  653. event.preventDefault();
  654. const minOrder = this.getMinSort();
  655. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  656. Popup.back();
  657. },
  658. 'click .js-move-card-to-bottom'(event) {
  659. event.preventDefault();
  660. const maxOrder = this.getMaxSort();
  661. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  662. Popup.back();
  663. },
  664. 'click .js-archive': Popup.afterConfirm('cardArchive', function () {
  665. Popup.close();
  666. this.archive();
  667. Utils.goBoardId(this.boardId);
  668. }),
  669. 'click .js-more': Popup.open('cardMore'),
  670. 'click .js-toggle-watch-card'() {
  671. const currentCard = this;
  672. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  673. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  674. if (!err && ret) Popup.close();
  675. });
  676. },
  677. 'click .js-toggle-show-list-on-minicard'() {
  678. const currentCard = this;
  679. const newValue = !currentCard.showListOnMinicard;
  680. Cards.update(currentCard._id, { $set: { showListOnMinicard: newValue } });
  681. Popup.close();
  682. },
  683. });
  684. BlazeComponent.extendComponent({
  685. onRendered() {
  686. autosize(this.$('textarea.js-edit-card-title'));
  687. },
  688. events() {
  689. return [
  690. {
  691. 'click a.fa.fa-copy'(event) {
  692. const $editor = this.$('textarea');
  693. const promise = Utils.copyTextToClipboard($editor[0].value);
  694. const $tooltip = this.$('.copied-tooltip');
  695. Utils.showCopied(promise, $tooltip);
  696. },
  697. 'keydown .js-edit-card-title'(event) {
  698. // If enter key was pressed, submit the data
  699. // Unless the shift key is also being pressed
  700. if (event.keyCode === 13 && !event.shiftKey) {
  701. $('.js-submit-edit-card-title-form').click();
  702. }
  703. },
  704. }
  705. ];
  706. }
  707. }).register('editCardTitleForm');
  708. Template.cardMembersPopup.onCreated(function () {
  709. let currBoard = Utils.getCurrentBoard();
  710. let members = currBoard.activeMembers();
  711. this.members = new ReactiveVar(members);
  712. });
  713. Template.cardMembersPopup.events({
  714. 'keyup .card-members-filter'(event) {
  715. const members = filterMembers(event.target.value);
  716. Template.instance().members.set(members);
  717. }
  718. });
  719. Template.cardMembersPopup.helpers({
  720. members() {
  721. return _.sortBy(Template.instance().members.get(),'fullname');
  722. },
  723. });
  724. const filterMembers = (filterTerm) => {
  725. let currBoard = Utils.getCurrentBoard();
  726. let members = currBoard.activeMembers();
  727. if (filterTerm) {
  728. members = members
  729. .map(member => ({
  730. member,
  731. user: ReactiveCache.getUser(member.userId)
  732. }))
  733. .filter(({ user }) =>
  734. (user.profile.fullname !== undefined && user.profile.fullname.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  735. || user.profile.fullname === undefined && user.profile.username !== undefined && user.profile.username.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
  736. .map(({ member }) => member);
  737. }
  738. return members;
  739. }
  740. Template.editCardRequesterForm.onRendered(function () {
  741. autosize(this.$('.js-edit-card-requester'));
  742. });
  743. Template.editCardRequesterForm.events({
  744. 'keydown .js-edit-card-requester'(event) {
  745. // If enter key was pressed, submit the data
  746. if (event.keyCode === 13) {
  747. $('.js-submit-edit-card-requester-form').click();
  748. }
  749. },
  750. });
  751. Template.editCardAssignerForm.onRendered(function () {
  752. autosize(this.$('.js-edit-card-assigner'));
  753. });
  754. Template.editCardAssignerForm.events({
  755. 'keydown .js-edit-card-assigner'(event) {
  756. // If enter key was pressed, submit the data
  757. if (event.keyCode === 13) {
  758. $('.js-submit-edit-card-assigner-form').click();
  759. }
  760. },
  761. });
  762. /** Move Card Dialog */
  763. (class extends DialogWithBoardSwimlaneList {
  764. getDialogOptions() {
  765. const ret = ReactiveCache.getCurrentUser().getMoveAndCopyDialogOptions();
  766. return ret;
  767. }
  768. setDone(boardId, swimlaneId, listId, options) {
  769. ReactiveCache.getCurrentUser().setMoveAndCopyDialogOption(this.currentBoardId, options);
  770. const card = this.data();
  771. const minOrder = card.getMinSort(listId, swimlaneId);
  772. card.move(boardId, swimlaneId, listId, minOrder - 1);
  773. }
  774. }).register('moveCardPopup');
  775. /** Copy Card Dialog */
  776. (class extends DialogWithBoardSwimlaneList {
  777. getDialogOptions() {
  778. const ret = ReactiveCache.getCurrentUser().getMoveAndCopyDialogOptions();
  779. return ret;
  780. }
  781. setDone(boardId, swimlaneId, listId, options) {
  782. ReactiveCache.getCurrentUser().setMoveAndCopyDialogOption(this.currentBoardId, options);
  783. const card = this.data();
  784. // const textarea = $('#copy-card-title');
  785. const textarea = this.$('#copy-card-title');
  786. const title = textarea.val().trim();
  787. if (title) {
  788. // insert new card to the top of new list
  789. const newCardId = Meteor.call('copyCard', card._id, boardId, swimlaneId, listId, true, {title: title});
  790. // In case the filter is active we need to add the newly inserted card in
  791. // the list of exceptions -- cards that are not filtered. Otherwise the
  792. // card will disappear instantly.
  793. // See https://github.com/wekan/wekan/issues/80
  794. Filter.addException(newCardId);
  795. }
  796. }
  797. }).register('copyCardPopup');
  798. /** Convert Checklist-Item to card dialog */
  799. (class extends DialogWithBoardSwimlaneList {
  800. getDialogOptions() {
  801. const ret = ReactiveCache.getCurrentUser().getMoveAndCopyDialogOptions();
  802. return ret;
  803. }
  804. setDone(boardId, swimlaneId, listId, options) {
  805. ReactiveCache.getCurrentUser().setMoveAndCopyDialogOption(this.currentBoardId, options);
  806. const card = this.data();
  807. const textarea = this.$('#copy-card-title');
  808. const title = textarea.val().trim();
  809. if (title) {
  810. const _id = Cards.insert({
  811. title: title,
  812. listId: listId,
  813. boardId: boardId,
  814. swimlaneId: swimlaneId,
  815. sort: 0,
  816. });
  817. const card = ReactiveCache.getCard(_id);
  818. const minOrder = card.getMinSort();
  819. card.move(card.boardId, card.swimlaneId, card.listId, minOrder - 1);
  820. Filter.addException(_id);
  821. }
  822. }
  823. }).register('convertChecklistItemToCardPopup');
  824. /** Copy many cards dialog */
  825. (class extends DialogWithBoardSwimlaneList {
  826. getDialogOptions() {
  827. const ret = ReactiveCache.getCurrentUser().getMoveAndCopyDialogOptions();
  828. return ret;
  829. }
  830. setDone(boardId, swimlaneId, listId, options) {
  831. ReactiveCache.getCurrentUser().setMoveAndCopyDialogOption(this.currentBoardId, options);
  832. const card = this.data();
  833. const textarea = this.$('#copy-card-title');
  834. const title = textarea.val().trim();
  835. if (title) {
  836. const titleList = JSON.parse(title);
  837. for (const obj of titleList) {
  838. const newCardId = Meteor.call('copyCard', card._id, boardId, swimlaneId, listId, false, {title: obj.title, description: obj.description});
  839. // In case the filter is active we need to add the newly inserted card in
  840. // the list of exceptions -- cards that are not filtered. Otherwise the
  841. // card will disappear instantly.
  842. // See https://github.com/wekan/wekan/issues/80
  843. Filter.addException(newCardId);
  844. }
  845. }
  846. }
  847. }).register('copyManyCardsPopup');
  848. BlazeComponent.extendComponent({
  849. onCreated() {
  850. this.currentCard = this.currentData();
  851. this.currentColor = new ReactiveVar(this.currentCard.color);
  852. },
  853. colors() {
  854. return ALLOWED_COLORS.map((color) => ({ color, name: '' }));
  855. },
  856. isSelected(color) {
  857. if (this.currentColor.get() === null) {
  858. return color === 'white';
  859. }
  860. return this.currentColor.get() === color;
  861. },
  862. events() {
  863. return [
  864. {
  865. 'click .js-palette-color'() {
  866. this.currentColor.set(this.currentData().color);
  867. },
  868. 'click .js-submit'(event) {
  869. event.preventDefault();
  870. this.currentCard.setColor(this.currentColor.get());
  871. Popup.back();
  872. },
  873. 'click .js-remove-color'(event) {
  874. event.preventDefault();
  875. this.currentCard.setColor(null);
  876. Popup.back();
  877. },
  878. },
  879. ];
  880. },
  881. }).register('setCardColorPopup');
  882. BlazeComponent.extendComponent({
  883. onCreated() {
  884. this.currentCard = this.currentData();
  885. this.parentBoard = new ReactiveVar(null);
  886. this.parentCard = this.currentCard.parentCard();
  887. if (this.parentCard) {
  888. const list = $('.js-field-parent-card');
  889. list.val(this.parentCard._id);
  890. this.parentBoard.set(this.parentCard.board()._id);
  891. } else {
  892. this.parentBoard.set(null);
  893. }
  894. },
  895. boards() {
  896. const ret = ReactiveCache.getBoards(
  897. {
  898. archived: false,
  899. 'members.userId': Meteor.userId(),
  900. _id: { $ne: ReactiveCache.getCurrentUser().getTemplatesBoardId() },
  901. },
  902. {
  903. sort: { sort: 1 /* boards default sorting */ },
  904. },
  905. );
  906. return ret;
  907. },
  908. cards() {
  909. const currentId = Utils.getCurrentCardId();
  910. if (this.parentBoard.get()) {
  911. const ret = ReactiveCache.getCards({
  912. boardId: this.parentBoard.get(),
  913. _id: { $ne: currentId },
  914. });
  915. return ret;
  916. } else {
  917. return [];
  918. }
  919. },
  920. isParentBoard() {
  921. const board = this.currentData();
  922. if (this.parentBoard.get()) {
  923. return board._id === this.parentBoard.get();
  924. }
  925. return false;
  926. },
  927. isParentCard() {
  928. const card = this.currentData();
  929. if (this.parentCard) {
  930. return card._id === this.parentCard;
  931. }
  932. return false;
  933. },
  934. setParentCardId(cardId) {
  935. if (cardId) {
  936. this.parentCard = ReactiveCache.getCard(cardId);
  937. } else {
  938. this.parentCard = null;
  939. }
  940. this.currentCard.setParentId(cardId);
  941. },
  942. events() {
  943. return [
  944. {
  945. 'click .js-copy-card-link-to-clipboard'(event) {
  946. const promise = Utils.copyTextToClipboard(location.origin + document.getElementById('cardURL').value);
  947. const $tooltip = this.$('.copied-tooltip');
  948. Utils.showCopied(promise, $tooltip);
  949. },
  950. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  951. Popup.close();
  952. // verify that there are no linked cards
  953. if (ReactiveCache.getCards({ linkedId: this._id }).length === 0) {
  954. Cards.remove(this._id);
  955. } else {
  956. // TODO: Maybe later we can list where the linked cards are.
  957. // Now here is popup with a hint that the card cannot be deleted
  958. // as there are linked cards.
  959. // Related:
  960. // client/components/lists/listHeader.js about line 248
  961. // https://github.com/wekan/wekan/issues/2785
  962. const message = `${TAPi18n.__(
  963. 'delete-linked-card-before-this-card',
  964. )} linkedId: ${this._id
  965. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  966. alert(message);
  967. }
  968. Utils.goBoardId(this.boardId);
  969. }),
  970. 'change .js-field-parent-board'(event) {
  971. const selection = $(event.currentTarget).val();
  972. const list = $('.js-field-parent-card');
  973. if (selection === 'none') {
  974. this.parentBoard.set(null);
  975. } else {
  976. subManager.subscribe('board', $(event.currentTarget).val(), false);
  977. this.parentBoard.set(selection);
  978. list.prop('disabled', false);
  979. }
  980. this.setParentCardId(null);
  981. },
  982. 'change .js-field-parent-card'(event) {
  983. const selection = $(event.currentTarget).val();
  984. this.setParentCardId(selection);
  985. },
  986. },
  987. ];
  988. },
  989. }).register('cardMorePopup');
  990. BlazeComponent.extendComponent({
  991. onCreated() {
  992. this.currentCard = this.currentData();
  993. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  994. },
  995. events() {
  996. return [
  997. {
  998. 'click .js-end-date': Popup.open('editVoteEndDate'),
  999. 'submit .edit-vote-question'(evt) {
  1000. evt.preventDefault();
  1001. const voteQuestion = evt.target.vote.value;
  1002. const publicVote = $('#vote-public').hasClass('is-checked');
  1003. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  1004. 'is-checked',
  1005. );
  1006. const endString = this.currentCard.getVoteEnd();
  1007. this.currentCard.setVoteQuestion(
  1008. voteQuestion,
  1009. publicVote,
  1010. allowNonBoardMembers,
  1011. );
  1012. if (endString) {
  1013. this.currentCard.setVoteEnd(endString);
  1014. }
  1015. Popup.back();
  1016. },
  1017. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  1018. event.preventDefault();
  1019. this.currentCard.unsetVote();
  1020. Popup.back();
  1021. }),
  1022. 'click a.js-toggle-vote-public'(event) {
  1023. event.preventDefault();
  1024. $('#vote-public').toggleClass('is-checked');
  1025. },
  1026. 'click a.js-toggle-vote-allow-non-members'(event) {
  1027. event.preventDefault();
  1028. $('#vote-allow-non-members').toggleClass('is-checked');
  1029. },
  1030. },
  1031. ];
  1032. },
  1033. }).register('cardStartVotingPopup');
  1034. // editVoteEndDatePopup
  1035. (class extends DatePicker {
  1036. onCreated() {
  1037. super.onCreated(formatDateTime(now()));
  1038. this.data().getVoteEnd() && this.date.set(new Date(this.data().getVoteEnd()));
  1039. }
  1040. events() {
  1041. return [
  1042. {
  1043. 'submit .edit-date'(evt) {
  1044. evt.preventDefault();
  1045. // if no time was given, init with 12:00
  1046. const time =
  1047. evt.target.time.value ||
  1048. formatTime(new Date().setHours(12, 0, 0));
  1049. const dateString = `${evt.target.date.value} ${time}`;
  1050. /*
  1051. const newDate = parseDate(dateString, ['L LT'], true);
  1052. if (newDate.isValid()) {
  1053. // if active vote - store it
  1054. if (this.currentData().getVoteQuestion()) {
  1055. this._storeDate(newDate.toDate());
  1056. Popup.back();
  1057. } else {
  1058. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  1059. Popup.back();
  1060. }
  1061. */
  1062. // Try to parse different date formats using native Date parsing
  1063. const formats = [
  1064. 'YYYY-MM-DD HH:mm',
  1065. 'MM/DD/YYYY HH:mm',
  1066. 'DD.MM.YYYY HH:mm',
  1067. 'DD/MM/YYYY HH:mm',
  1068. 'DD-MM-YYYY HH:mm'
  1069. ];
  1070. let parsedDate = null;
  1071. for (const format of formats) {
  1072. parsedDate = parseDate(dateString, [format], true);
  1073. if (parsedDate) break;
  1074. }
  1075. // Fallback to native Date parsing
  1076. if (!parsedDate) {
  1077. parsedDate = new Date(dateString);
  1078. }
  1079. if (isValidDate(parsedDate)) {
  1080. // if active poker - store it
  1081. if (this.currentData().getPokerQuestion()) {
  1082. this._storeDate(usaDate.toDate());
  1083. } else {
  1084. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1085. }
  1086. Popup.back();
  1087. } else if (euroAmDate.isValid()) {
  1088. // if active poker - store it
  1089. if (this.currentData().getPokerQuestion()) {
  1090. this._storeDate(euroAmDate.toDate());
  1091. } else {
  1092. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1093. }
  1094. Popup.back();
  1095. } else if (euro24hDate.isValid()) {
  1096. // if active poker - store it
  1097. if (this.currentData().getPokerQuestion()) {
  1098. this._storeDate(euro24hDate.toDate());
  1099. this.card.setPokerEnd(euro24hDate.toDate());
  1100. } else {
  1101. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1102. }
  1103. Popup.back();
  1104. } else if (eurodotDate.isValid()) {
  1105. // if active poker - store it
  1106. if (this.currentData().getPokerQuestion()) {
  1107. this._storeDate(eurodotDate.toDate());
  1108. this.card.setPokerEnd(eurodotDate.toDate());
  1109. } else {
  1110. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1111. }
  1112. Popup.back();
  1113. } else if (minusDate.isValid()) {
  1114. // if active poker - store it
  1115. if (this.currentData().getPokerQuestion()) {
  1116. this._storeDate(minusDate.toDate());
  1117. this.card.setPokerEnd(minusDate.toDate());
  1118. } else {
  1119. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1120. }
  1121. Popup.back();
  1122. } else if (slashDate.isValid()) {
  1123. // if active poker - store it
  1124. if (this.currentData().getPokerQuestion()) {
  1125. this._storeDate(slashDate.toDate());
  1126. this.card.setPokerEnd(slashDate.toDate());
  1127. } else {
  1128. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1129. }
  1130. Popup.back();
  1131. } else if (dotDate.isValid()) {
  1132. // if active poker - store it
  1133. if (this.currentData().getPokerQuestion()) {
  1134. this._storeDate(dotDate.toDate());
  1135. this.card.setPokerEnd(dotDate.toDate());
  1136. } else {
  1137. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1138. }
  1139. Popup.back();
  1140. } else if (brezhonegDate.isValid()) {
  1141. // if active poker - store it
  1142. if (this.currentData().getPokerQuestion()) {
  1143. this._storeDate(brezhonegDate.toDate());
  1144. this.card.setPokerEnd(brezhonegDate.toDate());
  1145. } else {
  1146. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1147. }
  1148. Popup.back();
  1149. } else if (hrvatskiDate.isValid()) {
  1150. // if active poker - store it
  1151. if (this.currentData().getPokerQuestion()) {
  1152. this._storeDate(hrvatskiDate.toDate());
  1153. this.card.setPokerEnd(hrvatskiDate.toDate());
  1154. } else {
  1155. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1156. Popup.back();
  1157. }
  1158. } else if (latviaDate.isValid()) {
  1159. // if active poker - store it
  1160. if (this.currentData().getPokerQuestion()) {
  1161. this._storeDate(latviaDate.toDate());
  1162. this.card.setPokerEnd(latviaDate.toDate());
  1163. } else {
  1164. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1165. }
  1166. Popup.back();
  1167. } else if (nederlandsDate.isValid()) {
  1168. // if active poker - store it
  1169. if (this.currentData().getPokerQuestion()) {
  1170. this._storeDate(nederlandsDate.toDate());
  1171. this.card.setPokerEnd(nederlandsDate.toDate());
  1172. } else {
  1173. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1174. }
  1175. Popup.back();
  1176. } else if (greekDate.isValid()) {
  1177. // if active poker - store it
  1178. if (this.currentData().getPokerQuestion()) {
  1179. this._storeDate(greekDate.toDate());
  1180. this.card.setPokerEnd(greekDate.toDate());
  1181. } else {
  1182. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1183. }
  1184. Popup.back();
  1185. } else if (macedonianDate.isValid()) {
  1186. // if active poker - store it
  1187. if (this.currentData().getPokerQuestion()) {
  1188. this._storeDate(macedonianDate.toDate());
  1189. this.card.setPokerEnd(macedonianDate.toDate());
  1190. } else {
  1191. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1192. }
  1193. Popup.back();
  1194. } else {
  1195. this.error.set('invalid-date');
  1196. evt.target.date.focus();
  1197. }
  1198. },
  1199. 'click .js-delete-date'(evt) {
  1200. evt.preventDefault();
  1201. this._deleteDate();
  1202. Popup.back();
  1203. },
  1204. },
  1205. ];
  1206. }
  1207. _storeDate(newDate) {
  1208. this.card.setVoteEnd(newDate);
  1209. }
  1210. _deleteDate() {
  1211. this.card.unsetVoteEnd();
  1212. }
  1213. }.register('editVoteEndDatePopup'));
  1214. BlazeComponent.extendComponent({
  1215. onCreated() {
  1216. this.currentCard = this.currentData();
  1217. this.pokerQuestion = new ReactiveVar(this.currentCard.pokerQuestion);
  1218. },
  1219. events() {
  1220. return [
  1221. {
  1222. 'click .js-end-date': Popup.open('editPokerEndDate'),
  1223. 'submit .edit-poker-question'(evt) {
  1224. evt.preventDefault();
  1225. const pokerQuestion = true;
  1226. const allowNonBoardMembers = $('#poker-allow-non-members').hasClass(
  1227. 'is-checked',
  1228. );
  1229. const endString = this.currentCard.getPokerEnd();
  1230. this.currentCard.setPokerQuestion(
  1231. pokerQuestion,
  1232. allowNonBoardMembers,
  1233. );
  1234. if (endString) {
  1235. this.currentCard.setPokerEnd(endString);
  1236. }
  1237. Popup.back();
  1238. },
  1239. 'click .js-remove-poker': Popup.afterConfirm('deletePoker', (event) => {
  1240. this.currentCard.unsetPoker();
  1241. Popup.back();
  1242. }),
  1243. 'click a.js-toggle-poker-allow-non-members'(event) {
  1244. event.preventDefault();
  1245. $('#poker-allow-non-members').toggleClass('is-checked');
  1246. },
  1247. },
  1248. ];
  1249. },
  1250. }).register('cardStartPlanningPokerPopup');
  1251. // editPokerEndDatePopup
  1252. (class extends DatePicker {
  1253. onCreated() {
  1254. super.onCreated(formatDateTime(now()));
  1255. this.data().getPokerEnd() &&
  1256. this.date.set(new Date(this.data().getPokerEnd()));
  1257. }
  1258. /*
  1259. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1260. to make detecting all date formats not necessary,
  1261. but got error "language mk does not exist".
  1262. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1263. datepicker format that could be used to detect date format?
  1264. dateFormat() {
  1265. return moment.localeData().longDateFormat('L');
  1266. }
  1267. timeFormat() {
  1268. return moment.localeData().longDateFormat('LT');
  1269. }
  1270. const newDate = parseDate(dateString, [dateformat() + ' ' + timeformat()], true);
  1271. */
  1272. events() {
  1273. return [
  1274. {
  1275. 'submit .edit-date'(evt) {
  1276. evt.preventDefault();
  1277. // if no time was given, init with 12:00
  1278. const time =
  1279. evt.target.time.value ||
  1280. formatTime(new Date().setHours(12, 0, 0));
  1281. const dateString = `${evt.target.date.value} ${time}`;
  1282. /*
  1283. Tried to use dateFormat and timeFormat from client/components/lib/datepicker.js
  1284. to make detecting all date formats not necessary,
  1285. but got error "language mk does not exist".
  1286. Maybe client/components/lib/datepicker.jade could have hidden input field for
  1287. datepicker format that could be used to detect date format?
  1288. const newDate = parseDate(dateString, [dateformat() + ' ' + timeformat()], true);
  1289. if (newDate.isValid()) {
  1290. // if active poker - store it
  1291. if (this.currentData().getPokerQuestion()) {
  1292. this._storeDate(newDate.toDate());
  1293. Popup.back();
  1294. } else {
  1295. this.currentData().poker = { end: newDate.toDate() }; // set poker end temp
  1296. Popup.back();
  1297. }
  1298. */
  1299. // Try to parse different date formats using native Date parsing
  1300. const formats = [
  1301. 'YYYY-MM-DD HH:mm',
  1302. 'MM/DD/YYYY HH:mm',
  1303. 'DD.MM.YYYY HH:mm',
  1304. 'DD/MM/YYYY HH:mm',
  1305. 'DD-MM-YYYY HH:mm'
  1306. ];
  1307. let parsedDate = null;
  1308. for (const format of formats) {
  1309. parsedDate = parseDate(dateString, [format], true);
  1310. if (parsedDate) break;
  1311. }
  1312. // Fallback to native Date parsing
  1313. if (!parsedDate) {
  1314. parsedDate = new Date(dateString);
  1315. }
  1316. if (isValidDate(parsedDate)) {
  1317. // if active poker - store it
  1318. if (this.currentData().getPokerQuestion()) {
  1319. this._storeDate(usaDate.toDate());
  1320. } else {
  1321. this.currentData().poker = { end: usaDate.toDate() }; // set poker end temp
  1322. }
  1323. Popup.back();
  1324. } else if (euroAmDate.isValid()) {
  1325. // if active poker - store it
  1326. if (this.currentData().getPokerQuestion()) {
  1327. this._storeDate(euroAmDate.toDate());
  1328. } else {
  1329. this.currentData().poker = { end: euroAmDate.toDate() }; // set poker end temp
  1330. }
  1331. Popup.back();
  1332. } else if (euro24hDate.isValid()) {
  1333. // if active poker - store it
  1334. if (this.currentData().getPokerQuestion()) {
  1335. this._storeDate(euro24hDate.toDate());
  1336. this.card.setPokerEnd(euro24hDate.toDate());
  1337. } else {
  1338. this.currentData().poker = { end: euro24hDate.toDate() }; // set poker end temp
  1339. }
  1340. Popup.back();
  1341. } else if (eurodotDate.isValid()) {
  1342. // if active poker - store it
  1343. if (this.currentData().getPokerQuestion()) {
  1344. this._storeDate(eurodotDate.toDate());
  1345. this.card.setPokerEnd(eurodotDate.toDate());
  1346. } else {
  1347. this.currentData().poker = { end: eurodotDate.toDate() }; // set poker end temp
  1348. }
  1349. Popup.back();
  1350. } else if (minusDate.isValid()) {
  1351. // if active poker - store it
  1352. if (this.currentData().getPokerQuestion()) {
  1353. this._storeDate(minusDate.toDate());
  1354. this.card.setPokerEnd(minusDate.toDate());
  1355. } else {
  1356. this.currentData().poker = { end: minusDate.toDate() }; // set poker end temp
  1357. }
  1358. Popup.back();
  1359. } else if (slashDate.isValid()) {
  1360. // if active poker - store it
  1361. if (this.currentData().getPokerQuestion()) {
  1362. this._storeDate(slashDate.toDate());
  1363. this.card.setPokerEnd(slashDate.toDate());
  1364. } else {
  1365. this.currentData().poker = { end: slashDate.toDate() }; // set poker end temp
  1366. }
  1367. Popup.back();
  1368. } else if (dotDate.isValid()) {
  1369. // if active poker - store it
  1370. if (this.currentData().getPokerQuestion()) {
  1371. this._storeDate(dotDate.toDate());
  1372. this.card.setPokerEnd(dotDate.toDate());
  1373. } else {
  1374. this.currentData().poker = { end: dotDate.toDate() }; // set poker end temp
  1375. }
  1376. Popup.back();
  1377. } else if (brezhonegDate.isValid()) {
  1378. // if active poker - store it
  1379. if (this.currentData().getPokerQuestion()) {
  1380. this._storeDate(brezhonegDate.toDate());
  1381. this.card.setPokerEnd(brezhonegDate.toDate());
  1382. } else {
  1383. this.currentData().poker = { end: brezhonegDate.toDate() }; // set poker end temp
  1384. }
  1385. Popup.back();
  1386. } else if (hrvatskiDate.isValid()) {
  1387. // if active poker - store it
  1388. if (this.currentData().getPokerQuestion()) {
  1389. this._storeDate(hrvatskiDate.toDate());
  1390. this.card.setPokerEnd(hrvatskiDate.toDate());
  1391. } else {
  1392. this.currentData().poker = { end: hrvatskiDate.toDate() }; // set poker end temp
  1393. }
  1394. Popup.back();
  1395. } else if (latviaDate.isValid()) {
  1396. // if active poker - store it
  1397. if (this.currentData().getPokerQuestion()) {
  1398. this._storeDate(latviaDate.toDate());
  1399. this.card.setPokerEnd(latviaDate.toDate());
  1400. } else {
  1401. this.currentData().poker = { end: latviaDate.toDate() }; // set poker end temp
  1402. }
  1403. Popup.back();
  1404. } else if (nederlandsDate.isValid()) {
  1405. // if active poker - store it
  1406. if (this.currentData().getPokerQuestion()) {
  1407. this._storeDate(nederlandsDate.toDate());
  1408. this.card.setPokerEnd(nederlandsDate.toDate());
  1409. } else {
  1410. this.currentData().poker = { end: nederlandsDate.toDate() }; // set poker end temp
  1411. }
  1412. Popup.back();
  1413. } else if (greekDate.isValid()) {
  1414. // if active poker - store it
  1415. if (this.currentData().getPokerQuestion()) {
  1416. this._storeDate(greekDate.toDate());
  1417. this.card.setPokerEnd(greekDate.toDate());
  1418. } else {
  1419. this.currentData().poker = { end: greekDate.toDate() }; // set poker end temp
  1420. }
  1421. Popup.back();
  1422. } else if (macedonianDate.isValid()) {
  1423. // if active poker - store it
  1424. if (this.currentData().getPokerQuestion()) {
  1425. this._storeDate(macedonianDate.toDate());
  1426. this.card.setPokerEnd(macedonianDate.toDate());
  1427. } else {
  1428. this.currentData().poker = { end: macedonianDate.toDate() }; // set poker end temp
  1429. }
  1430. Popup.back();
  1431. } else {
  1432. // this.error.set('invalid-date);
  1433. this.error.set('invalid-date' + ' ' + dateString);
  1434. evt.target.date.focus();
  1435. }
  1436. },
  1437. 'click .js-delete-date'(evt) {
  1438. evt.preventDefault();
  1439. this._deleteDate();
  1440. Popup.back();
  1441. },
  1442. },
  1443. ];
  1444. }
  1445. _storeDate(newDate) {
  1446. this.card.setPokerEnd(newDate);
  1447. }
  1448. _deleteDate() {
  1449. this.card.unsetPokerEnd();
  1450. }
  1451. }.register('editPokerEndDatePopup'));
  1452. // Close the card details pane by pressing escape
  1453. EscapeActions.register(
  1454. 'detailsPane',
  1455. () => {
  1456. // if card description diverges from database due to editing
  1457. // ask user whether changes should be applied
  1458. if (ReactiveCache.getCurrentUser()) {
  1459. if (ReactiveCache.getCurrentUser().profile.rescueCardDescription == true) {
  1460. currentDescription = document.getElementsByClassName("editor js-new-description-input").item(0)
  1461. if (currentDescription?.value && !(currentDescription.value === Utils.getCurrentCard().getDescription())) {
  1462. if (confirm(TAPi18n.__('rescue-card-description-dialogue'))) {
  1463. Utils.getCurrentCard().setDescription(document.getElementsByClassName("editor js-new-description-input").item(0).value);
  1464. // Save it!
  1465. console.log(document.getElementsByClassName("editor js-new-description-input").item(0).value);
  1466. console.log("current description", Utils.getCurrentCard().getDescription());
  1467. } else {
  1468. // Do nothing!
  1469. console.log('Description changes were not saved to the database.');
  1470. }
  1471. }
  1472. }
  1473. }
  1474. if (Session.get('cardDetailsIsDragging')) {
  1475. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1476. Session.set('cardDetailsIsDragging', false);
  1477. Session.set('cardDetailsIsMouseDown', false);
  1478. } else {
  1479. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1480. Utils.goBoardId(Session.get('currentBoard'));
  1481. }
  1482. },
  1483. () => {
  1484. return !Session.equals('currentCard', null);
  1485. },
  1486. {
  1487. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1488. },
  1489. );
  1490. Template.cardAssigneesPopup.onCreated(function () {
  1491. let currBoard = Utils.getCurrentBoard();
  1492. let members = currBoard.activeMembers();
  1493. this.members = new ReactiveVar(members);
  1494. });
  1495. Template.cardAssigneesPopup.events({
  1496. 'click .js-select-assignee'(event) {
  1497. const card = Utils.getCurrentCard();
  1498. const assigneeId = this.userId;
  1499. card.toggleAssignee(assigneeId);
  1500. event.preventDefault();
  1501. },
  1502. 'keyup .card-assignees-filter'(event) {
  1503. const members = filterMembers(event.target.value);
  1504. Template.instance().members.set(members);
  1505. },
  1506. });
  1507. Template.cardAssigneesPopup.helpers({
  1508. isCardAssignee() {
  1509. const card = Template.parentData();
  1510. const cardAssignees = card.getAssignees();
  1511. return _.contains(cardAssignees, this.userId);
  1512. },
  1513. members() {
  1514. return _.sortBy(Template.instance().members.get(),'fullname');
  1515. },
  1516. user() {
  1517. return ReactiveCache.getUser(this.userId);
  1518. },
  1519. });
  1520. Template.cardAssigneePopup.helpers({
  1521. userData() {
  1522. return ReactiveCache.getUser(this.userId, {
  1523. fields: {
  1524. profile: 1,
  1525. username: 1,
  1526. },
  1527. });
  1528. },
  1529. memberType() {
  1530. const user = ReactiveCache.getUser(this.userId);
  1531. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1532. },
  1533. isCardAssignee() {
  1534. const card = Template.parentData();
  1535. const cardAssignees = card.getAssignees();
  1536. return _.contains(cardAssignees, this.userId);
  1537. },
  1538. user() {
  1539. return ReactiveCache.getUser(this.userId);
  1540. },
  1541. });
  1542. Template.cardAssigneePopup.events({
  1543. 'click .js-remove-assignee'() {
  1544. ReactiveCache.getCard(this.cardId).unassignAssignee(this.userId);
  1545. Popup.back();
  1546. },
  1547. 'click .js-edit-profile': Popup.open('editProfile'),
  1548. });