minicard.js 5.5 KB

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