boardHeader.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Template.boardMenuPopup.events({
  2. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  3. 'click .js-open-archives'() {
  4. Sidebar.setView('archives');
  5. Popup.close();
  6. },
  7. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  8. 'click .js-change-language': Popup.open('changeLanguage'),
  9. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', () => {
  10. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  11. currentBoard.archive();
  12. // XXX We should have some kind of notification on top of the page to
  13. // confirm that the board was successfully archived.
  14. FlowRouter.go('home');
  15. }),
  16. });
  17. Template.boardChangeTitlePopup.events({
  18. submit(evt, tpl) {
  19. const newTitle = tpl.$('.js-board-name').val().trim();
  20. if (newTitle) {
  21. this.rename(newTitle);
  22. Popup.close();
  23. }
  24. evt.preventDefault();
  25. },
  26. });
  27. BlazeComponent.extendComponent({
  28. template() {
  29. return 'headerBoard';
  30. },
  31. isStarred() {
  32. const boardId = Session.get('currentBoard');
  33. const user = Meteor.user();
  34. return user && user.hasStarred(boardId);
  35. },
  36. // Only show the star counter if the number of star is greater than 2
  37. showStarCounter() {
  38. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  39. return currentBoard && currentBoard.stars >= 2;
  40. },
  41. events() {
  42. return [{
  43. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  44. 'click .js-star-board'() {
  45. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  46. },
  47. 'click .js-open-board-menu': Popup.open('boardMenu'),
  48. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  49. 'click .js-open-filter-view'() {
  50. Sidebar.setView('filter');
  51. },
  52. 'click .js-filter-reset'(evt) {
  53. evt.stopPropagation();
  54. Sidebar.setView();
  55. Filter.reset();
  56. },
  57. 'click .js-multiselection-activate'() {
  58. const currentCard = Session.get('currentCard');
  59. MultiSelection.activate();
  60. if (currentCard) {
  61. MultiSelection.add(currentCard);
  62. }
  63. },
  64. 'click .js-multiselection-reset'(evt) {
  65. evt.stopPropagation();
  66. MultiSelection.disable();
  67. },
  68. }];
  69. },
  70. }).register('headerBoard');
  71. BlazeComponent.extendComponent({
  72. template() {
  73. return 'boardChangeColorPopup';
  74. },
  75. backgroundColors() {
  76. return Boards.simpleSchema()._schema.color.allowedValues;
  77. },
  78. isSelected() {
  79. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  80. return currentBoard.color === this.currentData().toString();
  81. },
  82. events() {
  83. return [{
  84. 'click .js-select-background'(evt) {
  85. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  86. const newColor = this.currentData().toString();
  87. currentBoard.setColor(newColor);
  88. evt.preventDefault();
  89. },
  90. }];
  91. },
  92. }).register('boardChangeColorPopup');
  93. BlazeComponent.extendComponent({
  94. template() {
  95. return 'createBoardPopup';
  96. },
  97. onCreated() {
  98. this.visibilityMenuIsOpen = new ReactiveVar(false);
  99. this.visibility = new ReactiveVar('private');
  100. },
  101. visibilityCheck() {
  102. return this.currentData() === this.visibility.get();
  103. },
  104. setVisibility(visibility) {
  105. this.visibility.set(visibility);
  106. this.visibilityMenuIsOpen.set(false);
  107. },
  108. toggleVisibilityMenu() {
  109. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  110. },
  111. onSubmit(evt) {
  112. evt.preventDefault();
  113. const title = this.find('.js-new-board-title').value;
  114. const visibility = this.visibility.get();
  115. const boardId = Boards.insert({
  116. title,
  117. permission: visibility,
  118. });
  119. Utils.goBoardId(boardId);
  120. // Immediately star boards crated with the headerbar popup.
  121. Meteor.user().toggleBoardStar(boardId);
  122. },
  123. events() {
  124. return [{
  125. 'click .js-select-visibility'() {
  126. this.setVisibility(this.currentData());
  127. },
  128. 'click .js-change-visibility': this.toggleVisibilityMenu,
  129. submit: this.onSubmit,
  130. }];
  131. },
  132. }).register('createBoardPopup');
  133. BlazeComponent.extendComponent({
  134. template() {
  135. return 'boardChangeVisibilityPopup';
  136. },
  137. visibilityCheck() {
  138. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  139. return this.currentData() === currentBoard.permission;
  140. },
  141. selectBoardVisibility() {
  142. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  143. const visibility = this.currentData();
  144. currentBoard.setVisibility(visibility);
  145. Popup.close();
  146. },
  147. events() {
  148. return [{
  149. 'click .js-select-visibility': this.selectBoardVisibility,
  150. }];
  151. },
  152. }).register('boardChangeVisibilityPopup');