cardDetails.js 60 KB

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