listHeader.js 6.3 KB

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