minicard.js 4.2 KB

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