cardDetails.js 32 KB

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