listHeader.js 3.4 KB

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