boardHeader.js 5.0 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.boardMenuPopup.helpers({
  18. exportUrl() {
  19. const boardId = Session.get('currentBoard');
  20. const loginToken = Accounts._storedLoginToken();
  21. return FlowRouter.url(`api/boards/${boardId}?authToken=${loginToken}`);
  22. },
  23. exportFilename() {
  24. const boardId = Session.get('currentBoard');
  25. return `wekan-export-board-${boardId}.json`;
  26. },
  27. });
  28. Template.boardChangeTitlePopup.events({
  29. submit(evt, tpl) {
  30. const newTitle = tpl.$('.js-board-name').val().trim();
  31. const newDesc = tpl.$('.js-board-desc').val().trim();
  32. if (newTitle) {
  33. this.rename(newTitle);
  34. this.setDesciption(newDesc);
  35. Popup.close();
  36. }
  37. evt.preventDefault();
  38. },
  39. });
  40. BlazeComponent.extendComponent({
  41. isStarred() {
  42. const boardId = Session.get('currentBoard');
  43. const user = Meteor.user();
  44. return user && user.hasStarred(boardId);
  45. },
  46. isMiniScreen() {
  47. return Utils.isMiniScreen();
  48. },
  49. // Only show the star counter if the number of star is greater than 2
  50. showStarCounter() {
  51. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  52. return currentBoard && currentBoard.stars >= 2;
  53. },
  54. events() {
  55. return [{
  56. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  57. 'click .js-star-board'() {
  58. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  59. },
  60. 'click .js-open-board-menu': Popup.open('boardMenu'),
  61. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  62. 'click .js-open-filter-view'() {
  63. Sidebar.setView('filter');
  64. },
  65. 'click .js-filter-reset'(evt) {
  66. evt.stopPropagation();
  67. Sidebar.setView();
  68. Filter.reset();
  69. },
  70. 'click .js-multiselection-activate'() {
  71. const currentCard = Session.get('currentCard');
  72. MultiSelection.activate();
  73. if (currentCard) {
  74. MultiSelection.add(currentCard);
  75. }
  76. },
  77. 'click .js-multiselection-reset'(evt) {
  78. evt.stopPropagation();
  79. MultiSelection.disable();
  80. },
  81. }];
  82. },
  83. }).register('boardHeaderBar');
  84. BlazeComponent.extendComponent({
  85. backgroundColors() {
  86. return Boards.simpleSchema()._schema.color.allowedValues;
  87. },
  88. isSelected() {
  89. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  90. return currentBoard.color === this.currentData().toString();
  91. },
  92. events() {
  93. return [{
  94. 'click .js-select-background'(evt) {
  95. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  96. const newColor = this.currentData().toString();
  97. currentBoard.setColor(newColor);
  98. evt.preventDefault();
  99. },
  100. }];
  101. },
  102. }).register('boardChangeColorPopup');
  103. BlazeComponent.extendComponent({
  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. visibilityCheck() {
  143. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  144. return this.currentData() === currentBoard.permission;
  145. },
  146. selectBoardVisibility() {
  147. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  148. const visibility = this.currentData();
  149. currentBoard.setVisibility(visibility);
  150. Popup.close();
  151. },
  152. events() {
  153. return [{
  154. 'click .js-select-visibility': this.selectBoardVisibility,
  155. }];
  156. },
  157. }).register('boardChangeVisibilityPopup');