boardHeader.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 params = {
  20. boardId: Session.get('currentBoard'),
  21. };
  22. const queryParams = {
  23. authToken: Accounts._storedLoginToken(),
  24. };
  25. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  26. },
  27. exportFilename() {
  28. const boardId = Session.get('currentBoard');
  29. return `wekan-export-board-${boardId}.json`;
  30. },
  31. });
  32. Template.boardChangeTitlePopup.events({
  33. submit(evt, tpl) {
  34. const newTitle = tpl.$('.js-board-name').val().trim();
  35. const newDesc = tpl.$('.js-board-desc').val().trim();
  36. if (newTitle) {
  37. this.rename(newTitle);
  38. this.setDescription(newDesc);
  39. Popup.close();
  40. }
  41. evt.preventDefault();
  42. },
  43. });
  44. BlazeComponent.extendComponent({
  45. watchLevel() {
  46. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  47. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  48. },
  49. isStarred() {
  50. const boardId = Session.get('currentBoard');
  51. const user = Meteor.user();
  52. return user && user.hasStarred(boardId);
  53. },
  54. isMiniScreen() {
  55. return Utils.isMiniScreen();
  56. },
  57. // Only show the star counter if the number of star is greater than 2
  58. showStarCounter() {
  59. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  60. return currentBoard && currentBoard.stars >= 2;
  61. },
  62. events() {
  63. return [{
  64. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  65. 'click .js-star-board'() {
  66. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  67. },
  68. 'click .js-open-board-menu': Popup.open('boardMenu'),
  69. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  70. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  71. 'click .js-open-filter-view'() {
  72. Sidebar.setView('filter');
  73. },
  74. 'click .js-filter-reset'(evt) {
  75. evt.stopPropagation();
  76. Sidebar.setView();
  77. Filter.reset();
  78. },
  79. 'click .js-multiselection-activate'() {
  80. const currentCard = Session.get('currentCard');
  81. MultiSelection.activate();
  82. if (currentCard) {
  83. MultiSelection.add(currentCard);
  84. }
  85. },
  86. 'click .js-multiselection-reset'(evt) {
  87. evt.stopPropagation();
  88. MultiSelection.disable();
  89. },
  90. 'click .js-log-in'() {
  91. FlowRouter.go('atSignIn');
  92. },
  93. }];
  94. },
  95. }).register('boardHeaderBar');
  96. Template.boardHeaderBar.helpers({
  97. canModifyBoard() {
  98. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  99. },
  100. });
  101. BlazeComponent.extendComponent({
  102. backgroundColors() {
  103. return Boards.simpleSchema()._schema.color.allowedValues;
  104. },
  105. isSelected() {
  106. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  107. return currentBoard.color === this.currentData().toString();
  108. },
  109. events() {
  110. return [{
  111. 'click .js-select-background'(evt) {
  112. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  113. const newColor = this.currentData().toString();
  114. currentBoard.setColor(newColor);
  115. evt.preventDefault();
  116. },
  117. }];
  118. },
  119. }).register('boardChangeColorPopup');
  120. const CreateBoard = BlazeComponent.extendComponent({
  121. template() {
  122. return 'createBoard';
  123. },
  124. onCreated() {
  125. this.visibilityMenuIsOpen = new ReactiveVar(false);
  126. this.visibility = new ReactiveVar('private');
  127. this.boardId = new ReactiveVar('');
  128. },
  129. visibilityCheck() {
  130. return this.currentData() === this.visibility.get();
  131. },
  132. setVisibility(visibility) {
  133. this.visibility.set(visibility);
  134. this.visibilityMenuIsOpen.set(false);
  135. },
  136. toggleVisibilityMenu() {
  137. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  138. },
  139. onSubmit(evt) {
  140. evt.preventDefault();
  141. const title = this.find('.js-new-board-title').value;
  142. const visibility = this.visibility.get();
  143. this.boardId.set(Boards.insert({
  144. title,
  145. permission: visibility,
  146. }));
  147. Utils.goBoardId(this.boardId.get());
  148. },
  149. events() {
  150. return [{
  151. 'click .js-select-visibility'() {
  152. this.setVisibility(this.currentData());
  153. },
  154. 'click .js-change-visibility': this.toggleVisibilityMenu,
  155. 'click .js-import': Popup.open('boardImportBoard'),
  156. submit: this.onSubmit,
  157. }];
  158. },
  159. }).register('createBoardPopup');
  160. (class HeaderBarCreateBoard extends CreateBoard {
  161. onSubmit(evt) {
  162. super.onSubmit(evt);
  163. // Immediately star boards crated with the headerbar popup.
  164. Meteor.user().toggleBoardStar(this.boardId.get());
  165. }
  166. }).register('headerBarCreateBoardPopup');
  167. BlazeComponent.extendComponent({
  168. visibilityCheck() {
  169. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  170. return this.currentData() === currentBoard.permission;
  171. },
  172. selectBoardVisibility() {
  173. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  174. const visibility = this.currentData();
  175. currentBoard.setVisibility(visibility);
  176. Popup.close();
  177. },
  178. events() {
  179. return [{
  180. 'click .js-select-visibility': this.selectBoardVisibility,
  181. }];
  182. },
  183. }).register('boardChangeVisibilityPopup');
  184. BlazeComponent.extendComponent({
  185. watchLevel() {
  186. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  187. return currentBoard.getWatchLevel(Meteor.userId());
  188. },
  189. watchCheck() {
  190. return this.currentData() === this.watchLevel();
  191. },
  192. events() {
  193. return [{
  194. 'click .js-select-watch'() {
  195. const level = this.currentData();
  196. Meteor.call('watch', 'board', Session.get('currentBoard'), level, (err, ret) => {
  197. if (!err && ret) Popup.close();
  198. });
  199. },
  200. }];
  201. },
  202. }).register('boardChangeWatchPopup');