cardDetails.js 28 KB

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