cardDetails.js 29 KB

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