boardHeader.js 5.1 KB

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