minicard.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import { CustomFieldStringTemplate } from '/client/lib/customFields'
  4. // Template.cards.events({
  5. // 'click .member': Popup.open('cardMember')
  6. // });
  7. BlazeComponent.extendComponent({
  8. template() {
  9. return 'minicard';
  10. },
  11. formattedCurrencyCustomFieldValue(definition) {
  12. const customField = this.data()
  13. .customFieldsWD()
  14. .find(f => f._id === definition._id);
  15. const customFieldTrueValue =
  16. customField && customField.trueValue ? customField.trueValue : '';
  17. const locale = TAPi18n.getLanguage();
  18. return new Intl.NumberFormat(locale, {
  19. style: 'currency',
  20. currency: definition.settings.currencyCode,
  21. }).format(customFieldTrueValue);
  22. },
  23. formattedStringtemplateCustomFieldValue(definition) {
  24. const customField = this.data()
  25. .customFieldsWD()
  26. .find(f => f._id === definition._id);
  27. const customFieldTrueValue =
  28. customField && customField.trueValue ? customField.trueValue : [];
  29. const ret = new CustomFieldStringTemplate(definition).getFormattedValue(customFieldTrueValue);
  30. return ret;
  31. },
  32. showCreatorOnMinicard() {
  33. // cache "board" to reduce the mini-mongodb access
  34. const board = this.data().board();
  35. let ret = false;
  36. if (board) {
  37. ret = board.allowsCreatorOnMinicard ?? false;
  38. }
  39. return ret;
  40. },
  41. isWatching() {
  42. const card = this.currentData();
  43. return card.findWatcher(Meteor.userId());
  44. },
  45. showMembers() {
  46. // cache "board" to reduce the mini-mongodb access
  47. const board = this.data().board();
  48. let ret = false;
  49. if (board) {
  50. ret =
  51. board.allowsMembers === null ||
  52. board.allowsMembers === undefined ||
  53. board.allowsMembers
  54. ;
  55. }
  56. return ret;
  57. },
  58. showAssignee() {
  59. // cache "board" to reduce the mini-mongodb access
  60. const board = this.data().board();
  61. let ret = false;
  62. if (board) {
  63. ret =
  64. board.allowsAssignee === null ||
  65. board.allowsAssignee === undefined ||
  66. board.allowsAssignee
  67. ;
  68. }
  69. return ret;
  70. },
  71. /** opens the card label popup only if clicked onto a label
  72. * <li> this is necessary to have the data context of the minicard.
  73. * if .js-card-label is used at click event, then only the data context of the label itself is available at this.currentData()
  74. */
  75. cardLabelsPopup(event) {
  76. if (this.find('.js-card-label:hover')) {
  77. Popup.open("cardLabels")(event, {dataContextIfCurrentDataIsUndefined: this.currentData()});
  78. }
  79. },
  80. events() {
  81. return [
  82. {
  83. 'click .js-linked-link'() {
  84. if (this.data().isLinkedCard()) Utils.goCardId(this.data().linkedId);
  85. else if (this.data().isLinkedBoard())
  86. Utils.goBoardId(this.data().linkedId);
  87. },
  88. 'click .js-toggle-minicard-label-text'() {
  89. if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  90. window.localStorage.removeItem('hiddenMinicardLabelText'); //true
  91. } else {
  92. window.localStorage.setItem('hiddenMinicardLabelText', 'true'); //true
  93. }
  94. },
  95. 'click span.badge-icon.fa.fa-sort, click span.badge-text.check-list-sort' : Popup.open("editCardSortOrder"),
  96. 'click .minicard-labels' : this.cardLabelsPopup,
  97. 'click .js-open-minicard-details-menu': Popup.open('minicardDetailsActions'),
  98. }
  99. ];
  100. },
  101. }).register('minicard');
  102. Template.minicard.helpers({
  103. hiddenMinicardLabelText() {
  104. const currentUser = ReactiveCache.getCurrentUser();
  105. if (currentUser) {
  106. return (currentUser.profile || {}).hiddenMinicardLabelText;
  107. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  108. return true;
  109. } else {
  110. return false;
  111. }
  112. },
  113. // XXX resolve this nasty hack for https://github.com/veliovgroup/Meteor-Files/issues/763
  114. sess() {
  115. return Meteor.connection && Meteor.connection._lastSessionId
  116. ? Meteor.connection._lastSessionId
  117. : null;
  118. },
  119. isWatching() {
  120. return this.findWatcher(Meteor.userId());
  121. }
  122. });
  123. BlazeComponent.extendComponent({
  124. events() {
  125. return [
  126. {
  127. 'keydown input.js-edit-card-sort-popup'(evt) {
  128. // enter = save
  129. if (evt.keyCode === 13) {
  130. this.find('button[type=submit]').click();
  131. }
  132. },
  133. 'click button.js-submit-edit-card-sort-popup'(event) {
  134. // save button pressed
  135. event.preventDefault();
  136. const sort = this.$('.js-edit-card-sort-popup')[0]
  137. .value
  138. .trim();
  139. if (!Number.isNaN(sort)) {
  140. let card = this.data();
  141. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  142. Popup.back();
  143. }
  144. },
  145. }
  146. ]
  147. }
  148. }).register('editCardSortOrderPopup');
  149. Template.minicardDetailsActionsPopup.events({
  150. 'click .js-due-date': Popup.open('editCardDueDate'),
  151. 'click .js-move-card': Popup.open('moveCard'),
  152. 'click .js-copy-card': Popup.open('copyCard'),
  153. 'click .js-set-card-color': Popup.open('setCardColor'),
  154. 'click .js-add-labels': Popup.open('cardLabels'),
  155. 'click .js-link': Popup.open('linkCard'),
  156. 'click .js-move-card-to-top'(event) {
  157. event.preventDefault();
  158. const minOrder = this.getMinSort();
  159. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  160. Popup.back();
  161. },
  162. 'click .js-move-card-to-bottom'(event) {
  163. event.preventDefault();
  164. const maxOrder = this.getMaxSort();
  165. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  166. Popup.back();
  167. },
  168. 'click .js-archive': Popup.afterConfirm('cardArchive', function () {
  169. Popup.close();
  170. this.archive();
  171. Utils.goBoardId(this.boardId);
  172. }),
  173. 'click .js-toggle-watch-card'() {
  174. const currentCard = this;
  175. const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
  176. Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
  177. if (!err && ret) Popup.back();
  178. });
  179. },
  180. });