2
0

minicard.js 4.4 KB

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