listHeader.js 6.4 KB

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