cardDetails.js 53 KB

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