cardDetails.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. if ($checklistsDom.data('sortable')) {
  225. $checklistsDom.sortable('option', 'disabled', Utils.isMiniScreen());
  226. }
  227. if ($subtasksDom.data('sortable')) {
  228. $subtasksDom.sortable('option', 'disabled', Utils.isMiniScreen());
  229. }
  230. });
  231. },
  232. onDestroyed() {
  233. const parentComponent = this.parentComponent().parentComponent();
  234. //on mobile view parent is Board, not board body.
  235. if (parentComponent === null) return;
  236. parentComponent.showOverlay.set(false);
  237. },
  238. events() {
  239. const events = {
  240. [`${CSSEvents.transitionend} .js-card-details`]() {
  241. this.isLoaded.set(true);
  242. },
  243. [`${CSSEvents.animationend} .js-card-details`]() {
  244. this.isLoaded.set(true);
  245. },
  246. };
  247. return [
  248. {
  249. ...events,
  250. 'click .js-close-card-details'() {
  251. Utils.goBoardId(this.data().boardId);
  252. },
  253. 'click .js-copy-link'() {
  254. StringToCopyElement = document.getElementById('cardURL_copy');
  255. StringToCopyElement.select();
  256. if (document.execCommand('copy')) {
  257. StringToCopyElement.blur();
  258. } else {
  259. document.getElementById('cardURL_copy').selectionStart = 0;
  260. document.getElementById('cardURL_copy').selectionEnd = 999;
  261. document.execCommand('copy');
  262. if (window.getSelection) {
  263. if (window.getSelection().empty) {
  264. // Chrome
  265. window.getSelection().empty();
  266. } else if (window.getSelection().removeAllRanges) {
  267. // Firefox
  268. window.getSelection().removeAllRanges();
  269. }
  270. } else if (document.selection) {
  271. // IE?
  272. document.selection.empty();
  273. }
  274. }
  275. },
  276. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  277. 'submit .js-card-description'(event) {
  278. event.preventDefault();
  279. const description = this.currentComponent().getValue();
  280. this.data().setDescription(description);
  281. },
  282. 'submit .js-card-details-title'(event) {
  283. event.preventDefault();
  284. const title = this.currentComponent()
  285. .getValue()
  286. .trim();
  287. if (title) {
  288. this.data().setTitle(title);
  289. } else {
  290. this.data().setTitle('');
  291. }
  292. },
  293. 'submit .js-card-details-assigner'(event) {
  294. event.preventDefault();
  295. const assigner = this.currentComponent()
  296. .getValue()
  297. .trim();
  298. if (assigner) {
  299. this.data().setAssignedBy(assigner);
  300. } else {
  301. this.data().setAssignedBy('');
  302. }
  303. },
  304. 'submit .js-card-details-requester'(event) {
  305. event.preventDefault();
  306. const requester = this.currentComponent()
  307. .getValue()
  308. .trim();
  309. if (requester) {
  310. this.data().setRequestedBy(requester);
  311. } else {
  312. this.data().setRequestedBy('');
  313. }
  314. },
  315. 'click .js-member': Popup.open('cardMember'),
  316. 'click .js-add-members': Popup.open('cardMembers'),
  317. 'click .js-assignee': Popup.open('cardAssignee'),
  318. 'click .js-add-assignees': Popup.open('cardAssignees'),
  319. 'click .js-add-labels': Popup.open('cardLabels'),
  320. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  321. 'click .js-start-date': Popup.open('editCardStartDate'),
  322. 'click .js-due-date': Popup.open('editCardDueDate'),
  323. 'click .js-end-date': Popup.open('editCardEndDate'),
  324. 'mouseenter .js-card-details'() {
  325. const parentComponent = this.parentComponent().parentComponent();
  326. //on mobile view parent is Board, not BoardBody.
  327. if (parentComponent === null) return;
  328. parentComponent.showOverlay.set(true);
  329. parentComponent.mouseHasEnterCardDetails = true;
  330. },
  331. 'mousedown .js-card-details'() {
  332. Session.set('cardDetailsIsDragging', false);
  333. Session.set('cardDetailsIsMouseDown', true);
  334. },
  335. 'mousemove .js-card-details'() {
  336. if (Session.get('cardDetailsIsMouseDown')) {
  337. Session.set('cardDetailsIsDragging', true);
  338. }
  339. },
  340. 'mouseup .js-card-details'() {
  341. Session.set('cardDetailsIsDragging', false);
  342. Session.set('cardDetailsIsMouseDown', false);
  343. },
  344. 'click #toggleButton'() {
  345. Meteor.call('toggleSystemMessages');
  346. },
  347. },
  348. ];
  349. },
  350. }).register('cardDetails');
  351. Template.cardDetails.helpers({
  352. userData() {
  353. // We need to handle a special case for the search results provided by the
  354. // `matteodem:easy-search` package. Since these results gets published in a
  355. // separate collection, and not in the standard Meteor.Users collection as
  356. // expected, we use a component parameter ("property") to distinguish the
  357. // two cases.
  358. const userCollection = this.esSearch ? ESSearchResults : Users;
  359. return userCollection.findOne(this.userId, {
  360. fields: {
  361. profile: 1,
  362. username: 1,
  363. },
  364. });
  365. },
  366. receivedSelected() {
  367. if (this.getReceived().length === 0) {
  368. return false;
  369. } else {
  370. return true;
  371. }
  372. },
  373. startSelected() {
  374. if (this.getStart().length === 0) {
  375. return false;
  376. } else {
  377. return true;
  378. }
  379. },
  380. endSelected() {
  381. if (this.getEnd().length === 0) {
  382. return false;
  383. } else {
  384. return true;
  385. }
  386. },
  387. dueSelected() {
  388. if (this.getDue().length === 0) {
  389. return false;
  390. } else {
  391. return true;
  392. }
  393. },
  394. memberSelected() {
  395. if (this.getMembers().length === 0) {
  396. return false;
  397. } else {
  398. return true;
  399. }
  400. },
  401. labelSelected() {
  402. if (this.getLabels().length === 0) {
  403. return false;
  404. } else {
  405. return true;
  406. }
  407. },
  408. assigneeSelected() {
  409. if (this.getAssignees().length === 0) {
  410. return false;
  411. } else {
  412. return true;
  413. }
  414. },
  415. requestBySelected() {
  416. if (this.getRequestBy().length === 0) {
  417. return false;
  418. } else {
  419. return true;
  420. }
  421. },
  422. assigneeBySelected() {
  423. if (this.getAssigneeBy().length === 0) {
  424. return false;
  425. } else {
  426. return true;
  427. }
  428. },
  429. memberType() {
  430. const user = Users.findOne(this.userId);
  431. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  432. },
  433. presenceStatusClassName() {
  434. const user = Users.findOne(this.userId);
  435. const userPresence = presences.findOne({ userId: this.userId });
  436. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  437. else if (!userPresence) return 'disconnected';
  438. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  439. return 'active';
  440. else return 'idle';
  441. },
  442. });
  443. Template.userAvatarAssigneeInitials.helpers({
  444. initials() {
  445. const user = Users.findOne(this.userId);
  446. return user && user.getInitials();
  447. },
  448. viewPortWidth() {
  449. const user = Users.findOne(this.userId);
  450. return ((user && user.getInitials().length) || 1) * 12;
  451. },
  452. });
  453. // We extends the normal InlinedForm component to support UnsavedEdits draft
  454. // feature.
  455. (class extends InlinedForm {
  456. _getUnsavedEditKey() {
  457. return {
  458. fieldName: 'cardDescription',
  459. // XXX Recovering the currentCard identifier form a session variable is
  460. // fragile because this variable may change for instance if the route
  461. // change. We should use some component props instead.
  462. docId: Session.get('currentCard'),
  463. };
  464. }
  465. close(isReset = false) {
  466. if (this.isOpen.get() && !isReset) {
  467. const draft = this.getValue().trim();
  468. if (
  469. draft !== Cards.findOne(Session.get('currentCard')).getDescription()
  470. ) {
  471. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  472. }
  473. }
  474. super.close();
  475. }
  476. reset() {
  477. UnsavedEdits.reset(this._getUnsavedEditKey());
  478. this.close(true);
  479. }
  480. events() {
  481. const parentEvents = InlinedForm.prototype.events()[0];
  482. return [
  483. {
  484. ...parentEvents,
  485. 'click .js-close-inlined-form': this.reset,
  486. },
  487. ];
  488. }
  489. }.register('inlinedCardDescription'));
  490. Template.cardDetailsActionsPopup.helpers({
  491. isWatching() {
  492. return this.findWatcher(Meteor.userId());
  493. },
  494. canModifyCard() {
  495. return (
  496. Meteor.user() &&
  497. Meteor.user().isBoardMember() &&
  498. !Meteor.user().isCommentOnly()
  499. );
  500. },
  501. });
  502. Template.cardDetailsActionsPopup.events({
  503. 'click .js-members': Popup.open('cardMembers'),
  504. 'click .js-assignees': Popup.open('cardAssignees'),
  505. 'click .js-labels': Popup.open('cardLabels'),
  506. 'click .js-attachments': Popup.open('cardAttachments'),
  507. 'click .js-custom-fields': Popup.open('cardCustomFields'),
  508. 'click .js-received-date': Popup.open('editCardReceivedDate'),
  509. 'click .js-start-date': Popup.open('editCardStartDate'),
  510. 'click .js-due-date': Popup.open('editCardDueDate'),
  511. 'click .js-end-date': Popup.open('editCardEndDate'),
  512. 'click .js-spent-time': Popup.open('editCardSpentTime'),
  513. 'click .js-move-card': Popup.open('moveCard'),
  514. 'click .js-copy-card': Popup.open('copyCard'),
  515. 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
  516. 'click .js-set-card-color': Popup.open('setCardColor'),
  517. 'click .js-move-card-to-top'(event) {
  518. event.preventDefault();
  519. const minOrder = _.min(
  520. this.list()
  521. .cards(this.swimlaneId)
  522. .map(c => c.sort),
  523. );
  524. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  525. },
  526. 'click .js-move-card-to-bottom'(event) {
  527. event.preventDefault();
  528. const maxOrder = _.max(
  529. this.list()
  530. .cards(this.swimlaneId)
  531. .map(c => c.sort),
  532. );
  533. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  534. },
  535. 'click .js-archive'(event) {
  536. event.preventDefault();
  537. this.archive();
  538. Popup.close();
  539. },
  540. 'click .js-more': Popup.open('cardMore'),
  541. 'click .js-toggle-watch-card'() {
  542. const currentCard = this;
  543. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  544. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  545. if (!err && ret) Popup.close();
  546. });
  547. },
  548. });
  549. Template.editCardTitleForm.onRendered(function() {
  550. autosize(this.$('.js-edit-card-title'));
  551. });
  552. Template.editCardTitleForm.events({
  553. 'keydown .js-edit-card-title'(event) {
  554. // If enter key was pressed, submit the data
  555. // Unless the shift key is also being pressed
  556. if (event.keyCode === 13 && !event.shiftKey) {
  557. $('.js-submit-edit-card-title-form').click();
  558. }
  559. },
  560. });
  561. Template.editCardRequesterForm.onRendered(function() {
  562. autosize(this.$('.js-edit-card-requester'));
  563. });
  564. Template.editCardRequesterForm.events({
  565. 'keydown .js-edit-card-requester'(event) {
  566. // If enter key was pressed, submit the data
  567. if (event.keyCode === 13) {
  568. $('.js-submit-edit-card-requester-form').click();
  569. }
  570. },
  571. });
  572. Template.editCardAssignerForm.onRendered(function() {
  573. autosize(this.$('.js-edit-card-assigner'));
  574. });
  575. Template.editCardAssignerForm.events({
  576. 'keydown .js-edit-card-assigner'(event) {
  577. // If enter key was pressed, submit the data
  578. if (event.keyCode === 13) {
  579. $('.js-submit-edit-card-assigner-form').click();
  580. }
  581. },
  582. });
  583. Template.moveCardPopup.events({
  584. 'click .js-done'() {
  585. // XXX We should *not* get the currentCard from the global state, but
  586. // instead from a “component” state.
  587. const card = Cards.findOne(Session.get('currentCard'));
  588. const bSelect = $('.js-select-boards')[0];
  589. const boardId = bSelect.options[bSelect.selectedIndex].value;
  590. const lSelect = $('.js-select-lists')[0];
  591. const listId = lSelect.options[lSelect.selectedIndex].value;
  592. const slSelect = $('.js-select-swimlanes')[0];
  593. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  594. card.move(boardId, swimlaneId, listId, 0);
  595. Popup.close();
  596. },
  597. });
  598. BlazeComponent.extendComponent({
  599. onCreated() {
  600. subManager.subscribe('board', Session.get('currentBoard'), false);
  601. this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
  602. },
  603. boards() {
  604. const boards = Boards.find(
  605. {
  606. archived: false,
  607. 'members.userId': Meteor.userId(),
  608. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  609. },
  610. {
  611. sort: ['title'],
  612. },
  613. );
  614. return boards;
  615. },
  616. swimlanes() {
  617. const board = Boards.findOne(this.selectedBoardId.get());
  618. return board.swimlanes();
  619. },
  620. aBoardLists() {
  621. const board = Boards.findOne(this.selectedBoardId.get());
  622. return board.lists();
  623. },
  624. events() {
  625. return [
  626. {
  627. 'change .js-select-boards'(event) {
  628. this.selectedBoardId.set($(event.currentTarget).val());
  629. subManager.subscribe('board', this.selectedBoardId.get(), false);
  630. },
  631. },
  632. ];
  633. },
  634. }).register('boardsAndLists');
  635. Template.copyCardPopup.events({
  636. 'click .js-done'() {
  637. const card = Cards.findOne(Session.get('currentCard'));
  638. const lSelect = $('.js-select-lists')[0];
  639. listId = lSelect.options[lSelect.selectedIndex].value;
  640. const slSelect = $('.js-select-swimlanes')[0];
  641. const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  642. const bSelect = $('.js-select-boards')[0];
  643. const boardId = bSelect.options[bSelect.selectedIndex].value;
  644. const textarea = $('#copy-card-title');
  645. const title = textarea.val().trim();
  646. // insert new card to the bottom of new list
  647. card.sort = Lists.findOne(card.listId)
  648. .cards()
  649. .count();
  650. if (title) {
  651. card.title = title;
  652. card.coverId = '';
  653. const _id = card.copy(boardId, swimlaneId, listId);
  654. // In case the filter is active we need to add the newly inserted card in
  655. // the list of exceptions -- cards that are not filtered. Otherwise the
  656. // card will disappear instantly.
  657. // See https://github.com/wekan/wekan/issues/80
  658. Filter.addException(_id);
  659. Popup.close();
  660. }
  661. },
  662. });
  663. Template.copyChecklistToManyCardsPopup.events({
  664. 'click .js-done'() {
  665. const card = Cards.findOne(Session.get('currentCard'));
  666. const oldId = card._id;
  667. card._id = null;
  668. const lSelect = $('.js-select-lists')[0];
  669. card.listId = lSelect.options[lSelect.selectedIndex].value;
  670. const slSelect = $('.js-select-swimlanes')[0];
  671. card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
  672. const bSelect = $('.js-select-boards')[0];
  673. card.boardId = bSelect.options[bSelect.selectedIndex].value;
  674. const textarea = $('#copy-card-title');
  675. const titleEntry = textarea.val().trim();
  676. // insert new card to the bottom of new list
  677. card.sort = Lists.findOne(card.listId)
  678. .cards()
  679. .count();
  680. if (titleEntry) {
  681. const titleList = JSON.parse(titleEntry);
  682. for (let i = 0; i < titleList.length; i++) {
  683. const obj = titleList[i];
  684. card.title = obj.title;
  685. card.description = obj.description;
  686. card.coverId = '';
  687. const _id = Cards.insert(card);
  688. // In case the filter is active we need to add the newly inserted card in
  689. // the list of exceptions -- cards that are not filtered. Otherwise the
  690. // card will disappear instantly.
  691. // See https://github.com/wekan/wekan/issues/80
  692. Filter.addException(_id);
  693. // copy checklists
  694. Checklists.find({ cardId: oldId }).forEach(ch => {
  695. ch.copy(_id);
  696. });
  697. // copy subtasks
  698. cursor = Cards.find({ parentId: oldId });
  699. cursor.forEach(function() {
  700. 'use strict';
  701. const subtask = arguments[0];
  702. subtask.parentId = _id;
  703. subtask._id = null;
  704. /* const newSubtaskId = */ Cards.insert(subtask);
  705. });
  706. // copy card comments
  707. CardComments.find({ cardId: oldId }).forEach(cmt => {
  708. cmt.copy(_id);
  709. });
  710. }
  711. Popup.close();
  712. }
  713. },
  714. });
  715. BlazeComponent.extendComponent({
  716. onCreated() {
  717. this.currentCard = this.currentData();
  718. this.currentColor = new ReactiveVar(this.currentCard.color);
  719. },
  720. colors() {
  721. return cardColors.map(color => ({ color, name: '' }));
  722. },
  723. isSelected(color) {
  724. if (this.currentColor.get() === null) {
  725. return color === 'white';
  726. }
  727. return this.currentColor.get() === color;
  728. },
  729. events() {
  730. return [
  731. {
  732. 'click .js-palette-color'() {
  733. this.currentColor.set(this.currentData().color);
  734. },
  735. 'click .js-submit'() {
  736. this.currentCard.setColor(this.currentColor.get());
  737. Popup.close();
  738. },
  739. 'click .js-remove-color'() {
  740. this.currentCard.setColor(null);
  741. Popup.close();
  742. },
  743. },
  744. ];
  745. },
  746. }).register('setCardColorPopup');
  747. BlazeComponent.extendComponent({
  748. onCreated() {
  749. this.currentCard = this.currentData();
  750. this.parentBoard = new ReactiveVar(null);
  751. this.parentCard = this.currentCard.parentCard();
  752. if (this.parentCard) {
  753. const list = $('.js-field-parent-card');
  754. list.val(this.parentCard._id);
  755. this.parentBoard.set(this.parentCard.board()._id);
  756. } else {
  757. this.parentBoard.set(null);
  758. }
  759. },
  760. boards() {
  761. const boards = Boards.find(
  762. {
  763. archived: false,
  764. 'members.userId': Meteor.userId(),
  765. _id: {
  766. $ne: Meteor.user().getTemplatesBoardId(),
  767. },
  768. },
  769. {
  770. sort: ['title'],
  771. },
  772. );
  773. return boards;
  774. },
  775. cards() {
  776. const currentId = Session.get('currentCard');
  777. if (this.parentBoard.get()) {
  778. return Cards.find({
  779. boardId: this.parentBoard.get(),
  780. _id: { $ne: currentId },
  781. });
  782. } else {
  783. return [];
  784. }
  785. },
  786. isParentBoard() {
  787. const board = this.currentData();
  788. if (this.parentBoard.get()) {
  789. return board._id === this.parentBoard.get();
  790. }
  791. return false;
  792. },
  793. isParentCard() {
  794. const card = this.currentData();
  795. if (this.parentCard) {
  796. return card._id === this.parentCard;
  797. }
  798. return false;
  799. },
  800. setParentCardId(cardId) {
  801. if (cardId) {
  802. this.parentCard = Cards.findOne(cardId);
  803. } else {
  804. this.parentCard = null;
  805. }
  806. this.currentCard.setParentId(cardId);
  807. },
  808. events() {
  809. return [
  810. {
  811. 'click .js-copy-card-link-to-clipboard'() {
  812. // Clipboard code from:
  813. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  814. const StringToCopyElement = document.getElementById('cardURL');
  815. StringToCopyElement.select();
  816. if (document.execCommand('copy')) {
  817. StringToCopyElement.blur();
  818. } else {
  819. document.getElementById('cardURL').selectionStart = 0;
  820. document.getElementById('cardURL').selectionEnd = 999;
  821. document.execCommand('copy');
  822. if (window.getSelection) {
  823. if (window.getSelection().empty) {
  824. // Chrome
  825. window.getSelection().empty();
  826. } else if (window.getSelection().removeAllRanges) {
  827. // Firefox
  828. window.getSelection().removeAllRanges();
  829. }
  830. } else if (document.selection) {
  831. // IE?
  832. document.selection.empty();
  833. }
  834. }
  835. },
  836. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  837. Popup.close();
  838. Cards.remove(this._id);
  839. Utils.goBoardId(this.boardId);
  840. }),
  841. 'change .js-field-parent-board'(event) {
  842. const selection = $(event.currentTarget).val();
  843. const list = $('.js-field-parent-card');
  844. if (selection === 'none') {
  845. this.parentBoard.set(null);
  846. } else {
  847. subManager.subscribe('board', $(event.currentTarget).val(), false);
  848. this.parentBoard.set(selection);
  849. list.prop('disabled', false);
  850. }
  851. this.setParentCardId(null);
  852. },
  853. 'change .js-field-parent-card'(event) {
  854. const selection = $(event.currentTarget).val();
  855. this.setParentCardId(selection);
  856. },
  857. },
  858. ];
  859. },
  860. }).register('cardMorePopup');
  861. // Close the card details pane by pressing escape
  862. EscapeActions.register(
  863. 'detailsPane',
  864. () => {
  865. if (Session.get('cardDetailsIsDragging')) {
  866. // Reset dragging status as the mouse landed outside the cardDetails template area and this will prevent a mousedown event from firing
  867. Session.set('cardDetailsIsDragging', false);
  868. Session.set('cardDetailsIsMouseDown', false);
  869. } else {
  870. // Prevent close card when the user is selecting text and moves the mouse cursor outside the card detail area
  871. Utils.goBoardId(Session.get('currentBoard'));
  872. }
  873. },
  874. () => {
  875. return !Session.equals('currentCard', null);
  876. },
  877. {
  878. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  879. },
  880. );
  881. Template.cardAssigneesPopup.events({
  882. 'click .js-select-assignee'(event) {
  883. const card = Cards.findOne(Session.get('currentCard'));
  884. const assigneeId = this.userId;
  885. card.toggleAssignee(assigneeId);
  886. event.preventDefault();
  887. },
  888. });
  889. Template.cardAssigneesPopup.helpers({
  890. isCardAssignee() {
  891. const card = Template.parentData();
  892. const cardAssignees = card.getAssignees();
  893. return _.contains(cardAssignees, this.userId);
  894. },
  895. user() {
  896. return Users.findOne(this.userId);
  897. },
  898. });
  899. Template.cardAssigneePopup.helpers({
  900. userData() {
  901. // We need to handle a special case for the search results provided by the
  902. // `matteodem:easy-search` package. Since these results gets published in a
  903. // separate collection, and not in the standard Meteor.Users collection as
  904. // expected, we use a component parameter ("property") to distinguish the
  905. // two cases.
  906. const userCollection = this.esSearch ? ESSearchResults : Users;
  907. return userCollection.findOne(this.userId, {
  908. fields: {
  909. profile: 1,
  910. username: 1,
  911. },
  912. });
  913. },
  914. memberType() {
  915. const user = Users.findOne(this.userId);
  916. return user && user.isBoardAdmin() ? 'admin' : 'normal';
  917. },
  918. presenceStatusClassName() {
  919. const user = Users.findOne(this.userId);
  920. const userPresence = presences.findOne({ userId: this.userId });
  921. if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
  922. else if (!userPresence) return 'disconnected';
  923. else if (Session.equals('currentBoard', userPresence.state.currentBoardId))
  924. return 'active';
  925. else return 'idle';
  926. },
  927. isCardAssignee() {
  928. const card = Template.parentData();
  929. const cardAssignees = card.getAssignees();
  930. return _.contains(cardAssignees, this.userId);
  931. },
  932. user() {
  933. return Users.findOne(this.userId);
  934. },
  935. });
  936. Template.cardAssigneePopup.events({
  937. 'click .js-remove-assignee'() {
  938. Cards.findOne(this.cardId).unassignAssignee(this.userId);
  939. Popup.close();
  940. },
  941. 'click .js-edit-profile': Popup.open('editProfile'),
  942. });