listHeader.js 4.4 KB

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