listHeader.js 4.1 KB

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