boardHeader.js 8.4 KB

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