cardDetails.js 32 KB

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