minicard.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. 'click .js-open-minicard-details-menu': Popup.open('minicardDetailsActions'),
  89. }
  90. ];
  91. },
  92. }).register('minicard');
  93. Template.minicard.helpers({
  94. hiddenMinicardLabelText() {
  95. currentUser = Meteor.user();
  96. if (currentUser) {
  97. return (currentUser.profile || {}).hiddenMinicardLabelText;
  98. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. },
  104. // XXX resolve this nasty hack for https://github.com/veliovgroup/Meteor-Files/issues/763
  105. sess() {
  106. return Meteor.connection && Meteor.connection._lastSessionId
  107. ? Meteor.connection._lastSessionId
  108. : null;
  109. },
  110. });
  111. BlazeComponent.extendComponent({
  112. events() {
  113. return [
  114. {
  115. 'keydown input.js-edit-card-sort-popup'(evt) {
  116. // enter = save
  117. if (evt.keyCode === 13) {
  118. this.find('button[type=submit]').click();
  119. }
  120. },
  121. 'click button.js-submit-edit-card-sort-popup'(event) {
  122. // save button pressed
  123. event.preventDefault();
  124. const sort = this.$('.js-edit-card-sort-popup')[0]
  125. .value
  126. .trim();
  127. if (!Number.isNaN(sort)) {
  128. let card = this.data();
  129. card.move(card.boardId, card.swimlaneId, card.listId, sort);
  130. Popup.back();
  131. }
  132. },
  133. }
  134. ]
  135. }
  136. }).register('editCardSortOrderPopup');
  137. Template.minicardDetailsActionsPopup.events({
  138. 'click .js-due-date': Popup.open('editCardDueDate'),
  139. 'click .js-move-card': Popup.open('moveCard'),
  140. 'click .js-copy-card': Popup.open('copyCard'),
  141. 'click .js-set-card-color': Popup.open('setCardColor'),
  142. 'click .js-add-labels': Popup.open('cardLabels'),
  143. 'click .js-link': Popup.open('linkCard'),
  144. 'click .js-move-card-to-top'(event) {
  145. event.preventDefault();
  146. const minOrder = this.getMinSort();
  147. this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
  148. Popup.back();
  149. },
  150. 'click .js-move-card-to-bottom'(event) {
  151. event.preventDefault();
  152. const maxOrder = this.getMaxSort();
  153. this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
  154. Popup.back();
  155. },
  156. 'click .js-archive': Popup.afterConfirm('cardArchive', function () {
  157. Popup.close();
  158. this.archive();
  159. Utils.goBoardId(this.boardId);
  160. }),
  161. });