listHeader.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. currentUser = Meteor.user();
  96. if (currentUser) {
  97. return (currentUser.profile || {}).showDesktopDragHandles;
  98. } else {
  99. import { Cookies } from 'meteor/ostrio:cookies';
  100. const cookies = new Cookies();
  101. if (cookies.has('showDesktopDragHandles')) {
  102. return true;
  103. } else {
  104. return false;
  105. }
  106. }
  107. },
  108. });
  109. Template.listActionPopup.helpers({
  110. isWipLimitEnabled() {
  111. return Template.currentData().getWipLimit('enabled');
  112. },
  113. isWatching() {
  114. return this.findWatcher(Meteor.userId());
  115. },
  116. });
  117. Template.listActionPopup.events({
  118. 'click .js-list-subscribe'() {},
  119. 'click .js-set-color-list': Popup.open('setListColor'),
  120. 'click .js-select-cards'() {
  121. const cardIds = this.allCards().map(card => card._id);
  122. MultiSelection.add(cardIds);
  123. Popup.close();
  124. },
  125. 'click .js-toggle-watch-list'() {
  126. const currentList = this;
  127. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  128. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  129. if (!err && ret) Popup.close();
  130. });
  131. },
  132. 'click .js-close-list'(event) {
  133. event.preventDefault();
  134. this.archive();
  135. Popup.close();
  136. },
  137. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  138. 'click .js-more': Popup.open('listMore'),
  139. });
  140. BlazeComponent.extendComponent({
  141. applyWipLimit() {
  142. const list = Template.currentData();
  143. const limit = parseInt(
  144. Template.instance()
  145. .$('.wip-limit-value')
  146. .val(),
  147. 10,
  148. );
  149. if (limit < list.cards().count() && !list.getWipLimit('soft')) {
  150. Template.instance()
  151. .$('.wip-limit-error')
  152. .click();
  153. } else {
  154. Meteor.call('applyWipLimit', list._id, limit);
  155. Popup.back();
  156. }
  157. },
  158. enableSoftLimit() {
  159. const list = Template.currentData();
  160. if (
  161. list.getWipLimit('soft') &&
  162. list.getWipLimit('value') < list.cards().count()
  163. ) {
  164. list.setWipLimit(list.cards().count());
  165. }
  166. Meteor.call('enableSoftLimit', Template.currentData()._id);
  167. },
  168. enableWipLimit() {
  169. const list = Template.currentData();
  170. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  171. if (
  172. !list.getWipLimit('enabled') &&
  173. list.getWipLimit('value') < list.cards().count()
  174. ) {
  175. list.setWipLimit(list.cards().count());
  176. }
  177. Meteor.call('enableWipLimit', list._id);
  178. },
  179. isWipLimitSoft() {
  180. return Template.currentData().getWipLimit('soft');
  181. },
  182. isWipLimitEnabled() {
  183. return Template.currentData().getWipLimit('enabled');
  184. },
  185. wipLimitValue() {
  186. return Template.currentData().getWipLimit('value');
  187. },
  188. events() {
  189. return [
  190. {
  191. 'click .js-enable-wip-limit': this.enableWipLimit,
  192. 'click .wip-limit-apply': this.applyWipLimit,
  193. 'click .wip-limit-error': Popup.open('wipLimitError'),
  194. 'click .materialCheckBox': this.enableSoftLimit,
  195. },
  196. ];
  197. },
  198. }).register('setWipLimitPopup');
  199. Template.listMorePopup.events({
  200. 'click .js-delete': Popup.afterConfirm('listDelete', function() {
  201. Popup.close();
  202. this.allCards().map(card => Cards.remove(card._id));
  203. Lists.remove(this._id);
  204. Utils.goBoardId(this.boardId);
  205. }),
  206. });
  207. BlazeComponent.extendComponent({
  208. onCreated() {
  209. this.currentList = this.currentData();
  210. this.currentColor = new ReactiveVar(this.currentList.color);
  211. },
  212. colors() {
  213. return listsColors.map(color => ({ color, name: '' }));
  214. },
  215. isSelected(color) {
  216. return this.currentColor.get() === color;
  217. },
  218. events() {
  219. return [
  220. {
  221. 'click .js-palette-color'() {
  222. this.currentColor.set(this.currentData().color);
  223. },
  224. 'click .js-submit'() {
  225. this.currentList.setColor(this.currentColor.get());
  226. Popup.close();
  227. },
  228. 'click .js-remove-color'() {
  229. this.currentList.setColor(null);
  230. Popup.close();
  231. },
  232. },
  233. ];
  234. },
  235. }).register('setListColorPopup');