boardHeader.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. BlazeComponent.extendComponent({
  93. backgroundColors() {
  94. return Boards.simpleSchema()._schema.color.allowedValues;
  95. },
  96. isSelected() {
  97. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  98. return currentBoard.color === this.currentData().toString();
  99. },
  100. events() {
  101. return [{
  102. 'click .js-select-background'(evt) {
  103. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  104. const newColor = this.currentData().toString();
  105. currentBoard.setColor(newColor);
  106. evt.preventDefault();
  107. },
  108. }];
  109. },
  110. }).register('boardChangeColorPopup');
  111. BlazeComponent.extendComponent({
  112. onCreated() {
  113. this.visibilityMenuIsOpen = new ReactiveVar(false);
  114. this.visibility = new ReactiveVar('private');
  115. },
  116. visibilityCheck() {
  117. return this.currentData() === this.visibility.get();
  118. },
  119. setVisibility(visibility) {
  120. this.visibility.set(visibility);
  121. this.visibilityMenuIsOpen.set(false);
  122. },
  123. toggleVisibilityMenu() {
  124. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  125. },
  126. onSubmit(evt) {
  127. evt.preventDefault();
  128. const title = this.find('.js-new-board-title').value;
  129. const visibility = this.visibility.get();
  130. const boardId = Boards.insert({
  131. title,
  132. permission: visibility,
  133. });
  134. Utils.goBoardId(boardId);
  135. // Immediately star boards crated with the headerbar popup.
  136. Meteor.user().toggleBoardStar(boardId);
  137. },
  138. events() {
  139. return [{
  140. 'click .js-select-visibility'() {
  141. this.setVisibility(this.currentData());
  142. },
  143. 'click .js-change-visibility': this.toggleVisibilityMenu,
  144. 'click .js-import': Popup.open('boardImportBoard'),
  145. submit: this.onSubmit,
  146. }];
  147. },
  148. }).register('createBoardPopup');
  149. BlazeComponent.extendComponent({
  150. visibilityCheck() {
  151. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  152. return this.currentData() === currentBoard.permission;
  153. },
  154. selectBoardVisibility() {
  155. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  156. const visibility = this.currentData();
  157. currentBoard.setVisibility(visibility);
  158. Popup.close();
  159. },
  160. events() {
  161. return [{
  162. 'click .js-select-visibility': this.selectBoardVisibility,
  163. }];
  164. },
  165. }).register('boardChangeVisibilityPopup');
  166. BlazeComponent.extendComponent({
  167. watchLevel() {
  168. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  169. return currentBoard.getWatchLevel(Meteor.userId());
  170. },
  171. watchCheck() {
  172. return this.currentData() === this.watchLevel();
  173. },
  174. events() {
  175. return [{
  176. 'click .js-select-watch'() {
  177. const level = this.currentData();
  178. Meteor.call('watch', 'board', Session.get('currentBoard'), level, (err, ret) => {
  179. if (!err && ret) Popup.close();
  180. });
  181. },
  182. }];
  183. },
  184. }).register('boardChangeWatchPopup');