boardHeader.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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', function() {
  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. const newDesc = tpl.$('.js-board-desc').val().trim();
  21. if (newTitle) {
  22. this.rename(newTitle);
  23. this.setDesciption(newDesc);
  24. Popup.close();
  25. }
  26. evt.preventDefault();
  27. },
  28. });
  29. BlazeComponent.extendComponent({
  30. template() {
  31. return 'boardHeaderBar';
  32. },
  33. isStarred() {
  34. const boardId = Session.get('currentBoard');
  35. const user = Meteor.user();
  36. return user && user.hasStarred(boardId);
  37. },
  38. // Only show the star counter if the number of star is greater than 2
  39. showStarCounter() {
  40. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  41. return currentBoard && currentBoard.stars >= 2;
  42. },
  43. events() {
  44. return [{
  45. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  46. 'click .js-star-board'() {
  47. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  48. },
  49. 'click .js-open-board-menu': Popup.open('boardMenu'),
  50. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  51. 'click .js-open-filter-view'() {
  52. Sidebar.setView('filter');
  53. },
  54. 'click .js-filter-reset'(evt) {
  55. evt.stopPropagation();
  56. Sidebar.setView();
  57. Filter.reset();
  58. },
  59. 'click .js-multiselection-activate'() {
  60. const currentCard = Session.get('currentCard');
  61. MultiSelection.activate();
  62. if (currentCard) {
  63. MultiSelection.add(currentCard);
  64. }
  65. },
  66. 'click .js-multiselection-reset'(evt) {
  67. evt.stopPropagation();
  68. MultiSelection.disable();
  69. },
  70. }];
  71. },
  72. }).register('boardHeaderBar');
  73. BlazeComponent.extendComponent({
  74. template() {
  75. return 'boardChangeColorPopup';
  76. },
  77. backgroundColors() {
  78. return Boards.simpleSchema()._schema.color.allowedValues;
  79. },
  80. isSelected() {
  81. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  82. return currentBoard.color === this.currentData().toString();
  83. },
  84. events() {
  85. return [{
  86. 'click .js-select-background'(evt) {
  87. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  88. const newColor = this.currentData().toString();
  89. currentBoard.setColor(newColor);
  90. evt.preventDefault();
  91. },
  92. }];
  93. },
  94. }).register('boardChangeColorPopup');
  95. BlazeComponent.extendComponent({
  96. template() {
  97. return 'createBoardPopup';
  98. },
  99. onCreated() {
  100. this.visibilityMenuIsOpen = new ReactiveVar(false);
  101. this.visibility = new ReactiveVar('private');
  102. },
  103. visibilityCheck() {
  104. return this.currentData() === this.visibility.get();
  105. },
  106. setVisibility(visibility) {
  107. this.visibility.set(visibility);
  108. this.visibilityMenuIsOpen.set(false);
  109. },
  110. toggleVisibilityMenu() {
  111. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  112. },
  113. onSubmit(evt) {
  114. evt.preventDefault();
  115. const title = this.find('.js-new-board-title').value;
  116. const visibility = this.visibility.get();
  117. const boardId = Boards.insert({
  118. title,
  119. permission: visibility,
  120. });
  121. Utils.goBoardId(boardId);
  122. // Immediately star boards crated with the headerbar popup.
  123. Meteor.user().toggleBoardStar(boardId);
  124. },
  125. events() {
  126. return [{
  127. 'click .js-select-visibility'() {
  128. this.setVisibility(this.currentData());
  129. },
  130. 'click .js-change-visibility': this.toggleVisibilityMenu,
  131. 'click .js-import': Popup.open('boardImportBoard'),
  132. submit: this.onSubmit,
  133. }];
  134. },
  135. }).register('createBoardPopup');
  136. BlazeComponent.extendComponent({
  137. template() {
  138. return 'boardChangeVisibilityPopup';
  139. },
  140. visibilityCheck() {
  141. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  142. return this.currentData() === currentBoard.permission;
  143. },
  144. selectBoardVisibility() {
  145. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  146. const visibility = this.currentData();
  147. currentBoard.setVisibility(visibility);
  148. Popup.close();
  149. },
  150. events() {
  151. return [{
  152. 'click .js-select-visibility': this.selectBoardVisibility,
  153. }];
  154. },
  155. }).register('boardChangeVisibilityPopup');