listHeader.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. let listsColors;
  2. Meteor.startup(() => {
  3. listsColors = Lists.simpleSchema()._schema.color.allowedValues;
  4. });
  5. BlazeComponent.extendComponent({
  6. canSeeAddCard() {
  7. const list = Template.currentData();
  8. return !list.getWipLimit('enabled') || list.getWipLimit('soft') || !this.reachedWipLimit();
  9. },
  10. editTitle(evt) {
  11. evt.preventDefault();
  12. const newTitle = this.childComponents('inlinedForm')[0].getValue().trim();
  13. const list = this.currentData();
  14. if (newTitle) {
  15. list.rename(newTitle.trim());
  16. }
  17. },
  18. isWatching() {
  19. const list = this.currentData();
  20. return list.findWatcher(Meteor.userId());
  21. },
  22. limitToShowCardsCount() {
  23. return Meteor.user().getLimitToShowCardsCount();
  24. },
  25. cardsCount() {
  26. const list = Template.currentData();
  27. let swimlaneId = '';
  28. const boardView = Meteor.user().profile.boardView;
  29. if (boardView === 'board-view-swimlanes')
  30. swimlaneId = this.parentComponent().parentComponent().data()._id;
  31. return list.cards(swimlaneId).count();
  32. },
  33. reachedWipLimit() {
  34. const list = Template.currentData();
  35. return list.getWipLimit('enabled') && list.getWipLimit('value') <= list.cards().count();
  36. },
  37. showCardsCountForList(count) {
  38. const limit = this.limitToShowCardsCount();
  39. return limit > 0 && count > limit;
  40. },
  41. events() {
  42. return [{
  43. 'click .js-open-list-menu': Popup.open('listAction'),
  44. 'click .js-add-card' (evt) {
  45. const listDom = $(evt.target).parents(`#js-list-${this.currentData()._id}`)[0];
  46. const listComponent = BlazeComponent.getComponentForElement(listDom);
  47. listComponent.openForm({
  48. position: 'top',
  49. });
  50. },
  51. 'click .js-unselect-list'() {
  52. Session.set('currentList', null);
  53. },
  54. submit: this.editTitle,
  55. }];
  56. },
  57. }).register('listHeader');
  58. Template.listActionPopup.helpers({
  59. isWipLimitEnabled() {
  60. return Template.currentData().getWipLimit('enabled');
  61. },
  62. isWatching() {
  63. return this.findWatcher(Meteor.userId());
  64. },
  65. });
  66. Template.listActionPopup.events({
  67. 'click .js-list-subscribe' () {},
  68. 'click .js-set-color-list': Popup.open('setListColor'),
  69. 'click .js-select-cards' () {
  70. const cardIds = this.allCards().map((card) => card._id);
  71. MultiSelection.add(cardIds);
  72. Popup.close();
  73. },
  74. 'click .js-toggle-watch-list' () {
  75. const currentList = this;
  76. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  77. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  78. if (!err && ret) Popup.close();
  79. });
  80. },
  81. 'click .js-close-list' (evt) {
  82. evt.preventDefault();
  83. this.archive();
  84. Popup.close();
  85. },
  86. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  87. 'click .js-more': Popup.open('listMore'),
  88. });
  89. BlazeComponent.extendComponent({
  90. applyWipLimit() {
  91. const list = Template.currentData();
  92. const limit = parseInt(Template.instance().$('.wip-limit-value').val(), 10);
  93. if(limit < list.cards().count() && !list.getWipLimit('soft')){
  94. Template.instance().$('.wip-limit-error').click();
  95. } else {
  96. Meteor.call('applyWipLimit', list._id, limit);
  97. Popup.back();
  98. }
  99. },
  100. enableSoftLimit() {
  101. const list = Template.currentData();
  102. if(list.getWipLimit('soft') && list.getWipLimit('value') < list.cards().count()){
  103. list.setWipLimit(list.cards().count());
  104. }
  105. Meteor.call('enableSoftLimit', Template.currentData()._id);
  106. },
  107. enableWipLimit() {
  108. const list = Template.currentData();
  109. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  110. if(!list.getWipLimit('enabled') && list.getWipLimit('value') < list.cards().count()){
  111. list.setWipLimit(list.cards().count());
  112. }
  113. Meteor.call('enableWipLimit', list._id);
  114. },
  115. isWipLimitSoft() {
  116. return Template.currentData().getWipLimit('soft');
  117. },
  118. isWipLimitEnabled() {
  119. return Template.currentData().getWipLimit('enabled');
  120. },
  121. wipLimitValue(){
  122. return Template.currentData().getWipLimit('value');
  123. },
  124. events() {
  125. return [{
  126. 'click .js-enable-wip-limit': this.enableWipLimit,
  127. 'click .wip-limit-apply': this.applyWipLimit,
  128. 'click .wip-limit-error': Popup.open('wipLimitError'),
  129. 'click .materialCheckBox': this.enableSoftLimit,
  130. }];
  131. },
  132. }).register('setWipLimitPopup');
  133. Template.listMorePopup.events({
  134. 'click .js-delete': Popup.afterConfirm('listDelete', function () {
  135. Popup.close();
  136. this.allCards().map((card) => Cards.remove(card._id));
  137. Lists.remove(this._id);
  138. Utils.goBoardId(this.boardId);
  139. }),
  140. });
  141. BlazeComponent.extendComponent({
  142. onCreated() {
  143. this.currentList = this.currentData();
  144. this.currentColor = new ReactiveVar(this.currentList.color);
  145. },
  146. colors() {
  147. return listsColors.map((color) => ({ color, name: '' }));
  148. },
  149. isSelected(color) {
  150. return this.currentColor.get() === color;
  151. },
  152. events() {
  153. return [{
  154. 'click .js-palette-color'() {
  155. this.currentColor.set(this.currentData().color);
  156. },
  157. 'click .js-submit' () {
  158. this.currentList.setColor(this.currentColor.get());
  159. Popup.close();
  160. },
  161. 'click .js-remove-color'() {
  162. this.currentList.setColor(null);
  163. Popup.close();
  164. },
  165. }];
  166. },
  167. }).register('setListColorPopup');