cardDetails.js 56 KB

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