cardDetails.js 32 KB

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