listHeader.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 (
  9. !list.getWipLimit('enabled') ||
  10. list.getWipLimit('soft') ||
  11. !this.reachedWipLimit()
  12. );
  13. },
  14. isBoardAdmin() {
  15. return Meteor.user().isBoardAdmin();
  16. },
  17. starred(check = undefined) {
  18. const list = Template.currentData();
  19. const status = list.isStarred();
  20. if (check === undefined) {
  21. // just check
  22. return status;
  23. } else {
  24. list.star(!status);
  25. return !status;
  26. }
  27. },
  28. editTitle(event) {
  29. event.preventDefault();
  30. const newTitle = this.childComponents('inlinedForm')[0]
  31. .getValue()
  32. .trim();
  33. const list = this.currentData();
  34. if (newTitle) {
  35. list.rename(newTitle.trim());
  36. }
  37. },
  38. isWatching() {
  39. const list = this.currentData();
  40. return list.findWatcher(Meteor.userId());
  41. },
  42. limitToShowCardsCount() {
  43. return Meteor.user().getLimitToShowCardsCount();
  44. },
  45. cardsCount() {
  46. const list = Template.currentData();
  47. let swimlaneId = '';
  48. const boardView = (Meteor.user().profile || {}).boardView;
  49. if (boardView === 'board-view-swimlanes')
  50. swimlaneId = this.parentComponent()
  51. .parentComponent()
  52. .data()._id;
  53. return list.cards(swimlaneId).count();
  54. },
  55. reachedWipLimit() {
  56. const list = Template.currentData();
  57. return (
  58. list.getWipLimit('enabled') &&
  59. list.getWipLimit('value') <= list.cards().count()
  60. );
  61. },
  62. showCardsCountForList(count) {
  63. const limit = this.limitToShowCardsCount();
  64. return limit > 0 && count > limit;
  65. },
  66. events() {
  67. return [
  68. {
  69. 'click .js-list-star'(event) {
  70. event.preventDefault();
  71. this.starred(!this.starred());
  72. },
  73. 'click .js-open-list-menu': Popup.open('listAction'),
  74. 'click .js-add-card'(event) {
  75. const listDom = $(event.target).parents(
  76. `#js-list-${this.currentData()._id}`,
  77. )[0];
  78. const listComponent = BlazeComponent.getComponentForElement(listDom);
  79. listComponent.openForm({
  80. position: 'top',
  81. });
  82. },
  83. 'click .js-unselect-list'() {
  84. Session.set('currentList', null);
  85. },
  86. submit: this.editTitle,
  87. },
  88. ];
  89. },
  90. }).register('listHeader');
  91. Template.listHeader.helpers({
  92. showDesktopDragHandles() {
  93. return Meteor.user().hasShowDesktopDragHandles();
  94. },
  95. });
  96. Template.listActionPopup.helpers({
  97. isWipLimitEnabled() {
  98. return Template.currentData().getWipLimit('enabled');
  99. },
  100. isWatching() {
  101. return this.findWatcher(Meteor.userId());
  102. },
  103. });
  104. Template.listActionPopup.events({
  105. 'click .js-list-subscribe'() {},
  106. 'click .js-set-color-list': Popup.open('setListColor'),
  107. 'click .js-select-cards'() {
  108. const cardIds = this.allCards().map(card => card._id);
  109. MultiSelection.add(cardIds);
  110. Popup.close();
  111. },
  112. 'click .js-toggle-watch-list'() {
  113. const currentList = this;
  114. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  115. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  116. if (!err && ret) Popup.close();
  117. });
  118. },
  119. 'click .js-close-list'(event) {
  120. event.preventDefault();
  121. this.archive();
  122. Popup.close();
  123. },
  124. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  125. 'click .js-more': Popup.open('listMore'),
  126. });
  127. BlazeComponent.extendComponent({
  128. applyWipLimit() {
  129. const list = Template.currentData();
  130. const limit = parseInt(
  131. Template.instance()
  132. .$('.wip-limit-value')
  133. .val(),
  134. 10,
  135. );
  136. if (limit < list.cards().count() && !list.getWipLimit('soft')) {
  137. Template.instance()
  138. .$('.wip-limit-error')
  139. .click();
  140. } else {
  141. Meteor.call('applyWipLimit', list._id, limit);
  142. Popup.back();
  143. }
  144. },
  145. enableSoftLimit() {
  146. const list = Template.currentData();
  147. if (
  148. list.getWipLimit('soft') &&
  149. list.getWipLimit('value') < list.cards().count()
  150. ) {
  151. list.setWipLimit(list.cards().count());
  152. }
  153. Meteor.call('enableSoftLimit', Template.currentData()._id);
  154. },
  155. enableWipLimit() {
  156. const list = Template.currentData();
  157. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  158. if (
  159. !list.getWipLimit('enabled') &&
  160. list.getWipLimit('value') < list.cards().count()
  161. ) {
  162. list.setWipLimit(list.cards().count());
  163. }
  164. Meteor.call('enableWipLimit', list._id);
  165. },
  166. isWipLimitSoft() {
  167. return Template.currentData().getWipLimit('soft');
  168. },
  169. isWipLimitEnabled() {
  170. return Template.currentData().getWipLimit('enabled');
  171. },
  172. wipLimitValue() {
  173. return Template.currentData().getWipLimit('value');
  174. },
  175. events() {
  176. return [
  177. {
  178. 'click .js-enable-wip-limit': this.enableWipLimit,
  179. 'click .wip-limit-apply': this.applyWipLimit,
  180. 'click .wip-limit-error': Popup.open('wipLimitError'),
  181. 'click .materialCheckBox': this.enableSoftLimit,
  182. },
  183. ];
  184. },
  185. }).register('setWipLimitPopup');
  186. Template.listMorePopup.events({
  187. 'click .js-delete': Popup.afterConfirm('listDelete', function() {
  188. Popup.close();
  189. this.allCards().map(card => Cards.remove(card._id));
  190. Lists.remove(this._id);
  191. Utils.goBoardId(this.boardId);
  192. }),
  193. });
  194. BlazeComponent.extendComponent({
  195. onCreated() {
  196. this.currentList = this.currentData();
  197. this.currentColor = new ReactiveVar(this.currentList.color);
  198. },
  199. colors() {
  200. return listsColors.map(color => ({ color, name: '' }));
  201. },
  202. isSelected(color) {
  203. return this.currentColor.get() === color;
  204. },
  205. events() {
  206. return [
  207. {
  208. 'click .js-palette-color'() {
  209. this.currentColor.set(this.currentData().color);
  210. },
  211. 'click .js-submit'() {
  212. this.currentList.setColor(this.currentColor.get());
  213. Popup.close();
  214. },
  215. 'click .js-remove-color'() {
  216. this.currentList.setColor(null);
  217. Popup.close();
  218. },
  219. },
  220. ];
  221. },
  222. }).register('setListColorPopup');