boardHeader.js 8.7 KB

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