2
0

cardDetails.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. BlazeComponent.extendComponent({
  2. mixins() {
  3. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  4. },
  5. calculateNextPeak() {
  6. const cardElement = this.find('.js-card-details');
  7. if (cardElement) {
  8. const altitude = cardElement.scrollHeight;
  9. this.callFirstWith(this, 'setNextPeak', altitude);
  10. }
  11. },
  12. reachNextPeak() {
  13. const activitiesComponent = this.childComponents('activities')[0];
  14. activitiesComponent.loadNextPage();
  15. },
  16. onCreated() {
  17. this.isLoaded = new ReactiveVar(false);
  18. this.parentComponent().showOverlay.set(true);
  19. this.parentComponent().mouseHasEnterCardDetails = false;
  20. this.calculateNextPeak();
  21. },
  22. isWatching() {
  23. const card = this.currentData();
  24. return card.findWatcher(Meteor.userId());
  25. },
  26. hiddenSystemMessages() {
  27. console.log('doo:', Meteor.user().hasHiddenSystemMessages());
  28. return Meteor.user().hasHiddenSystemMessages();
  29. },
  30. canModifyCard() {
  31. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  32. },
  33. scrollParentContainer() {
  34. const cardPanelWidth = 510;
  35. const bodyBoardComponent = this.parentComponent();
  36. const $cardContainer = bodyBoardComponent.$('.js-lists');
  37. const $cardView = this.$(this.firstNode());
  38. const cardContainerScroll = $cardContainer.scrollLeft();
  39. const cardContainerWidth = $cardContainer.width();
  40. const cardViewStart = $cardView.offset().left;
  41. const cardViewEnd = cardViewStart + cardPanelWidth;
  42. let offset = false;
  43. if (cardViewStart < 0) {
  44. offset = cardViewStart;
  45. } else if (cardViewEnd > cardContainerWidth) {
  46. offset = cardViewEnd - cardContainerWidth;
  47. }
  48. if (offset) {
  49. bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
  50. }
  51. },
  52. onRendered() {
  53. if (!Utils.isMiniScreen()) this.scrollParentContainer();
  54. },
  55. onDestroyed() {
  56. this.parentComponent().showOverlay.set(false);
  57. },
  58. events() {
  59. const events = {
  60. [`${CSSEvents.transitionend} .js-card-details`]() {
  61. this.isLoaded.set(true);
  62. },
  63. [`${CSSEvents.animationend} .js-card-details`]() {
  64. this.isLoaded.set(true);
  65. },
  66. };
  67. return [{
  68. ...events,
  69. 'click .js-close-card-details' () {
  70. Utils.goBoardId(this.data().boardId);
  71. },
  72. 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
  73. 'submit .js-card-description' (evt) {
  74. evt.preventDefault();
  75. const description = this.currentComponent().getValue();
  76. this.data().setDescription(description);
  77. },
  78. 'submit .js-card-details-title' (evt) {
  79. evt.preventDefault();
  80. const title = this.currentComponent().getValue().trim();
  81. if (title) {
  82. this.data().setTitle(title);
  83. }
  84. },
  85. 'click .js-member': Popup.open('cardMember'),
  86. 'click .js-add-members': Popup.open('cardMembers'),
  87. 'click .js-add-labels': Popup.open('cardLabels'),
  88. 'mouseenter .js-card-details' () {
  89. this.parentComponent().showOverlay.set(true);
  90. this.parentComponent().mouseHasEnterCardDetails = true;
  91. },
  92. 'click #toggleButton'() {
  93. $('div.activity.js-card-activity:not(:has(.activity-comment))').toggle();
  94. },
  95. }];
  96. },
  97. }).register('cardDetails');
  98. // We extends the normal InlinedForm component to support UnsavedEdits draft
  99. // feature.
  100. (class extends InlinedForm {
  101. _getUnsavedEditKey() {
  102. return {
  103. fieldName: 'cardDescription',
  104. // XXX Recovering the currentCard identifier form a session variable is
  105. // fragile because this variable may change for instance if the route
  106. // change. We should use some component props instead.
  107. docId: Session.get('currentCard'),
  108. };
  109. }
  110. close(isReset = false) {
  111. if (this.isOpen.get() && !isReset) {
  112. const draft = this.getValue().trim();
  113. if (draft !== Cards.findOne(Session.get('currentCard')).description) {
  114. UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
  115. }
  116. }
  117. super.close();
  118. }
  119. reset() {
  120. UnsavedEdits.reset(this._getUnsavedEditKey());
  121. this.close(true);
  122. }
  123. events() {
  124. const parentEvents = InlinedForm.prototype.events()[0];
  125. return [{
  126. ...parentEvents,
  127. 'click .js-close-inlined-form': this.reset,
  128. }];
  129. }
  130. }).register('inlinedCardDescription');
  131. Template.cardDetailsActionsPopup.helpers({
  132. isWatching() {
  133. return this.findWatcher(Meteor.userId());
  134. },
  135. canModifyCard() {
  136. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  137. },
  138. });
  139. Template.cardDetailsActionsPopup.events({
  140. 'click .js-members': Popup.open('cardMembers'),
  141. 'click .js-labels': Popup.open('cardLabels'),
  142. 'click .js-attachments': Popup.open('cardAttachments'),
  143. 'click .js-start-date': Popup.open('editCardStartDate'),
  144. 'click .js-due-date': Popup.open('editCardDueDate'),
  145. 'click .js-move-card': Popup.open('moveCard'),
  146. 'click .js-copy-card': Popup.open('copyCard'),
  147. 'click .js-move-card-to-top' (evt) {
  148. evt.preventDefault();
  149. const minOrder = _.min(this.list().cards().map((c) => c.sort));
  150. this.move(this.listId, minOrder - 1);
  151. },
  152. 'click .js-move-card-to-bottom' (evt) {
  153. evt.preventDefault();
  154. const maxOrder = _.max(this.list().cards().map((c) => c.sort));
  155. this.move(this.listId, maxOrder + 1);
  156. },
  157. 'click .js-archive' (evt) {
  158. evt.preventDefault();
  159. this.archive();
  160. Popup.close();
  161. },
  162. 'click .js-more': Popup.open('cardMore'),
  163. 'click .js-toggle-watch-card' () {
  164. const currentCard = this;
  165. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  166. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  167. if (!err && ret) Popup.close();
  168. });
  169. },
  170. });
  171. Template.editCardTitleForm.onRendered(function () {
  172. autosize(this.$('.js-edit-card-title'));
  173. });
  174. Template.editCardTitleForm.events({
  175. 'keydown .js-edit-card-title' (evt) {
  176. // If enter key was pressed, submit the data
  177. if (evt.keyCode === 13) {
  178. $('.js-submit-edit-card-title-form').click();
  179. }
  180. },
  181. });
  182. Template.moveCardPopup.events({
  183. 'click .js-select-list' () {
  184. // XXX We should *not* get the currentCard from the global state, but
  185. // instead from a “component” state.
  186. const card = Cards.findOne(Session.get('currentCard'));
  187. const newListId = this._id;
  188. card.move(newListId);
  189. Popup.close();
  190. },
  191. });
  192. Template.copyCardPopup.events({
  193. 'click .js-select-list' (evt) {
  194. const card = Cards.findOne(Session.get('currentCard'));
  195. const oldId = card._id;
  196. card._id = null;
  197. card.listId = this._id;
  198. const textarea = $(evt.currentTarget).parents('.content').find('textarea');
  199. const title = textarea.val().trim();
  200. // insert new card to the bottom of new list
  201. card.sort = Lists.findOne(this._id).cards().count();
  202. if (title) {
  203. card.title = title;
  204. const _id = Cards.insert(card);
  205. // In case the filter is active we need to add the newly inserted card in
  206. // the list of exceptions -- cards that are not filtered. Otherwise the
  207. // card will disappear instantly.
  208. // See https://github.com/wekan/wekan/issues/80
  209. Filter.addException(_id);
  210. // copy checklists
  211. let cursor = Checklists.find({cardId: oldId});
  212. cursor.forEach(function() {
  213. 'use strict';
  214. const checklist = arguments[0];
  215. checklist.cardId = _id;
  216. checklist._id = null;
  217. Checklists.insert(checklist);
  218. });
  219. // copy card comments
  220. cursor = CardComments.find({cardId: oldId});
  221. cursor.forEach(function () {
  222. 'use strict';
  223. const comment = arguments[0];
  224. comment.cardId = _id;
  225. comment._id = null;
  226. CardComments.insert(comment);
  227. });
  228. Popup.close();
  229. }
  230. },
  231. });
  232. Template.cardMorePopup.events({
  233. 'click .js-copy-card-link-to-clipboard' () {
  234. // Clipboard code from:
  235. // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
  236. const StringToCopyElement = document.getElementById('cardURL');
  237. StringToCopyElement.select();
  238. if (document.execCommand('copy')) {
  239. StringToCopyElement.blur();
  240. } else {
  241. document.getElementById('cardURL').selectionStart = 0;
  242. document.getElementById('cardURL').selectionEnd = 999;
  243. document.execCommand('copy');
  244. if (window.getSelection) {
  245. if (window.getSelection().empty) { // Chrome
  246. window.getSelection().empty();
  247. } else if (window.getSelection().removeAllRanges) { // Firefox
  248. window.getSelection().removeAllRanges();
  249. }
  250. } else if (document.selection) { // IE?
  251. document.selection.empty();
  252. }
  253. }
  254. },
  255. 'click .js-delete': Popup.afterConfirm('cardDelete', function () {
  256. Popup.close();
  257. Cards.remove(this._id);
  258. Utils.goBoardId(this.boardId);
  259. }),
  260. });
  261. // Close the card details pane by pressing escape
  262. EscapeActions.register('detailsPane',
  263. () => {
  264. Utils.goBoardId(Session.get('currentBoard'));
  265. },
  266. () => {
  267. return !Session.equals('currentCard', null);
  268. }, {
  269. noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
  270. }
  271. );