cardDetails.js 28 KB

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