minicard.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. showMembers() {
  42. // cache "board" to reduce the mini-mongodb access
  43. const board = this.data().board();
  44. let ret = false;
  45. if (board) {
  46. ret =
  47. board.allowsMembers === null ||
  48. board.allowsMembers === undefined ||
  49. board.allowsMembers
  50. ;
  51. }
  52. return ret;
  53. },
  54. showAssignee() {
  55. // cache "board" to reduce the mini-mongodb access
  56. const board = this.data().board();
  57. let ret = false;
  58. if (board) {
  59. ret =
  60. board.allowsAssignee === null ||
  61. board.allowsAssignee === undefined ||
  62. board.allowsAssignee
  63. ;
  64. }
  65. return ret;
  66. },
  67. /** opens the card label popup only if clicked onto a label
  68. * <li> this is necessary to have the data context of the minicard.
  69. * if .js-card-label is used at click event, then only the data context of the label itself is available at this.currentData()
  70. */
  71. cardLabelsPopup(event) {
  72. if (this.find('.js-card-label:hover')) {
  73. Popup.open("cardLabels")(event, {dataContextIfCurrentDataIsUndefined: this.currentData()});
  74. }
  75. },
  76. events() {
  77. return [
  78. {
  79. 'click .js-linked-link'() {
  80. if (this.data().isLinkedCard()) Utils.goCardId(this.data().linkedId);
  81. else if (this.data().isLinkedBoard())
  82. Utils.goBoardId(this.data().linkedId);
  83. },
  84. 'click .js-toggle-minicard-label-text'() {
  85. if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  86. window.localStorage.removeItem('hiddenMinicardLabelText'); //true
  87. } else {
  88. window.localStorage.setItem('hiddenMinicardLabelText', 'true'); //true
  89. }
  90. },
  91. 'click span.badge-icon.fa.fa-sort, click span.badge-text.check-list-sort' : Popup.open("editCardSortOrder"),
  92. 'click .minicard-labels' : this.cardLabelsPopup,
  93. 'click .js-open-minicard-details-menu': Popup.open('minicardDetailsActions'),
  94. }
  95. ];
  96. },
  97. }).register('minicard');
  98. Template.minicard.helpers({
  99. hiddenMinicardLabelText() {
  100. const currentUser = ReactiveCache.getCurrentUser();
  101. if (currentUser) {
  102. return (currentUser.profile || {}).hiddenMinicardLabelText;
  103. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. },
  109. // XXX resolve this nasty hack for https://github.com/veliovgroup/Meteor-Files/issues/763
  110. sess() {
  111. return Meteor.connection && Meteor.connection._lastSessionId
  112. ? Meteor.connection._lastSessionId
  113. : null;
  114. },
  115. });
  116. BlazeComponent.extendComponent({
  117. events() {
  118. return [
  119. {
  120. 'keydown input.js-edit-card-sort-popup'(evt) {
  121. // enter = save
  122. if (evt.keyCode === 13) {
  123. this.find('button[type=submit]').click();
  124. }
  125. },
  126. 'click button.js-submit-edit-card-sort-popup'(event) {
  127. // save button pressed
  128. event.preventDefault();
  129. const sort = this.$('.js-edit-card-sort-popup')[0]
  130. .value
  131. .trim();
  132. if (!Number.isNaN(sort)) {
  133. let card = this.data();
  134. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  135. Popup.back();
  136. }
  137. },
  138. }
  139. ]
  140. }
  141. }).register('editCardSortOrderPopup');
  142. Template.minicardDetailsActionsPopup.events({
  143. 'click .js-due-date': Popup.open('editCardDueDate'),
  144. 'click .js-move-card': Popup.open('moveCard'),
  145. 'click .js-copy-card': Popup.open('copyCard'),
  146. 'click .js-set-card-color': Popup.open('setCardColor'),
  147. 'click .js-add-labels': Popup.open('cardLabels'),
  148. 'click .js-link': Popup.open('linkCard'),
  149. 'click .js-move-card-to-top'(event) {
  150. event.preventDefault();
  151. const minOrder = this.getMinSort();
  152. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  153. Popup.back();
  154. },
  155. 'click .js-move-card-to-bottom'(event) {
  156. event.preventDefault();
  157. const maxOrder = this.getMaxSort();
  158. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  159. Popup.back();
  160. },
  161. 'click .js-archive': Popup.afterConfirm('cardArchive', function () {
  162. Popup.close();
  163. this.archive();
  164. Utils.goBoardId(this.boardId);
  165. }),
  166. });