minicard.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /** opens the card label popup only if clicked onto a label
  45. * <li> this is necessary to have the data context of the minicard.
  46. * if .js-card-label is used at click event, then only the data context of the label itself is available at this.currentData()
  47. */
  48. cardLabelsPopup(event) {
  49. if (this.find('.js-card-label:hover')) {
  50. Popup.open("cardLabels")(event, {dataContextIfCurrentDataIsUndefined: this.currentData()});
  51. }
  52. },
  53. events() {
  54. return [
  55. {
  56. 'click .js-linked-link'() {
  57. if (this.data().isLinkedCard()) Utils.goCardId(this.data().linkedId);
  58. else if (this.data().isLinkedBoard())
  59. Utils.goBoardId(this.data().linkedId);
  60. },
  61. 'click .js-toggle-minicard-label-text'() {
  62. if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  63. window.localStorage.removeItem('hiddenMinicardLabelText'); //true
  64. } else {
  65. window.localStorage.setItem('hiddenMinicardLabelText', 'true'); //true
  66. }
  67. },
  68. 'click span.badge-icon.fa.fa-sort, click span.badge-text.check-list-sort' : Popup.open("editCardSortOrder"),
  69. 'click .minicard-labels' : this.cardLabelsPopup,
  70. }
  71. ];
  72. },
  73. }).register('minicard');
  74. Template.minicard.helpers({
  75. hiddenMinicardLabelText() {
  76. currentUser = Meteor.user();
  77. if (currentUser) {
  78. return (currentUser.profile || {}).hiddenMinicardLabelText;
  79. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. },
  85. });
  86. BlazeComponent.extendComponent({
  87. events() {
  88. return [
  89. {
  90. 'keydown input.js-edit-card-sort-popup'(evt) {
  91. // enter = save
  92. if (evt.keyCode === 13) {
  93. this.find('button[type=submit]').click();
  94. }
  95. },
  96. 'click button.js-submit-edit-card-sort-popup'(event) {
  97. // save button pressed
  98. event.preventDefault();
  99. const sort = this.$('.js-edit-card-sort-popup')[0]
  100. .value
  101. .trim();
  102. if (!Number.isNaN(sort)) {
  103. let card = this.data();
  104. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  105. Popup.back();
  106. }
  107. },
  108. }
  109. ]
  110. }
  111. }).register('editCardSortOrderPopup');