listHeader.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. 'click .js-unselect-list'() {
  39. Session.set('currentList', null);
  40. },
  41. submit: this.editTitle,
  42. }];
  43. },
  44. }).register('listHeader');
  45. Template.listActionPopup.helpers({
  46. isWipLimitEnabled() {
  47. return Template.currentData().getWipLimit('enabled');
  48. },
  49. isWatching() {
  50. return this.findWatcher(Meteor.userId());
  51. },
  52. });
  53. Template.listActionPopup.events({
  54. 'click .js-list-subscribe' () {},
  55. 'click .js-select-cards' () {
  56. const cardIds = this.allCards().map((card) => card._id);
  57. MultiSelection.add(cardIds);
  58. Popup.close();
  59. },
  60. 'click .js-toggle-watch-list' () {
  61. const currentList = this;
  62. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  63. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  64. if (!err && ret) Popup.close();
  65. });
  66. },
  67. 'click .js-close-list' (evt) {
  68. evt.preventDefault();
  69. this.archive();
  70. Popup.close();
  71. },
  72. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  73. 'click .js-more': Popup.open('listMore'),
  74. });
  75. BlazeComponent.extendComponent({
  76. applyWipLimit() {
  77. const list = Template.currentData();
  78. const limit = parseInt(Template.instance().$('.wip-limit-value').val(), 10);
  79. if(limit < list.cards().count() && !list.getWipLimit('soft')){
  80. Template.instance().$('.wip-limit-error').click();
  81. } else {
  82. Meteor.call('applyWipLimit', list._id, limit);
  83. Popup.back();
  84. }
  85. },
  86. enableSoftLimit() {
  87. const list = Template.currentData();
  88. if(list.getWipLimit('soft') && list.getWipLimit('value') < list.cards().count()){
  89. list.setWipLimit(list.cards().count());
  90. }
  91. Meteor.call('enableSoftLimit', Template.currentData()._id);
  92. },
  93. enableWipLimit() {
  94. const list = Template.currentData();
  95. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  96. if(!list.getWipLimit('enabled') && list.getWipLimit('value') < list.cards().count()){
  97. list.setWipLimit(list.cards().count());
  98. }
  99. Meteor.call('enableWipLimit', list._id);
  100. },
  101. isWipLimitSoft() {
  102. return Template.currentData().getWipLimit('soft');
  103. },
  104. isWipLimitEnabled() {
  105. return Template.currentData().getWipLimit('enabled');
  106. },
  107. wipLimitValue(){
  108. return Template.currentData().getWipLimit('value');
  109. },
  110. events() {
  111. return [{
  112. 'click .js-enable-wip-limit': this.enableWipLimit,
  113. 'click .wip-limit-apply': this.applyWipLimit,
  114. 'click .wip-limit-error': Popup.open('wipLimitError'),
  115. 'click .materialCheckBox': this.enableSoftLimit,
  116. }];
  117. },
  118. }).register('setWipLimitPopup');
  119. Template.listMorePopup.events({
  120. 'click .js-delete': Popup.afterConfirm('listDelete', function () {
  121. Popup.close();
  122. this.allCards().map((card) => Cards.remove(card._id));
  123. Lists.remove(this._id);
  124. Utils.goBoardId(this.boardId);
  125. }),
  126. });