boardHeader.js 4.9 KB

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