cardDetails.js 32 KB

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