boardHeader.js 5.7 KB

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