cardDetails.js 30 KB

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