boardHeader.js 6.3 KB

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