boardHeader.js 5.2 KB

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