cardDetails.js 53 KB

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