boardHeader.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. Template.boardMenuPopup.events({
  2. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  3. 'click .js-custom-fields'() {
  4. Sidebar.setView('customFields');
  5. Popup.close();
  6. },
  7. 'click .js-open-archives'() {
  8. Sidebar.setView('archives');
  9. Popup.close();
  10. },
  11. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  12. 'click .js-change-language': Popup.open('changeLanguage'),
  13. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  14. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  15. currentBoard.archive();
  16. // XXX We should have some kind of notification on top of the page to
  17. // confirm that the board was successfully archived.
  18. FlowRouter.go('home');
  19. }),
  20. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  21. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  22. Popup.close();
  23. Boards.remove(currentBoard._id);
  24. FlowRouter.go('home');
  25. }),
  26. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  27. 'click .js-import-board': Popup.open('chooseBoardSource'),
  28. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  29. });
  30. Template.boardMenuPopup.helpers({
  31. exportUrl() {
  32. const params = {
  33. boardId: Session.get('currentBoard'),
  34. };
  35. const queryParams = {
  36. authToken: Accounts._storedLoginToken(),
  37. };
  38. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  39. },
  40. exportFilename() {
  41. const boardId = Session.get('currentBoard');
  42. return `wekan-export-board-${boardId}.json`;
  43. },
  44. });
  45. Template.boardChangeTitlePopup.events({
  46. submit(event, templateInstance) {
  47. const newTitle = templateInstance
  48. .$('.js-board-name')
  49. .val()
  50. .trim();
  51. const newDesc = templateInstance
  52. .$('.js-board-desc')
  53. .val()
  54. .trim();
  55. if (newTitle) {
  56. this.rename(newTitle);
  57. this.setDescription(newDesc);
  58. Popup.close();
  59. }
  60. event.preventDefault();
  61. },
  62. });
  63. BlazeComponent.extendComponent({
  64. watchLevel() {
  65. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  66. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  67. },
  68. isStarred() {
  69. const boardId = Session.get('currentBoard');
  70. const user = Meteor.user();
  71. return user && user.hasStarred(boardId);
  72. },
  73. // Only show the star counter if the number of star is greater than 2
  74. showStarCounter() {
  75. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  76. return currentBoard && currentBoard.stars >= 2;
  77. },
  78. events() {
  79. return [
  80. {
  81. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  82. 'click .js-star-board'() {
  83. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  84. },
  85. 'click .js-open-board-menu': Popup.open('boardMenu'),
  86. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  87. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  88. 'click .js-open-archived-board'() {
  89. Modal.open('archivedBoards');
  90. },
  91. 'click .js-toggle-board-view'() {
  92. const currentUser = Meteor.user();
  93. if (
  94. (currentUser.profile || {}).boardView === 'board-view-swimlanes'
  95. ) {
  96. currentUser.setBoardView('board-view-cal');
  97. } else if (
  98. (currentUser.profile || {}).boardView === 'board-view-lists'
  99. ) {
  100. currentUser.setBoardView('board-view-swimlanes');
  101. } else if (
  102. (currentUser.profile || {}).boardView === 'board-view-cal'
  103. ) {
  104. currentUser.setBoardView('board-view-lists');
  105. } else {
  106. currentUser.setBoardView('board-view-swimlanes');
  107. }
  108. },
  109. 'click .js-toggle-sidebar'() {
  110. Sidebar.toggle();
  111. },
  112. 'click .js-open-filter-view'() {
  113. Sidebar.setView('filter');
  114. },
  115. 'click .js-filter-reset'(event) {
  116. event.stopPropagation();
  117. Sidebar.setView();
  118. Filter.reset();
  119. },
  120. 'click .js-open-search-view'() {
  121. Sidebar.setView('search');
  122. },
  123. 'click .js-open-rules-view'() {
  124. Modal.openWide('rulesMain');
  125. },
  126. 'click .js-multiselection-activate'() {
  127. const currentCard = Session.get('currentCard');
  128. MultiSelection.activate();
  129. if (currentCard) {
  130. MultiSelection.add(currentCard);
  131. }
  132. },
  133. 'click .js-multiselection-reset'(event) {
  134. event.stopPropagation();
  135. MultiSelection.disable();
  136. },
  137. 'click .js-log-in'() {
  138. FlowRouter.go('atSignIn');
  139. },
  140. },
  141. ];
  142. },
  143. }).register('boardHeaderBar');
  144. Template.boardHeaderBar.helpers({
  145. canModifyBoard() {
  146. return (
  147. Meteor.user() &&
  148. Meteor.user().isBoardMember() &&
  149. !Meteor.user().isCommentOnly()
  150. );
  151. },
  152. });
  153. const CreateBoard = BlazeComponent.extendComponent({
  154. template() {
  155. return 'createBoard';
  156. },
  157. onCreated() {
  158. this.visibilityMenuIsOpen = new ReactiveVar(false);
  159. this.visibility = new ReactiveVar('private');
  160. this.boardId = new ReactiveVar('');
  161. },
  162. visibilityCheck() {
  163. return this.currentData() === this.visibility.get();
  164. },
  165. setVisibility(visibility) {
  166. this.visibility.set(visibility);
  167. this.visibilityMenuIsOpen.set(false);
  168. },
  169. toggleVisibilityMenu() {
  170. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  171. },
  172. onSubmit(event) {
  173. event.preventDefault();
  174. const title = this.find('.js-new-board-title').value;
  175. const visibility = this.visibility.get();
  176. this.boardId.set(
  177. Boards.insert({
  178. title,
  179. permission: visibility,
  180. }),
  181. );
  182. Swimlanes.insert({
  183. title: 'Default',
  184. boardId: this.boardId.get(),
  185. });
  186. Utils.goBoardId(this.boardId.get());
  187. },
  188. events() {
  189. return [
  190. {
  191. 'click .js-select-visibility'() {
  192. this.setVisibility(this.currentData());
  193. },
  194. 'click .js-change-visibility': this.toggleVisibilityMenu,
  195. 'click .js-import': Popup.open('boardImportBoard'),
  196. submit: this.onSubmit,
  197. 'click .js-import-board': Popup.open('chooseBoardSource'),
  198. 'click .js-board-template': Popup.open('searchElement'),
  199. },
  200. ];
  201. },
  202. }).register('createBoardPopup');
  203. (class HeaderBarCreateBoard extends CreateBoard {
  204. onSubmit(event) {
  205. super.onSubmit(event);
  206. // Immediately star boards crated with the headerbar popup.
  207. Meteor.user().toggleBoardStar(this.boardId.get());
  208. }
  209. }.register('headerBarCreateBoardPopup'));
  210. BlazeComponent.extendComponent({
  211. visibilityCheck() {
  212. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  213. return this.currentData() === currentBoard.permission;
  214. },
  215. selectBoardVisibility() {
  216. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  217. const visibility = this.currentData();
  218. currentBoard.setVisibility(visibility);
  219. Popup.close();
  220. },
  221. events() {
  222. return [
  223. {
  224. 'click .js-select-visibility': this.selectBoardVisibility,
  225. },
  226. ];
  227. },
  228. }).register('boardChangeVisibilityPopup');
  229. BlazeComponent.extendComponent({
  230. watchLevel() {
  231. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  232. return currentBoard.getWatchLevel(Meteor.userId());
  233. },
  234. watchCheck() {
  235. return this.currentData() === this.watchLevel();
  236. },
  237. events() {
  238. return [
  239. {
  240. 'click .js-select-watch'() {
  241. const level = this.currentData();
  242. Meteor.call(
  243. 'watch',
  244. 'board',
  245. Session.get('currentBoard'),
  246. level,
  247. (err, ret) => {
  248. if (!err && ret) Popup.close();
  249. },
  250. );
  251. },
  252. },
  253. ];
  254. },
  255. }).register('boardChangeWatchPopup');