boardHeader.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. 'click .js-export-board'() {
  17. const boardId = Session.get('currentBoard');
  18. Meteor.call('exportBoard', boardId, (error, response) => {
  19. if(error) {
  20. // the only error we can anticipate is accessing a non-authorized board
  21. // and this should have been caugh by UI before.
  22. // So no treatment here for the time being.
  23. } else {
  24. const dataToSave = new Blob([JSON.stringify(response)], {type: 'application/json;charset=utf-8'});
  25. const filename = `wekan-export-board-${boardId}.json`;
  26. saveAs(dataToSave, filename);
  27. }
  28. });
  29. }
  30. });
  31. Template.boardMenuPopup.helpers({
  32. urlExport() {
  33. return Meteor.absoluteUrl(`api/b/${Session.get('currentBoard')}`);
  34. },
  35. });
  36. Template.boardChangeTitlePopup.events({
  37. submit(evt, tpl) {
  38. const newTitle = tpl.$('.js-board-name').val().trim();
  39. const newDesc = tpl.$('.js-board-desc').val().trim();
  40. if (newTitle) {
  41. this.rename(newTitle);
  42. this.setDesciption(newDesc);
  43. Popup.close();
  44. }
  45. evt.preventDefault();
  46. },
  47. });
  48. BlazeComponent.extendComponent({
  49. template() {
  50. return 'headerBoard';
  51. },
  52. isStarred() {
  53. const boardId = Session.get('currentBoard');
  54. const user = Meteor.user();
  55. return user && user.hasStarred(boardId);
  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-open-filter-view'() {
  71. Sidebar.setView('filter');
  72. },
  73. 'click .js-filter-reset'(evt) {
  74. evt.stopPropagation();
  75. Sidebar.setView();
  76. Filter.reset();
  77. },
  78. 'click .js-multiselection-activate'() {
  79. const currentCard = Session.get('currentCard');
  80. MultiSelection.activate();
  81. if (currentCard) {
  82. MultiSelection.add(currentCard);
  83. }
  84. },
  85. 'click .js-multiselection-reset'(evt) {
  86. evt.stopPropagation();
  87. MultiSelection.disable();
  88. },
  89. }];
  90. },
  91. }).register('headerBoard');
  92. BlazeComponent.extendComponent({
  93. template() {
  94. return 'boardChangeColorPopup';
  95. },
  96. backgroundColors() {
  97. return Boards.simpleSchema()._schema.color.allowedValues;
  98. },
  99. isSelected() {
  100. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  101. return currentBoard.color === this.currentData().toString();
  102. },
  103. events() {
  104. return [{
  105. 'click .js-select-background'(evt) {
  106. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  107. const newColor = this.currentData().toString();
  108. currentBoard.setColor(newColor);
  109. evt.preventDefault();
  110. },
  111. }];
  112. },
  113. }).register('boardChangeColorPopup');
  114. BlazeComponent.extendComponent({
  115. template() {
  116. return 'createBoardPopup';
  117. },
  118. onCreated() {
  119. this.visibilityMenuIsOpen = new ReactiveVar(false);
  120. this.visibility = new ReactiveVar('private');
  121. },
  122. visibilityCheck() {
  123. return this.currentData() === this.visibility.get();
  124. },
  125. setVisibility(visibility) {
  126. this.visibility.set(visibility);
  127. this.visibilityMenuIsOpen.set(false);
  128. },
  129. toggleVisibilityMenu() {
  130. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  131. },
  132. onSubmit(evt) {
  133. evt.preventDefault();
  134. const title = this.find('.js-new-board-title').value;
  135. const visibility = this.visibility.get();
  136. const boardId = Boards.insert({
  137. title,
  138. permission: visibility,
  139. });
  140. Utils.goBoardId(boardId);
  141. // Immediately star boards crated with the headerbar popup.
  142. Meteor.user().toggleBoardStar(boardId);
  143. },
  144. events() {
  145. return [{
  146. 'click .js-select-visibility'() {
  147. this.setVisibility(this.currentData());
  148. },
  149. 'click .js-change-visibility': this.toggleVisibilityMenu,
  150. 'click .js-import': Popup.open('boardImportBoard'),
  151. submit: this.onSubmit,
  152. }];
  153. },
  154. }).register('createBoardPopup');
  155. BlazeComponent.extendComponent({
  156. template() {
  157. return 'boardChangeVisibilityPopup';
  158. },
  159. visibilityCheck() {
  160. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  161. return this.currentData() === currentBoard.permission;
  162. },
  163. selectBoardVisibility() {
  164. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  165. const visibility = this.currentData();
  166. currentBoard.setVisibility(visibility);
  167. Popup.close();
  168. },
  169. events() {
  170. return [{
  171. 'click .js-select-visibility': this.selectBoardVisibility,
  172. }];
  173. },
  174. }).register('boardChangeVisibilityPopup');