2
0

cardDetails.js 61 KB

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