boardHeader.js 6.2 KB

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