listHeader.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. BlazeComponent.extendComponent({
  2. canSeeAddCard() {
  3. const list = Template.currentData();
  4. return !list.getWipLimit('enabled') || list.getWipLimit('soft') || !this.reachedWipLimit();
  5. },
  6. editTitle(evt) {
  7. evt.preventDefault();
  8. const newTitle = this.childComponents('inlinedForm')[0].getValue().trim();
  9. const list = this.currentData();
  10. if (newTitle) {
  11. list.rename(newTitle.trim());
  12. }
  13. },
  14. isWatching() {
  15. const list = this.currentData();
  16. return list.findWatcher(Meteor.userId());
  17. },
  18. limitToShowCardsCount() {
  19. return Meteor.user().getLimitToShowCardsCount();
  20. },
  21. reachedWipLimit() {
  22. const list = Template.currentData();
  23. return list.getWipLimit('enabled') && list.getWipLimit('value') <= list.cards().count();
  24. },
  25. showCardsCountForList(count) {
  26. return count > this.limitToShowCardsCount();
  27. },
  28. events() {
  29. return [{
  30. 'click .js-open-list-menu': Popup.open('listAction'),
  31. 'click .js-add-card' () {
  32. const listDom = document.getElementById(`js-list-${this.currentData()._id}`);
  33. const listComponent = BlazeComponent.getComponentForElement(listDom);
  34. listComponent.openForm({
  35. position: 'top',
  36. });
  37. },
  38. submit: this.editTitle,
  39. }];
  40. },
  41. }).register('listHeader');
  42. Template.listActionPopup.helpers({
  43. isWipLimitEnabled() {
  44. return Template.currentData().getWipLimit('enabled');
  45. },
  46. isWatching() {
  47. return this.findWatcher(Meteor.userId());
  48. },
  49. });
  50. Template.listActionPopup.events({
  51. 'click .js-list-subscribe' () {},
  52. 'click .js-select-cards' () {
  53. const cardIds = this.allCards().map((card) => card._id);
  54. MultiSelection.add(cardIds);
  55. Popup.close();
  56. },
  57. 'click .js-toggle-watch-list' () {
  58. const currentList = this;
  59. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  60. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  61. if (!err && ret) Popup.close();
  62. });
  63. },
  64. 'click .js-close-list' (evt) {
  65. evt.preventDefault();
  66. this.archive();
  67. Popup.close();
  68. },
  69. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  70. 'click .js-more': Popup.open('listMore'),
  71. });
  72. BlazeComponent.extendComponent({
  73. applyWipLimit() {
  74. const list = Template.currentData();
  75. const limit = parseInt(Template.instance().$('.wip-limit-value').val(), 10);
  76. if(limit < list.cards().count() && !list.getWipLimit('soft')){
  77. Template.instance().$('.wip-limit-error').click();
  78. } else {
  79. Meteor.call('applyWipLimit', list._id, limit);
  80. Popup.back();
  81. }
  82. },
  83. enableSoftLimit() {
  84. const list = Template.currentData();
  85. if(list.getWipLimit('soft') && list.getWipLimit('value') < list.cards().count()){
  86. list.setWipLimit(list.cards().count());
  87. }
  88. Meteor.call('enableSoftLimit', Template.currentData()._id);
  89. },
  90. enableWipLimit() {
  91. const list = Template.currentData();
  92. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  93. if(!list.getWipLimit('enabled') && list.getWipLimit('value') < list.cards().count()){
  94. list.setWipLimit(list.cards().count());
  95. }
  96. Meteor.call('enableWipLimit', list._id);
  97. },
  98. isWipLimitSoft() {
  99. return Template.currentData().getWipLimit('soft');
  100. },
  101. isWipLimitEnabled() {
  102. return Template.currentData().getWipLimit('enabled');
  103. },
  104. wipLimitValue(){
  105. return Template.currentData().getWipLimit('value');
  106. },
  107. events() {
  108. return [{
  109. 'click .js-enable-wip-limit': this.enableWipLimit,
  110. 'click .wip-limit-apply': this.applyWipLimit,
  111. 'click .wip-limit-error': Popup.open('wipLimitError'),
  112. 'click .materialCheckBox': this.enableSoftLimit,
  113. }];
  114. },
  115. }).register('setWipLimitPopup');
  116. Template.listMorePopup.events({
  117. 'click .js-delete': Popup.afterConfirm('listDelete', function () {
  118. Popup.close();
  119. this.allCards().map((card) => Cards.remove(card._id));
  120. Lists.remove(this._id);
  121. Utils.goBoardId(this.boardId);
  122. }),
  123. });