minicard.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Template.cards.events({
  2. // 'click .member': Popup.open('cardMember')
  3. // });
  4. BlazeComponent.extendComponent({
  5. template() {
  6. return 'minicard';
  7. },
  8. formattedCurrencyCustomFieldValue(definition) {
  9. const customField = this.data()
  10. .customFieldsWD()
  11. .find(f => f._id === definition._id);
  12. const customFieldTrueValue =
  13. customField && customField.trueValue ? customField.trueValue : '';
  14. const locale = TAPi18n.getLanguage();
  15. return new Intl.NumberFormat(locale, {
  16. style: 'currency',
  17. currency: definition.settings.currencyCode,
  18. }).format(customFieldTrueValue);
  19. },
  20. formattedStringtemplateCustomFieldValue(definition) {
  21. const customField = this.data()
  22. .customFieldsWD()
  23. .find(f => f._id === definition._id);
  24. const customFieldTrueValue =
  25. customField && customField.trueValue ? customField.trueValue : [];
  26. return customFieldTrueValue
  27. .filter(value => !!value.trim())
  28. .map(value =>
  29. definition.settings.stringtemplateFormat.replace(/%\{value\}/gi, value),
  30. )
  31. .join(definition.settings.stringtemplateSeparator ?? '');
  32. },
  33. showCreator() {
  34. if (this.data().board()) {
  35. return (
  36. this.data().board.allowsCreator === null ||
  37. this.data().board().allowsCreator === undefined ||
  38. this.data().board().allowsCreator
  39. );
  40. // return this.data().board().allowsCreator;
  41. }
  42. return false;
  43. },
  44. showMembers() {
  45. if (this.data().board()) {
  46. return (
  47. this.data().board.allowsMembers === null ||
  48. this.data().board().allowsMembers === undefined ||
  49. this.data().board().allowsMembers
  50. );
  51. }
  52. return false;
  53. },
  54. showAssignee() {
  55. if (this.data().board()) {
  56. return (
  57. this.data().board.allowsAssignee === null ||
  58. this.data().board().allowsAssignee === undefined ||
  59. this.data().board().allowsAssignee
  60. );
  61. }
  62. return false;
  63. },
  64. /** opens the card label popup only if clicked onto a label
  65. * <li> this is necessary to have the data context of the minicard.
  66. * if .js-card-label is used at click event, then only the data context of the label itself is available at this.currentData()
  67. */
  68. cardLabelsPopup(event) {
  69. if (this.find('.js-card-label:hover')) {
  70. Popup.open("cardLabels")(event, {dataContextIfCurrentDataIsUndefined: this.currentData()});
  71. }
  72. },
  73. events() {
  74. return [
  75. {
  76. 'click .js-linked-link'() {
  77. if (this.data().isLinkedCard()) Utils.goCardId(this.data().linkedId);
  78. else if (this.data().isLinkedBoard())
  79. Utils.goBoardId(this.data().linkedId);
  80. },
  81. 'click .js-toggle-minicard-label-text'() {
  82. if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  83. window.localStorage.removeItem('hiddenMinicardLabelText'); //true
  84. } else {
  85. window.localStorage.setItem('hiddenMinicardLabelText', 'true'); //true
  86. }
  87. },
  88. 'click span.badge-icon.fa.fa-sort, click span.badge-text.check-list-sort' : Popup.open("editCardSortOrder"),
  89. 'click .minicard-labels' : this.cardLabelsPopup,
  90. }
  91. ];
  92. },
  93. }).register('minicard');
  94. Template.minicard.helpers({
  95. hiddenMinicardLabelText() {
  96. currentUser = Meteor.user();
  97. if (currentUser) {
  98. return (currentUser.profile || {}).hiddenMinicardLabelText;
  99. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. },
  105. });
  106. BlazeComponent.extendComponent({
  107. events() {
  108. return [
  109. {
  110. 'keydown input.js-edit-card-sort-popup'(evt) {
  111. // enter = save
  112. if (evt.keyCode === 13) {
  113. this.find('button[type=submit]').click();
  114. }
  115. },
  116. 'click button.js-submit-edit-card-sort-popup'(event) {
  117. // save button pressed
  118. event.preventDefault();
  119. const sort = this.$('.js-edit-card-sort-popup')[0]
  120. .value
  121. .trim();
  122. if (!Number.isNaN(sort)) {
  123. let card = this.data();
  124. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  125. Popup.back();
  126. }
  127. },
  128. }
  129. ]
  130. }
  131. }).register('editCardSortOrderPopup');