cardDetails.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. const subManager = new SubsManager();
  2. const { calculateIndexData } = Utils;
  3. let cardColors;
  4. Meteor.startup(() => {
  5. cardColors = Cards.simpleSchema()._schema.color.allowedValues;
  6. });
  7. BlazeComponent.extendComponent({
  8. mixins() {
  9. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  10. },
  11. calculateNextPeak() {
  12. const cardElement = this.find('.js-card-details');
  13. if (cardElement) {
  14. const altitude = cardElement.scrollHeight;
  15. this.callFirstWith(this, 'setNextPeak', altitude);
  16. }
  17. },
  18. reachNextPeak() {
  19. const activitiesComponent = this.childComponents('activities')[0];
  20. activitiesComponent.loadNextPage();
  21. },
  22. onCreated() {
  23. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  24. this.isLoaded = new ReactiveVar(false);
  25. const boardBody = this.parentComponent().parentComponent();
  26. //in Miniview parent is Board, not BoardBody.
  27. if (boardBody !== null) {
  28. boardBody.showOverlay.set(true);
  29. boardBody.mouseHasEnterCardDetails = false;
  30. }
  31. this.calculateNextPeak();
  32. Meteor.subscribe('unsaved-edits');
  33. },
  34. voteState() {
  35. const card = this.currentData();
  36. const userId = Meteor.userId();
  37. let state;
  38. if (card.vote) {
  39. if (card.vote.positive) {
  40. state = _.contains(card.vote.positive, userId);
  41. if (state === true) return true;
  42. }
  43. if (card.vote.negative) {
  44. state = _.contains(card.vote.negative, userId);
  45. if (state === true) return false;
  46. }
  47. }
  48. return null;
  49. },
  50. isWatching() {
  51. const card = this.currentData();
  52. return card.findWatcher(Meteor.userId());
  53. },
  54. hiddenSystemMessages() {
  55. return Meteor.user().hasHiddenSystemMessages();
  56. },
  57. canModifyCard() {
  58. return (
  59. Meteor.user() &&
  60. Meteor.user().isBoardMember() &&
  61. !Meteor.user().isCommentOnly() &&
  62. !Meteor.user().isWorker()
  63. );
  64. },
  65. scrollParentContainer() {
  66. const cardPanelWidth = 510;
  67. const parentComponent = this.parentComponent();
  68. // TODO sometimes parentComponent is not available, maybe because it's not
  69. // yet created?!
  70. if (!parentComponent) return;
  71. const bodyBoardComponent = parentComponent.parentComponent();
  72. //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
  73. if (bodyBoardComponent === null) return;
  74. const $cardView = this.$(this.firstNode());
  75. const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
  76. // TODO sometimes cardContainer is not available, maybe because it's not yet
  77. // created?!
  78. if (!$cardContainer) return;
  79. const cardContainerScroll = $cardContainer.scrollLeft();
  80. const cardContainerWidth = $cardContainer.width();
  81. const cardViewStart = $cardView.offset().left;
  82. const cardViewEnd = cardViewStart + cardPanelWidth;
  83. let offset = false;
  84. if (cardViewStart < 0) {
  85. offset = cardViewStart;
  86. } else if (cardViewEnd > cardContainerWidth) {
  87. offset = cardViewEnd - cardContainerWidth;
  88. }
  89. if (offset) {
  90. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  91. }
  92. //Scroll top
  93. const cardViewStartTop = $cardView.offset().top;
  94. const cardContainerScrollTop = $cardContainer.scrollTop();
  95. let topOffset = false;
  96. if (cardViewStartTop !== 100) {
  97. topOffset = cardViewStartTop - 100;
  98. }
  99. if (topOffset !== false) {
  100. bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
  101. }
  102. },
  103. presentParentTask() {
  104. let result = this.currentBoard.presentParentTask;
  105. if (result === null || result === undefined) {
  106. result = 'no-parent';
  107. }
  108. return result;
  109. },
  110. linkForCard() {
  111. const card = this.currentData();
  112. let result = '#';
  113. if (card) {
  114. const board = Boards.findOne(card.boardId);
  115. if (board) {
  116. result = FlowRouter.url('card', {
  117. boardId: card.boardId,
  118. slug: board.slug,
  119. cardId: card._id,
  120. });
  121. }
  122. }
  123. return result;
  124. },
  125. showVotingButtons() {
  126. const card = this.currentData();
  127. return (
  128. (currentUser.isBoardMember() ||
  129. (currentUser && card.voteAllowNonBoardMembers())) &&
  130. !card.expiredVote()
  131. );
  132. },
  133. onRendered() {
  134. if (Meteor.settings.public.CARD_OPENED_WEBHOOK_ENABLED) {
  135. // Send Webhook but not create Activities records ---
  136. const card = this.currentData();
  137. const userId = Meteor.userId();
  138. const params = {
  139. userId,
  140. cardId: card._id,
  141. boardId: card.boardId,
  142. listId: card.listId,
  143. user: Meteor.user().username,
  144. url: '',
  145. };
  146. const integrations = Integrations.find({
  147. boardId: { $in: [card.boardId, Integrations.Const.GLOBAL_WEBHOOK_ID] },
  148. enabled: true,
  149. activities: { $in: ['CardDetailsRendered', 'all'] },
  150. }).fetch();
  151. if (integrations.length > 0) {
  152. integrations.forEach(integration => {
  153. Meteor.call(
  154. 'outgoingWebhooks',
  155. integration,
  156. 'CardSelected',
  157. params,
  158. () => {
  159. return;
  160. },
  161. );
  162. });
  163. }
  164. //-------------
  165. }
  166. if (!Utils.isMiniScreen()) {
  167. Meteor.setTimeout(() => {
  168. $('.card-details').mCustomScrollbar({
  169. theme: 'minimal-dark',
  170. setWidth: false,
  171. setLeft: 0,
  172. scrollbarPosition: 'outside',
  173. mouseWheel: true,
  174. });
  175. this.scrollParentContainer();
  176. }, 500);
  177. }
  178. const $checklistsDom = this.$('.card-checklist-items');
  179. $checklistsDom.sortable({
  180. tolerance: 'pointer',
  181. helper: 'clone',
  182. handle: '.checklist-title',
  183. items: '.js-checklist',
  184. placeholder: 'checklist placeholder',
  185. distance: 7,
  186. start(evt, ui) {
  187. ui.placeholder.height(ui.helper.height());
  188. EscapeActions.executeUpTo('popup-close');
  189. },
  190. stop(evt, ui) {
  191. let prevChecklist = ui.item.prev('.js-checklist').get(0);
  192. if (prevChecklist) {
  193. prevChecklist = Blaze.getData(prevChecklist).checklist;
  194. }
  195. let nextChecklist = ui.item.next('.js-checklist').get(0);
  196. if (nextChecklist) {
  197. nextChecklist = Blaze.getData(nextChecklist).checklist;
  198. }
  199. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  200. $checklistsDom.sortable('cancel');
  201. const checklist = Blaze.getData(ui.item.get(0)).checklist;
  202. Checklists.update(checklist._id, {
  203. $set: {
  204. sort: sortIndex.base,
  205. },
  206. });
  207. },
  208. });
  209. const $subtasksDom = this.$('.card-subtasks-items');
  210. $subtasksDom.sortable({
  211. tolerance: 'pointer',
  212. helper: 'clone',
  213. handle: '.subtask-title',
  214. items: '.js-subtasks',
  215. placeholder: 'subtasks placeholder',
  216. distance: 7,
  217. start(evt, ui) {
  218. ui.placeholder.height(ui.helper.height());
  219. EscapeActions.executeUpTo('popup-close');
  220. },
  221. stop(evt, ui) {
  222. let prevChecklist = ui.item.prev('.js-subtasks').get(0);
  223. if (prevChecklist) {
  224. prevChecklist = Blaze.getData(prevChecklist).subtask;
  225. }
  226. let nextChecklist = ui.item.next('.js-subtasks').get(0);
  227. if (nextChecklist) {
  228. nextChecklist = Blaze.getData(nextChecklist).subtask;
  229. }
  230. const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
  231. $subtasksDom.sortable('cancel');
  232. const subtask = Blaze.getData(ui.item.get(0)).subtask;
  233. Subtasks.update(subtask._id, {
  234. $set: {
  235. subtaskSort: sortIndex.base,
  236. },
  237. });
  238. },
  239. });
  240. function userIsMember() {
  241. return Meteor.user() && Meteor.user().isBoardMember();
  242. }
  243. // Disable sorting if the current user is not a board member
  244. this.autorun(() => {
  245. const disabled = !userIsMember() || Utils.isMiniScreen();
  246. if (
  247. $checklistsDom.data('uiSortable') ||
  248. $checklistsDom.data('sortable')
  249. ) {
  250. $checklistsDom.sortable('option', 'disabled', disabled);
  251. }
  252. if ($subtasksDom.data('uiSortable') || $subtasksDom.data('sortable')) {
  253. $subtasksDom.sortable('option', 'disabled', disabled);
  254. }
  255. });
  256. },
  257. onDestroyed() {
  258. const parentComponent = this.parentComponent().parentComponent();
  259. //on mobile view parent is Board, not board body.
  260. if (parentComponent === null) return;
  261. parentComponent.showOverlay.set(false);
  262. },
  263. events() {
  264. const events = {
  265. [`${CSSEvents.transitionend} .js-card-details`]() {
  266. this.isLoaded.set(true);
  267. },
  268. [`${CSSEvents.animationend} .js-card-details`]() {
  269. this.isLoaded.set(true);
  270. },
  271. };
  272. return [
  273. {
  274. ...events,
  275. 'click .js-close-card-details'() {
  276. Utils.goBoardId(this.data().boardId);
  277. },
  278. 'click .js-copy-link'() {
  279. StringToCopyElement = document.getElementById('cardURL_copy');
  280. StringToCopyElement.select();
  281. if (document.execCommand('copy')) {
  282. StringToCopyElement.blur();
  283. } else {
  284. document.getElementById('cardURL_copy').selectionStart = 0;
  285. document.getElementById('cardURL_copy').selectionEnd = 999;
  286. document.execCommand('copy');
  287. if (window.getSelection) {
  288. if (window.getSelection().empty) {
  289. // Chrome
  290. window.getSelection().empty();
  291. } else if (window.getSelection().removeAllRanges) {
  292. // Firefox
  293. window.getSelection().removeAllRanges();
  294. }
  295. } else if (document.selection) {
  296. // IE?
  297. document.selection.empty();
  298. }
  299. }
  300. },
  301. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  302. 'submit .js-card-description'(event) {
  303. event.preventDefault();
  304. const description = this.currentComponent().getValue();
  305. this.data().setDescription(description);
  306. },
  307. 'submit .js-card-details-title'(event) {
  308. event.preventDefault();
  309. const title = this.currentComponent()
  310. .getValue()
  311. .trim();
  312. if (title) {
  313. this.data().setTitle(title);
  314. } else {
  315. this.data().setTitle('');
  316. }
  317. },
  318. 'submit .js-card-details-assigner'(event) {
  319. event.preventDefault();
  320. const assigner = this.currentComponent()
  321. .getValue()
  322. .trim();
  323. if (assigner) {
  324. this.data().setAssignedBy(assigner);
  325. } else {
  326. this.data().setAssignedBy('');
  327. }
  328. },
  329. 'submit .js-card-details-requester'(event) {
  330. event.preventDefault();
  331. const requester = this.currentComponent()
  332. .getValue()
  333. .trim();
  334. if (requester) {
  335. this.data().setRequestedBy(requester);
  336. } else {
  337. this.data().setRequestedBy('');
  338. }
  339. },
  340. 'click .js-go-to-linked-card'() {
  341. Utils.goCardId(this.data().linkedId);
  342. },
  343. 'click .js-member': Popup.open('cardMember'),
  344. 'click .js-add-members': Popup.open('cardMembers'),
  345. 'click .js-assignee': Popup.open('cardAssignee'),
  346. 'click .js-add-assignees': Popup.open('cardAssignees'),
  347. 'click .js-add-labels': Popup.open('cardLabels'),
  348. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  349. 'click .js-start-date': Popup.open('editCardStartDate'),
  350. 'click .js-due-date': Popup.open('editCardDueDate'),
  351. 'click .js-end-date': Popup.open('editCardEndDate'),
  352. 'click .js-show-positive-votes': Popup.open('positiveVoteMembers'),
  353. 'click .js-show-negative-votes': Popup.open('negativeVoteMembers'),
  354. 'mouseenter .js-card-details'() {
  355. const parentComponent = this.parentComponent().parentComponent();
  356. //on mobile view parent is Board, not BoardBody.
  357. if (parentComponent === null) return;
  358. parentComponent.showOverlay.set(true);
  359. parentComponent.mouseHasEnterCardDetails = true;
  360. },
  361. 'mousedown .js-card-details'() {
  362. Session.set('cardDetailsIsDragging', false);
  363. Session.set('cardDetailsIsMouseDown', true);
  364. },
  365. 'mousemove .js-card-details'() {
  366. if (Session.get('cardDetailsIsMouseDown')) {
  367. Session.set('cardDetailsIsDragging', true);
  368. }
  369. },
  370. 'mouseup .js-card-details'() {
  371. Session.set('cardDetailsIsDragging', false);
  372. Session.set('cardDetailsIsMouseDown', false);
  373. },
  374. 'click #toggleButton'() {
  375. Meteor.call('toggleSystemMessages');
  376. },
  377. 'click .js-vote'(e) {
  378. const forIt = $(e.target).hasClass('js-vote-positive');
  379. let newState = null;
  380. if (
  381. this.voteState() === null ||
  382. (this.voteState() === false && forIt) ||
  383. (this.voteState() === true && !forIt)
  384. ) {
  385. newState = forIt;
  386. }
  387. this.data().setVote(Meteor.userId(), newState);
  388. },
  389. },
  390. ];
  391. },
  392. }).register('cardDetails');
  393. Template.cardDetails.helpers({
  394. userData() {
  395. // We need to handle a special case for the search results provided by the
  396. // `matteodem:easy-search` package. Since these results gets published in a
  397. // separate collection, and not in the standard Meteor.Users collection as
  398. // expected, we use a component parameter ("property") to distinguish the
  399. // two cases.
  400. const userCollection = this.esSearch ? ESSearchResults : Users;
  401. return userCollection.findOne(this.userId, {
  402. fields: {
  403. profile: 1,
  404. username: 1,
  405. },
  406. });
  407. },
  408. receivedSelected() {
  409. if (this.getReceived().length === 0) {
  410. return false;
  411. } else {
  412. return true;
  413. }
  414. },
  415. startSelected() {
  416. if (this.getStart().length === 0) {
  417. return false;
  418. } else {
  419. return true;
  420. }
  421. },
  422. endSelected() {
  423. if (this.getEnd().length === 0) {
  424. return false;
  425. } else {
  426. return true;
  427. }
  428. },
  429. dueSelected() {
  430. if (this.getDue().length === 0) {
  431. return false;
  432. } else {
  433. return true;
  434. }
  435. },
  436. memberSelected() {
  437. if (this.getMembers().length === 0) {
  438. return false;
  439. } else {
  440. return true;
  441. }
  442. },
  443. labelSelected() {
  444. if (this.getLabels().length === 0) {
  445. return false;
  446. } else {
  447. return true;
  448. }
  449. },
  450. assigneeSelected() {
  451. if (this.getAssignees().length === 0) {
  452. return false;
  453. } else {
  454. return true;
  455. }
  456. },
  457. requestBySelected() {
  458. if (this.getRequestBy().length === 0) {
  459. return false;
  460. } else {
  461. return true;
  462. }
  463. },
  464. assigneeBySelected() {
  465. if (this.getAssigneeBy().length === 0) {
  466. return false;
  467. } else {
  468. return true;
  469. }
  470. },
  471. memberType() {
  472. const user = Users.findOne(this.userId);
  473. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  474. },
  475. presenceStatusClassName() {
  476. const user = Users.findOne(this.userId);
  477. const userPresence = presences.findOne({ userId: this.userId });
  478. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  479. else if (!userPresence) return 'disconnected';
  480. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  481. return 'active';
  482. else return 'idle';
  483. },
  484. });
  485. Template.userAvatarAssigneeInitials.helpers({
  486. initials() {
  487. const user = Users.findOne(this.userId);
  488. return user && user.getInitials();
  489. },
  490. viewPortWidth() {
  491. const user = Users.findOne(this.userId);
  492. return ((user && user.getInitials().length) || 1) * 12;
  493. },
  494. });
  495. // We extends the normal InlinedForm component to support UnsavedEdits draft
  496. // feature.
  497. (class extends InlinedForm {
  498. _getUnsavedEditKey() {
  499. return {
  500. fieldName: 'cardDescription',
  501. // XXX Recovering the currentCard identifier form a session variable is
  502. // fragile because this variable may change for instance if the route
  503. // change. We should use some component props instead.
  504. docId: Session.get('currentCard'),
  505. };
  506. }
  507. close(isReset = false) {
  508. if (this.isOpen.get() && !isReset) {
  509. const draft = this.getValue().trim();
  510. if (
  511. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  512. ) {
  513. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  514. }
  515. }
  516. super.close();
  517. }
  518. reset() {
  519. UnsavedEdits.reset(this._getUnsavedEditKey());
  520. this.close(true);
  521. }
  522. events() {
  523. const parentEvents = InlinedForm.prototype.events()[0];
  524. return [
  525. {
  526. ...parentEvents,
  527. 'click .js-close-inlined-form': this.reset,
  528. },
  529. ];
  530. }
  531. }.register('inlinedCardDescription'));
  532. Template.cardDetailsActionsPopup.helpers({
  533. isWatching() {
  534. return this.findWatcher(Meteor.userId());
  535. },
  536. canModifyCard() {
  537. return (
  538. Meteor.user() &&
  539. Meteor.user().isBoardMember() &&
  540. !Meteor.user().isCommentOnly()
  541. );
  542. },
  543. });
  544. Template.cardDetailsActionsPopup.events({
  545. 'click .js-members': Popup.open('cardMembers'),
  546. 'click .js-assignees': Popup.open('cardAssignees'),
  547. 'click .js-labels': Popup.open('cardLabels'),
  548. 'click .js-attachments': Popup.open('cardAttachments'),
  549. 'click .js-start-voting': Popup.open('cardStartVoting'),
  550. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  551. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  552. 'click .js-start-date': Popup.open('editCardStartDate'),
  553. 'click .js-due-date': Popup.open('editCardDueDate'),
  554. 'click .js-end-date': Popup.open('editCardEndDate'),
  555. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  556. 'click .js-move-card': Popup.open('moveCard'),
  557. 'click .js-copy-card': Popup.open('copyCard'),
  558. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  559. 'click .js-set-card-color': Popup.open('setCardColor'),
  560. 'click .js-move-card-to-top'(event) {
  561. event.preventDefault();
  562. const minOrder = _.min(
  563. this.list()
  564. .cards(this.swimlaneId)
  565. .map(c => c.sort),
  566. );
  567. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  568. },
  569. 'click .js-move-card-to-bottom'(event) {
  570. event.preventDefault();
  571. const maxOrder = _.max(
  572. this.list()
  573. .cards(this.swimlaneId)
  574. .map(c => c.sort),
  575. );
  576. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  577. },
  578. 'click .js-archive'(event) {
  579. event.preventDefault();
  580. this.archive();
  581. Popup.close();
  582. },
  583. 'click .js-more': Popup.open('cardMore'),
  584. 'click .js-toggle-watch-card'() {
  585. const currentCard = this;
  586. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  587. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  588. if (!err && ret) Popup.close();
  589. });
  590. },
  591. });
  592. Template.editCardTitleForm.onRendered(function() {
  593. autosize(this.$('.js-edit-card-title'));
  594. });
  595. Template.editCardTitleForm.events({
  596. 'keydown .js-edit-card-title'(event) {
  597. // If enter key was pressed, submit the data
  598. // Unless the shift key is also being pressed
  599. if (event.keyCode === 13 && !event.shiftKey) {
  600. $('.js-submit-edit-card-title-form').click();
  601. }
  602. },
  603. });
  604. Template.editCardRequesterForm.onRendered(function() {
  605. autosize(this.$('.js-edit-card-requester'));
  606. });
  607. Template.editCardRequesterForm.events({
  608. 'keydown .js-edit-card-requester'(event) {
  609. // If enter key was pressed, submit the data
  610. if (event.keyCode === 13) {
  611. $('.js-submit-edit-card-requester-form').click();
  612. }
  613. },
  614. });
  615. Template.editCardAssignerForm.onRendered(function() {
  616. autosize(this.$('.js-edit-card-assigner'));
  617. });
  618. Template.editCardAssignerForm.events({
  619. 'keydown .js-edit-card-assigner'(event) {
  620. // If enter key was pressed, submit the data
  621. if (event.keyCode === 13) {
  622. $('.js-submit-edit-card-assigner-form').click();
  623. }
  624. },
  625. });
  626. Template.moveCardPopup.events({
  627. 'click .js-done'() {
  628. // XXX We should *not* get the currentCard from the global state, but
  629. // instead from a “component” state.
  630. const card = Cards.findOne(Session.get('currentCard'));
  631. const bSelect = $('.js-select-boards')[0];
  632. const boardId = bSelect.options[bSelect.selectedIndex].value;
  633. const lSelect = $('.js-select-lists')[0];
  634. const listId = lSelect.options[lSelect.selectedIndex].value;
  635. const slSelect = $('.js-select-swimlanes')[0];
  636. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  637. card.move(boardId, swimlaneId, listId, 0);
  638. Popup.close();
  639. },
  640. });
  641. BlazeComponent.extendComponent({
  642. onCreated() {
  643. subManager.subscribe('board', Session.get('currentBoard'), false);
  644. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  645. },
  646. boards() {
  647. const boards = Boards.find(
  648. {
  649. archived: false,
  650. 'members.userId': Meteor.userId(),
  651. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  652. },
  653. {
  654. sort: { sort: 1 /* boards default sorting */ },
  655. },
  656. );
  657. return boards;
  658. },
  659. swimlanes() {
  660. const board = Boards.findOne(this.selectedBoardId.get());
  661. return board.swimlanes();
  662. },
  663. aBoardLists() {
  664. const board = Boards.findOne(this.selectedBoardId.get());
  665. return board.lists();
  666. },
  667. events() {
  668. return [
  669. {
  670. 'change .js-select-boards'(event) {
  671. this.selectedBoardId.set($(event.currentTarget).val());
  672. subManager.subscribe('board', this.selectedBoardId.get(), false);
  673. },
  674. },
  675. ];
  676. },
  677. }).register('boardsAndLists');
  678. Template.copyCardPopup.events({
  679. 'click .js-done'() {
  680. const card = Cards.findOne(Session.get('currentCard'));
  681. const lSelect = $('.js-select-lists')[0];
  682. listId = lSelect.options[lSelect.selectedIndex].value;
  683. const slSelect = $('.js-select-swimlanes')[0];
  684. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  685. const bSelect = $('.js-select-boards')[0];
  686. const boardId = bSelect.options[bSelect.selectedIndex].value;
  687. const textarea = $('#copy-card-title');
  688. const title = textarea.val().trim();
  689. // insert new card to the bottom of new list
  690. card.sort = Lists.findOne(card.listId)
  691. .cards()
  692. .count();
  693. if (title) {
  694. card.title = title;
  695. card.coverId = '';
  696. const _id = card.copy(boardId, swimlaneId, listId);
  697. // In case the filter is active we need to add the newly inserted card in
  698. // the list of exceptions -- cards that are not filtered. Otherwise the
  699. // card will disappear instantly.
  700. // See https://github.com/wekan/wekan/issues/80
  701. Filter.addException(_id);
  702. Popup.close();
  703. }
  704. },
  705. });
  706. Template.copyChecklistToManyCardsPopup.events({
  707. 'click .js-done'() {
  708. const card = Cards.findOne(Session.get('currentCard'));
  709. const oldId = card._id;
  710. card._id = null;
  711. const lSelect = $('.js-select-lists')[0];
  712. card.listId = lSelect.options[lSelect.selectedIndex].value;
  713. const slSelect = $('.js-select-swimlanes')[0];
  714. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  715. const bSelect = $('.js-select-boards')[0];
  716. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  717. const textarea = $('#copy-card-title');
  718. const titleEntry = textarea.val().trim();
  719. // insert new card to the bottom of new list
  720. card.sort = Lists.findOne(card.listId)
  721. .cards()
  722. .count();
  723. if (titleEntry) {
  724. const titleList = JSON.parse(titleEntry);
  725. for (let i = 0; i < titleList.length; i++) {
  726. const obj = titleList[i];
  727. card.title = obj.title;
  728. card.description = obj.description;
  729. card.coverId = '';
  730. const _id = Cards.insert(card);
  731. // In case the filter is active we need to add the newly inserted card in
  732. // the list of exceptions -- cards that are not filtered. Otherwise the
  733. // card will disappear instantly.
  734. // See https://github.com/wekan/wekan/issues/80
  735. Filter.addException(_id);
  736. // copy checklists
  737. Checklists.find({ cardId: oldId }).forEach(ch => {
  738. ch.copy(_id);
  739. });
  740. // copy subtasks
  741. cursor = Cards.find({ parentId: oldId });
  742. cursor.forEach(function() {
  743. 'use strict';
  744. const subtask = arguments[0];
  745. subtask.parentId = _id;
  746. subtask._id = null;
  747. /* const newSubtaskId = */ Cards.insert(subtask);
  748. });
  749. // copy card comments
  750. CardComments.find({ cardId: oldId }).forEach(cmt => {
  751. cmt.copy(_id);
  752. });
  753. }
  754. Popup.close();
  755. }
  756. },
  757. });
  758. BlazeComponent.extendComponent({
  759. onCreated() {
  760. this.currentCard = this.currentData();
  761. this.currentColor = new ReactiveVar(this.currentCard.color);
  762. },
  763. colors() {
  764. return cardColors.map(color => ({ color, name: '' }));
  765. },
  766. isSelected(color) {
  767. if (this.currentColor.get() === null) {
  768. return color === 'white';
  769. }
  770. return this.currentColor.get() === color;
  771. },
  772. events() {
  773. return [
  774. {
  775. 'click .js-palette-color'() {
  776. this.currentColor.set(this.currentData().color);
  777. },
  778. 'click .js-submit'() {
  779. this.currentCard.setColor(this.currentColor.get());
  780. Popup.close();
  781. },
  782. 'click .js-remove-color'() {
  783. this.currentCard.setColor(null);
  784. Popup.close();
  785. },
  786. },
  787. ];
  788. },
  789. }).register('setCardColorPopup');
  790. BlazeComponent.extendComponent({
  791. onCreated() {
  792. this.currentCard = this.currentData();
  793. this.parentBoard = new ReactiveVar(null);
  794. this.parentCard = this.currentCard.parentCard();
  795. if (this.parentCard) {
  796. const list = $('.js-field-parent-card');
  797. list.val(this.parentCard._id);
  798. this.parentBoard.set(this.parentCard.board()._id);
  799. } else {
  800. this.parentBoard.set(null);
  801. }
  802. },
  803. boards() {
  804. const boards = Boards.find(
  805. {
  806. archived: false,
  807. 'members.userId': Meteor.userId(),
  808. _id: {
  809. $ne: Meteor.user().getTemplatesBoardId(),
  810. },
  811. },
  812. {
  813. sort: { sort: 1 /* boards default sorting */ },
  814. },
  815. );
  816. return boards;
  817. },
  818. cards() {
  819. const currentId = Session.get('currentCard');
  820. if (this.parentBoard.get()) {
  821. return Cards.find({
  822. boardId: this.parentBoard.get(),
  823. _id: { $ne: currentId },
  824. });
  825. } else {
  826. return [];
  827. }
  828. },
  829. isParentBoard() {
  830. const board = this.currentData();
  831. if (this.parentBoard.get()) {
  832. return board._id === this.parentBoard.get();
  833. }
  834. return false;
  835. },
  836. isParentCard() {
  837. const card = this.currentData();
  838. if (this.parentCard) {
  839. return card._id === this.parentCard;
  840. }
  841. return false;
  842. },
  843. setParentCardId(cardId) {
  844. if (cardId) {
  845. this.parentCard = Cards.findOne(cardId);
  846. } else {
  847. this.parentCard = null;
  848. }
  849. this.currentCard.setParentId(cardId);
  850. },
  851. events() {
  852. return [
  853. {
  854. 'click .js-copy-card-link-to-clipboard'() {
  855. // Clipboard code from:
  856. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  857. const StringToCopyElement = document.getElementById('cardURL');
  858. StringToCopyElement.select();
  859. if (document.execCommand('copy')) {
  860. StringToCopyElement.blur();
  861. } else {
  862. document.getElementById('cardURL').selectionStart = 0;
  863. document.getElementById('cardURL').selectionEnd = 999;
  864. document.execCommand('copy');
  865. if (window.getSelection) {
  866. if (window.getSelection().empty) {
  867. // Chrome
  868. window.getSelection().empty();
  869. } else if (window.getSelection().removeAllRanges) {
  870. // Firefox
  871. window.getSelection().removeAllRanges();
  872. }
  873. } else if (document.selection) {
  874. // IE?
  875. document.selection.empty();
  876. }
  877. }
  878. },
  879. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  880. Popup.close();
  881. // verify that there are no linked cards
  882. if (Cards.find({ linkedId: this._id }).count() === 0) {
  883. Cards.remove(this._id);
  884. } else {
  885. // TODO: Maybe later we can list where the linked cards are.
  886. // Now here is popup with a hint that the card cannot be deleted
  887. // as there are linked cards.
  888. // Related:
  889. // client/components/lists/listHeader.js about line 248
  890. // https://github.com/wekan/wekan/issues/2785
  891. const message = `${TAPi18n.__(
  892. 'delete-linked-card-before-this-card',
  893. )} linkedId: ${
  894. this._id
  895. } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
  896. alert(message);
  897. }
  898. Utils.goBoardId(this.boardId);
  899. }),
  900. 'change .js-field-parent-board'(event) {
  901. const selection = $(event.currentTarget).val();
  902. const list = $('.js-field-parent-card');
  903. if (selection === 'none') {
  904. this.parentBoard.set(null);
  905. } else {
  906. subManager.subscribe('board', $(event.currentTarget).val(), false);
  907. this.parentBoard.set(selection);
  908. list.prop('disabled', false);
  909. }
  910. this.setParentCardId(null);
  911. },
  912. 'change .js-field-parent-card'(event) {
  913. const selection = $(event.currentTarget).val();
  914. this.setParentCardId(selection);
  915. },
  916. },
  917. ];
  918. },
  919. }).register('cardMorePopup');
  920. BlazeComponent.extendComponent({
  921. onCreated() {
  922. this.currentCard = this.currentData();
  923. this.voteQuestion = new ReactiveVar(this.currentCard.voteQuestion);
  924. },
  925. events() {
  926. return [
  927. {
  928. 'click .js-end-date': Popup.open('editVoteEndDate'),
  929. 'submit .edit-vote-question'(evt) {
  930. evt.preventDefault();
  931. const voteQuestion = evt.target.vote.value;
  932. const publicVote = $('#vote-public').hasClass('is-checked');
  933. const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
  934. 'is-checked',
  935. );
  936. const endString = this.currentCard.getVoteEnd();
  937. this.currentCard.setVoteQuestion(
  938. voteQuestion,
  939. publicVote,
  940. allowNonBoardMembers,
  941. );
  942. if (endString) {
  943. this.currentCard.setVoteEnd(endString);
  944. }
  945. Popup.close();
  946. },
  947. 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
  948. event.preventDefault();
  949. this.currentCard.unsetVote();
  950. Popup.close();
  951. }),
  952. 'click a.js-toggle-vote-public'(event) {
  953. event.preventDefault();
  954. $('#vote-public').toggleClass('is-checked');
  955. },
  956. 'click a.js-toggle-vote-allow-non-members'(event) {
  957. event.preventDefault();
  958. $('#vote-allow-non-members').toggleClass('is-checked');
  959. },
  960. },
  961. ];
  962. },
  963. }).register('cardStartVotingPopup');
  964. // editVoteEndDatePopup
  965. (class extends DatePicker {
  966. onCreated() {
  967. super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
  968. this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
  969. }
  970. events() {
  971. return [
  972. {
  973. 'submit .edit-date'(evt) {
  974. evt.preventDefault();
  975. // if no time was given, init with 12:00
  976. const time =
  977. evt.target.time.value ||
  978. moment(new Date().setHours(12, 0, 0)).format('LT');
  979. const dateString = `${evt.target.date.value} ${time}`;
  980. const newDate = moment(dateString, 'L LT', true);
  981. if (newDate.isValid()) {
  982. // if active vote - store it
  983. if (this.currentData().getVoteQuestion()) {
  984. this._storeDate(newDate.toDate());
  985. Popup.close();
  986. } else {
  987. this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
  988. Popup.back();
  989. }
  990. } else {
  991. this.error.set('invalid-date');
  992. evt.target.date.focus();
  993. }
  994. },
  995. 'click .js-delete-date'(evt) {
  996. evt.preventDefault();
  997. this._deleteDate();
  998. Popup.close();
  999. },
  1000. },
  1001. ];
  1002. }
  1003. _storeDate(newDate) {
  1004. this.card.setVoteEnd(newDate);
  1005. }
  1006. _deleteDate() {
  1007. this.card.unsetVoteEnd();
  1008. }
  1009. }.register('editVoteEndDatePopup'));
  1010. // Close the card details pane by pressing escape
  1011. EscapeActions.register(
  1012. 'detailsPane',
  1013. () => {
  1014. if (Session.get('cardDetailsIsDragging')) {
  1015. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  1016. Session.set('cardDetailsIsDragging', false);
  1017. Session.set('cardDetailsIsMouseDown', false);
  1018. } else {
  1019. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  1020. Utils.goBoardId(Session.get('currentBoard'));
  1021. }
  1022. },
  1023. () => {
  1024. return !Session.equals('currentCard', null);
  1025. },
  1026. {
  1027. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  1028. },
  1029. );
  1030. Template.cardAssigneesPopup.events({
  1031. 'click .js-select-assignee'(event) {
  1032. const card = Cards.findOne(Session.get('currentCard'));
  1033. const assigneeId = this.userId;
  1034. card.toggleAssignee(assigneeId);
  1035. event.preventDefault();
  1036. },
  1037. });
  1038. Template.cardAssigneesPopup.helpers({
  1039. isCardAssignee() {
  1040. const card = Template.parentData();
  1041. const cardAssignees = card.getAssignees();
  1042. return _.contains(cardAssignees, this.userId);
  1043. },
  1044. user() {
  1045. return Users.findOne(this.userId);
  1046. },
  1047. });
  1048. Template.cardAssigneePopup.helpers({
  1049. userData() {
  1050. // We need to handle a special case for the search results provided by the
  1051. // `matteodem:easy-search` package. Since these results gets published in a
  1052. // separate collection, and not in the standard Meteor.Users collection as
  1053. // expected, we use a component parameter ("property") to distinguish the
  1054. // two cases.
  1055. const userCollection = this.esSearch ? ESSearchResults : Users;
  1056. return userCollection.findOne(this.userId, {
  1057. fields: {
  1058. profile: 1,
  1059. username: 1,
  1060. },
  1061. });
  1062. },
  1063. memberType() {
  1064. const user = Users.findOne(this.userId);
  1065. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  1066. },
  1067. presenceStatusClassName() {
  1068. const user = Users.findOne(this.userId);
  1069. const userPresence = presences.findOne({ userId: this.userId });
  1070. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  1071. else if (!userPresence) return 'disconnected';
  1072. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  1073. return 'active';
  1074. else return 'idle';
  1075. },
  1076. isCardAssignee() {
  1077. const card = Template.parentData();
  1078. const cardAssignees = card.getAssignees();
  1079. return _.contains(cardAssignees, this.userId);
  1080. },
  1081. user() {
  1082. return Users.findOne(this.userId);
  1083. },
  1084. });
  1085. Template.cardAssigneePopup.events({
  1086. 'click .js-remove-assignee'() {
  1087. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  1088. Popup.close();
  1089. },
  1090. 'click .js-edit-profile': Popup.open('editProfile'),
  1091. });