minicard.js 5.6 KB

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