cardDetails.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  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. // TODO sometimes parentComponent is not available, maybe because it's not
  75. // yet created?!
  76. if (!parentComponent) return;
  77. const bodyBoardComponent = parentComponent.parentComponent();
  78. //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
  79. if (bodyBoardComponent === null) return;
  80. const $cardView = this.$(this.firstNode());
  81. const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
  82. // TODO sometimes cardContainer is not available, maybe because it's not yet
  83. // created?!
  84. if (!$cardContainer) return;
  85. const cardContainerScroll = $cardContainer.scrollLeft();
  86. const cardContainerWidth = $cardContainer.width();
  87. const cardViewStart = $cardView.offset().left;
  88. const cardViewEnd = cardViewStart + cardPanelWidth;
  89. let offset = false;
  90. if (cardViewStart < 0) {
  91. offset = cardViewStart;
  92. } else if (cardViewEnd > cardContainerWidth) {
  93. offset = cardViewEnd - cardContainerWidth;
  94. }
  95. if (offset) {
  96. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  97. }
  98. //Scroll top
  99. const cardViewStartTop = $cardView.offset().top;
  100. const cardContainerScrollTop = $cardContainer.scrollTop();
  101. let topOffset = false;
  102. if (cardViewStartTop !== 100) {
  103. topOffset = cardViewStartTop - 100;
  104. }
  105. if (topOffset !== false) {
  106. bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
  107. }
  108. },
  109. presentParentTask() {
  110. let result = this.currentBoard.presentParentTask;
  111. if (result === null || result === undefined) {
  112. result = 'no-parent';
  113. }
  114. return result;
  115. },
  116. linkForCard() {
  117. const card = this.currentData();
  118. let result = '#';
  119. if (card) {
  120. const board = Boards.findOne(card.boardId);
  121. if (board) {
  122. result = FlowRouter.path('card', {
  123. boardId: card.boardId,
  124. slug: board.slug,
  125. cardId: card._id,
  126. });
  127. }
  128. }
  129. return result;
  130. },
  131. showVotingButtons() {
  132. const card = this.currentData();
  133. return (
  134. (currentUser.isBoardMember() ||
  135. (currentUser && card.voteAllowNonBoardMembers())) &&
  136. !card.expiredVote()
  137. );
  138. },
  139. showPlanningPokerButtons() {
  140. const card = this.currentData();
  141. return (
  142. (currentUser.isBoardMember() ||
  143. (currentUser && card.pokerAllowNonBoardMembers())) &&
  144. !card.expiredPoker()
  145. );
  146. },
  147. /** returns if the list id is the current list id
  148. * @param listId list id to check
  149. * @return is the list id the current list id ?
  150. */
  151. isCurrentListId(listId) {
  152. const ret = this.data().listId == listId;
  153. return ret;
  154. },
  155. onRendered() {
  156. if (Meteor.settings.public.CARD_OPENED_WEBHOOK_ENABLED) {
  157. // Send Webhook but not create Activities records ---
  158. const card = this.currentData();
  159. const userId = Meteor.userId();
  160. const params = {
  161. userId,
  162. cardId: card._id,
  163. boardId: card.boardId,
  164. listId: card.listId,
  165. user: Meteor.user().username,
  166. url: '',
  167. };
  168. const integrations = Integrations.find({
  169. boardId: { $in: [card.boardId, Integrations.Const.GLOBAL_WEBHOOK_ID] },
  170. enabled: true,
  171. activities: { $in: ['CardDetailsRendered', 'all'] },
  172. }).fetch();
  173. if (integrations.length > 0) {
  174. integrations.forEach((integration) => {
  175. Meteor.call(
  176. 'outgoingWebhooks',
  177. integration,
  178. 'CardSelected',
  179. params,
  180. () => { },
  181. );
  182. });
  183. }
  184. //-------------
  185. }
  186. const $checklistsDom = this.$('.card-checklist-items');
  187. $checklistsDom.sortable({
  188. tolerance: 'pointer',
  189. helper: 'clone',
  190. handle: '.checklist-title',
  191. items: '.js-checklist',
  192. placeholder: 'checklist placeholder',
  193. distance: 7,
  194. start(evt, ui) {
  195. ui.placeholder.height(ui.helper.height());
  196. EscapeActions.clickExecute(evt.target, 'inlinedForm');
  197. },
  198. stop(evt, ui) {
  199. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  200. if (prevChecklist) {
  201. prevChecklist = Blaze.getData(prevChecklist).checklist;
  202. }
  203. let nextChecklist = ui.item.next('.js-checklist').get(0);
  204. if (nextChecklist) {
  205. nextChecklist = Blaze.getData(nextChecklist).checklist;
  206. }
  207. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  208. $checklistsDom.sortable('cancel');
  209. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  210. Checklists.update(checklist._id, {
  211. $set: {
  212. sort: sortIndex.base,
  213. },
  214. });
  215. },
  216. });
  217. const $subtasksDom = this.$('.card-subtasks-items');
  218. $subtasksDom.sortable({
  219. tolerance: 'pointer',
  220. helper: 'clone',
  221. handle: '.subtask-title',
  222. items: '.js-subtasks',
  223. placeholder: 'subtasks placeholder',
  224. distance: 7,
  225. start(evt, ui) {
  226. ui.placeholder.height(ui.helper.height());
  227. EscapeActions.executeUpTo('popup-close');
  228. },
  229. stop(evt, ui) {
  230. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  231. if (prevChecklist) {
  232. prevChecklist = Blaze.getData(prevChecklist).subtask;
  233. }
  234. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  235. if (nextChecklist) {
  236. nextChecklist = Blaze.getData(nextChecklist).subtask;
  237. }
  238. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  239. $subtasksDom.sortable('cancel');
  240. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  241. Subtasks.update(subtask._id, {
  242. $set: {
  243. subtaskSort: sortIndex.base,
  244. },
  245. });
  246. },
  247. });
  248. function userIsMember() {
  249. return Meteor.user() && Meteor.user().isBoardMember();
  250. }
  251. // Disable sorting if the current user is not a board member
  252. this.autorun(() => {
  253. const disabled = !userIsMember();
  254. if (
  255. $checklistsDom.data('uiSortable') ||
  256. $checklistsDom.data('sortable')
  257. ) {
  258. $checklistsDom.sortable('option', 'disabled', disabled);
  259. if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
  260. $checklistsDom.sortable({ handle: '.checklist-handle' });
  261. }
  262. }
  263. if ($subtasksDom.data('uiSortable') || $subtasksDom.data('sortable')) {
  264. $subtasksDom.sortable('option', 'disabled', disabled);
  265. }
  266. });
  267. },
  268. onDestroyed() {
  269. if (this.parentComponent() === null) return;
  270. const parentComponent = this.parentComponent().parentComponent();
  271. //on mobile view parent is Board, not board body.
  272. if (parentComponent === null) return;
  273. parentComponent.showOverlay.set(false);
  274. },
  275. events() {
  276. const events = {
  277. [`${CSSEvents.transitionend} .js-card-details`]() {
  278. this.isLoaded.set(true);
  279. },
  280. [`${CSSEvents.animationend} .js-card-details`]() {
  281. this.isLoaded.set(true);
  282. },
  283. };
  284. return [
  285. {
  286. ...events,
  287. 'click .js-close-card-details'() {
  288. Utils.goBoardId(this.data().boardId);
  289. },
  290. 'click .js-copy-link'(event) {
  291. event.preventDefault();
  292. const promise = Utils.copyTextToClipboard(event.target.href);
  293. const $tooltip = this.$('.card-details-header .copied-tooltip');
  294. Utils.showCopied(promise, $tooltip);
  295. },
  296. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  297. 'submit .js-card-description'(event) {
  298. event.preventDefault();
  299. const description = this.currentComponent().getValue();
  300. this.data().setDescription(description);
  301. },
  302. 'submit .js-card-details-title'(event) {
  303. event.preventDefault();
  304. const title = this.currentComponent().getValue().trim();
  305. if (title) {
  306. this.data().setTitle(title);
  307. } else {
  308. this.data().setTitle('');
  309. }
  310. },
  311. 'submit .js-card-details-assigner'(event) {
  312. event.preventDefault();
  313. const assigner = this.currentComponent().getValue().trim();
  314. if (assigner) {
  315. this.data().setAssignedBy(assigner);
  316. } else {
  317. this.data().setAssignedBy('');
  318. }
  319. },
  320. 'submit .js-card-details-requester'(event) {
  321. event.preventDefault();
  322. const requester = this.currentComponent().getValue().trim();
  323. if (requester) {
  324. this.data().setRequestedBy(requester);
  325. } else {
  326. this.data().setRequestedBy('');
  327. }
  328. },
  329. 'keydown input.js-edit-card-sort'(evt) {
  330. // enter = save
  331. if (evt.keyCode === 13) {
  332. this.find('button[type=submit]').click();
  333. }
  334. },
  335. 'submit .js-card-details-sort'(event) {
  336. event.preventDefault();
  337. const sort = parseFloat(this.currentComponent()
  338. .getValue()
  339. .trim());
  340. if (!Number.isNaN(sort)) {
  341. let card = this.data();
  342. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  343. }
  344. },
  345. 'change .js-select-card-details-lists'(event) {
  346. let card = this.data();
  347. const listSelect = this.$('.js-select-card-details-lists')[0];
  348. const listId = listSelect.options[listSelect.selectedIndex].value;
  349. const minOrder = card.getMinSort(listId, card.swimlaneId);
  350. card.move(card.boardId, card.swimlaneId, listId, minOrder - 1);
  351. },
  352. 'click .js-go-to-linked-card'() {
  353. Utils.goCardId(this.data().linkedId);
  354. },
  355. 'click .js-member': Popup.open('cardMember'),
  356. 'click .js-add-members': Popup.open('cardMembers'),
  357. 'click .js-assignee': Popup.open('cardAssignee'),
  358. 'click .js-add-assignees': Popup.open('cardAssignees'),
  359. 'click .js-add-labels': Popup.open('cardLabels'),
  360. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  361. 'click .js-start-date': Popup.open('editCardStartDate'),
  362. 'click .js-due-date': Popup.open('editCardDueDate'),
  363. 'click .js-end-date': Popup.open('editCardEndDate'),
  364. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  365. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  366. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  367. 'mouseenter .js-card-details'() {
  368. if (this.parentComponent() === null) return;
  369. const parentComponent = this.parentComponent().parentComponent();
  370. //on mobile view parent is Board, not BoardBody.
  371. if (parentComponent === null) return;
  372. parentComponent.showOverlay.set(true);
  373. parentComponent.mouseHasEnterCardDetails = true;
  374. },
  375. 'mousedown .js-card-details'() {
  376. Session.set('cardDetailsIsDragging', false);
  377. Session.set('cardDetailsIsMouseDown', true);
  378. },
  379. 'mousemove .js-card-details'() {
  380. if (Session.get('cardDetailsIsMouseDown')) {
  381. Session.set('cardDetailsIsDragging', true);
  382. }
  383. },
  384. 'mouseup .js-card-details'() {
  385. Session.set('cardDetailsIsDragging', false);
  386. Session.set('cardDetailsIsMouseDown', false);
  387. },
  388. 'click #toggleButton'() {
  389. Meteor.call('toggleSystemMessages');
  390. },
  391. 'click #toggleCustomFieldsGridButton'() {
  392. Meteor.call('toggleCustomFieldsGrid');
  393. },
  394. 'click .js-maximize-card-details'() {
  395. Meteor.call('toggleCardMaximized');
  396. autosize($('.card-details'));
  397. if (!Utils.isMiniScreen()) {
  398. Meteor.setTimeout(() => {
  399. this.scrollParentContainer();
  400. }, 500);
  401. }
  402. },
  403. 'click .js-minimize-card-details'() {
  404. Meteor.call('toggleCardMaximized');
  405. autosize($('.card-details'));
  406. if (!Utils.isMiniScreen()) {
  407. Meteor.setTimeout(() => {
  408. this.scrollParentContainer();
  409. }, 500);
  410. }
  411. },
  412. 'click .js-vote'(e) {
  413. const forIt = $(e.target).hasClass('js-vote-positive');
  414. let newState = null;
  415. if (
  416. this.data().voteState() === null ||
  417. (this.data().voteState() === false && forIt) ||
  418. (this.data().voteState() === true && !forIt)
  419. ) {
  420. newState = forIt;
  421. }
  422. this.data().setVote(Meteor.userId(), newState);
  423. },
  424. 'click .js-poker'(e) {
  425. let newState = null;
  426. if ($(e.target).hasClass('js-poker-vote-one')) {
  427. newState = 'one';
  428. this.data().setPoker(Meteor.userId(), newState);
  429. }
  430. if ($(e.target).hasClass('js-poker-vote-two')) {
  431. newState = 'two';
  432. this.data().setPoker(Meteor.userId(), newState);
  433. }
  434. if ($(e.target).hasClass('js-poker-vote-three')) {
  435. newState = 'three';
  436. this.data().setPoker(Meteor.userId(), newState);
  437. }
  438. if ($(e.target).hasClass('js-poker-vote-five')) {
  439. newState = 'five';
  440. this.data().setPoker(Meteor.userId(), newState);
  441. }
  442. if ($(e.target).hasClass('js-poker-vote-eight')) {
  443. newState = 'eight';
  444. this.data().setPoker(Meteor.userId(), newState);
  445. }
  446. if ($(e.target).hasClass('js-poker-vote-thirteen')) {
  447. newState = 'thirteen';
  448. this.data().setPoker(Meteor.userId(), newState);
  449. }
  450. if ($(e.target).hasClass('js-poker-vote-twenty')) {
  451. newState = 'twenty';
  452. this.data().setPoker(Meteor.userId(), newState);
  453. }
  454. if ($(e.target).hasClass('js-poker-vote-forty')) {
  455. newState = 'forty';
  456. this.data().setPoker(Meteor.userId(), newState);
  457. }
  458. if ($(e.target).hasClass('js-poker-vote-one-hundred')) {
  459. newState = 'oneHundred';
  460. this.data().setPoker(Meteor.userId(), newState);
  461. }
  462. if ($(e.target).hasClass('js-poker-vote-unsure')) {
  463. newState = 'unsure';
  464. this.data().setPoker(Meteor.userId(), newState);
  465. }
  466. },
  467. 'click .js-poker-finish'(e) {
  468. if ($(e.target).hasClass('js-poker-finish')) {
  469. e.preventDefault();
  470. const now = moment().format('YYYY-MM-DD HH:mm');
  471. this.data().setPokerEnd(now);
  472. }
  473. },
  474. 'click .js-poker-replay'(e) {
  475. if ($(e.target).hasClass('js-poker-replay')) {
  476. e.preventDefault();
  477. this.currentCard = this.currentData();
  478. this.currentCard.replayPoker();
  479. this.data().unsetPokerEnd();
  480. this.data().unsetPokerEstimation();
  481. }
  482. },
  483. 'click .js-poker-estimation'(event) {
  484. event.preventDefault();
  485. const ruleTitle = this.find('#pokerEstimation').value;
  486. if (ruleTitle !== undefined && ruleTitle !== '') {
  487. this.find('#pokerEstimation').value = '';
  488. if (ruleTitle) {
  489. this.data().setPokerEstimation(parseInt(ruleTitle, 10));
  490. } else {
  491. this.data().setPokerEstimation('');
  492. }
  493. }
  494. },
  495. },
  496. ];
  497. },
  498. }).register('cardDetails');
  499. Template.cardDetails.helpers({
  500. isPopup() {
  501. let ret = !!Utils.getPopupCardId();
  502. return ret;
  503. }
  504. });
  505. Template.cardDetailsPopup.onDestroyed(() => {
  506. Session.delete('popupCardId');
  507. Session.delete('popupCardBoardId');
  508. });
  509. Template.cardDetailsPopup.helpers({
  510. popupCard() {
  511. const ret = Utils.getPopupCard();
  512. return ret;
  513. },
  514. });
  515. BlazeComponent.extendComponent({
  516. template() {
  517. return 'exportCard';
  518. },
  519. withApi() {
  520. return Template.instance().apiEnabled.get();
  521. },
  522. exportUrlCardPDF() {
  523. const params = {
  524. boardId: Session.get('currentBoard'),
  525. listId: this.listId,
  526. cardId: this.cardId,
  527. };
  528. const queryParams = {
  529. authToken: Accounts._storedLoginToken(),
  530. };
  531. return FlowRouter.path(
  532. '/api/boards/:boardId/lists/:listId/cards/:cardId/exportPDF',
  533. params,
  534. queryParams,
  535. );
  536. },
  537. exportFilenameCardPDF() {
  538. //const boardId = Session.get('currentBoard');
  539. //return `export-card-pdf-${boardId}.xlsx`;
  540. return `export-card.pdf`;
  541. },
  542. }).register('exportCardPopup');
  543. // only allow number input
  544. Template.editCardSortOrderForm.onRendered(function () {
  545. this.$('input').on("keypress paste", function (event) {
  546. let keyCode = event.keyCode;
  547. let charCode = String.fromCharCode(keyCode);
  548. let regex = new RegExp('[-0-9.]');
  549. let ret = regex.test(charCode);
  550. // only working here, defining in events() doesn't handle the return value correctly
  551. return ret;
  552. });
  553. });
  554. // We extends the normal InlinedForm component to support UnsavedEdits draft
  555. // feature.
  556. (class extends InlinedForm {
  557. _getUnsavedEditKey() {
  558. return {
  559. fieldName: 'cardDescription',
  560. // XXX Recovering the currentCard identifier form a session variable is
  561. // fragile because this variable may change for instance if the route
  562. // change. We should use some component props instead.
  563. docId: Utils.getCurrentCardId(),
  564. };
  565. }
  566. close(isReset = false) {
  567. if (this.isOpen.get() && !isReset) {
  568. const draft = this.getValue().trim();
  569. let card = Utils.getCurrentCard();
  570. if (card && draft !== card.getDescription()) {
  571. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  572. }
  573. }
  574. super.close();
  575. }
  576. reset() {
  577. UnsavedEdits.reset(this._getUnsavedEditKey());
  578. this.close(true);
  579. }
  580. events() {
  581. const parentEvents = InlinedForm.prototype.events()[0];
  582. return [
  583. {
  584. ...parentEvents,
  585. 'click .js-close-inlined-form': this.reset,
  586. },
  587. ];
  588. }
  589. }.register('inlinedCardDescription'));
  590. Template.cardDetailsActionsPopup.helpers({
  591. isWatching() {
  592. return this.findWatcher(Meteor.userId());
  593. },
  594. isBoardAdmin() {
  595. return Meteor.user().isBoardAdmin();
  596. },
  597. canModifyCard() {
  598. return (
  599. Meteor.user() &&
  600. Meteor.user().isBoardMember() &&
  601. !Meteor.user().isCommentOnly()
  602. );
  603. },
  604. });
  605. Template.cardDetailsActionsPopup.events({
  606. 'click .js-export-card': Popup.open('exportCard'),
  607. 'click .js-members': Popup.open('cardMembers'),
  608. 'click .js-assignees': Popup.open('cardAssignees'),
  609. 'click .js-attachments': Popup.open('cardAttachments'),
  610. 'click .js-start-voting': Popup.open('cardStartVoting'),
  611. 'click .js-start-planning-poker': Popup.open('cardStartPlanningPoker'),
  612. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  613. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  614. 'click .js-start-date': Popup.open('editCardStartDate'),
  615. 'click .js-due-date': Popup.open('editCardDueDate'),
  616. 'click .js-end-date': Popup.open('editCardEndDate'),
  617. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  618. 'click .js-move-card': Popup.open('moveCard'),
  619. 'click .js-copy-card': Popup.open('copyCard'),
  620. 'click .js-convert-checklist-item-to-card': Popup.open('convertChecklistItemToCard'),
  621. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  622. 'click .js-set-card-color': Popup.open('setCardColor'),
  623. 'click .js-move-card-to-top'(event) {
  624. event.preventDefault();
  625. const minOrder = _.min(
  626. this.list()
  627. .cardsUnfiltered(this.swimlaneId)
  628. .map((c) => c.sort),
  629. );
  630. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  631. Popup.back();
  632. },
  633. 'click .js-move-card-to-bottom'(event) {
  634. event.preventDefault();
  635. const maxOrder = _.max(
  636. this.list()
  637. .cardsUnfiltered(this.swimlaneId)
  638. .map((c) => c.sort),
  639. );
  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();
  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();
  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 (Session.get('cardDetailsIsDragging')) {
  1582. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1583. Session.set('cardDetailsIsDragging', false);
  1584. Session.set('cardDetailsIsMouseDown', false);
  1585. } else {
  1586. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1587. Utils.goBoardId(Session.get('currentBoard'));
  1588. }
  1589. },
  1590. () => {
  1591. return !Session.equals('currentCard', null);
  1592. },
  1593. {
  1594. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1595. },
  1596. );
  1597. Template.cardAssigneesPopup.onCreated(function () {
  1598. let currBoard = Boards.findOne(Session.get('currentBoard'));
  1599. let members = currBoard.activeMembers();
  1600. // let query = {
  1601. // "teams.teamId": { $in: currBoard.teams.map(t => t.teamId) },
  1602. // };
  1603. // let boardTeamUsers = Users.find(query, {
  1604. // sort: { sort: 1 },
  1605. // });
  1606. // members = currBoard.activeMembers2(members, boardTeamUsers);
  1607. this.members = new ReactiveVar(members);
  1608. });
  1609. Template.cardAssigneesPopup.events({
  1610. 'click .js-select-assignee'(event) {
  1611. const card = Utils.getCurrentCard();
  1612. const assigneeId = this.userId;
  1613. card.toggleAssignee(assigneeId);
  1614. event.preventDefault();
  1615. },
  1616. 'keyup .card-assignees-filter'(event) {
  1617. const members = filterMembers(event.target.value);
  1618. Template.instance().members.set(members);
  1619. },
  1620. });
  1621. Template.cardAssigneesPopup.helpers({
  1622. isCardAssignee() {
  1623. const card = Template.parentData();
  1624. const cardAssignees = card.getAssignees();
  1625. return _.contains(cardAssignees, this.userId);
  1626. },
  1627. members() {
  1628. return Template.instance().members.get();
  1629. },
  1630. user() {
  1631. return Users.findOne(this.userId);
  1632. },
  1633. });
  1634. Template.cardAssigneePopup.helpers({
  1635. userData() {
  1636. // We need to handle a special case for the search results provided by the
  1637. // `matteodem:easy-search` package. Since these results gets published in a
  1638. // separate collection, and not in the standard Meteor.Users collection as
  1639. // expected, we use a component parameter ("property") to distinguish the
  1640. // two cases.
  1641. const userCollection = this.esSearch ? ESSearchResults : Users;
  1642. return userCollection.findOne(this.userId, {
  1643. fields: {
  1644. profile: 1,
  1645. username: 1,
  1646. },
  1647. });
  1648. },
  1649. memberType() {
  1650. const user = Users.findOne(this.userId);
  1651. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1652. },
  1653. /*
  1654. presenceStatusClassName() {
  1655. const user = Users.findOne(this.userId);
  1656. const userPresence = presences.findOne({ userId: this.userId });
  1657. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1658. else if (!userPresence) return 'disconnected';
  1659. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1660. return 'active';
  1661. else return 'idle';
  1662. },
  1663. */
  1664. isCardAssignee() {
  1665. const card = Template.parentData();
  1666. const cardAssignees = card.getAssignees();
  1667. return _.contains(cardAssignees, this.userId);
  1668. },
  1669. user() {
  1670. return Users.findOne(this.userId);
  1671. },
  1672. });
  1673. Template.cardAssigneePopup.events({
  1674. 'click .js-remove-assignee'() {
  1675. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1676. Popup.back();
  1677. },
  1678. 'click .js-edit-profile': Popup.open('editProfile'),
  1679. });