boardHeader.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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-open-filter-view'() {
  74. Sidebar.setView('filter');
  75. },
  76. 'click .js-filter-reset'(evt) {
  77. evt.stopPropagation();
  78. Sidebar.setView();
  79. Filter.reset();
  80. },
  81. 'click .js-multiselection-activate'() {
  82. const currentCard = Session.get('currentCard');
  83. MultiSelection.activate();
  84. if (currentCard) {
  85. MultiSelection.add(currentCard);
  86. }
  87. },
  88. 'click .js-multiselection-reset'(evt) {
  89. evt.stopPropagation();
  90. MultiSelection.disable();
  91. },
  92. 'click .js-log-in'() {
  93. FlowRouter.go('atSignIn');
  94. },
  95. }];
  96. },
  97. }).register('boardHeaderBar');
  98. Template.boardHeaderBar.helpers({
  99. canModifyBoard() {
  100. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  101. },
  102. });
  103. BlazeComponent.extendComponent({
  104. backgroundColors() {
  105. return Boards.simpleSchema()._schema.color.allowedValues;
  106. },
  107. isSelected() {
  108. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  109. return currentBoard.color === this.currentData().toString();
  110. },
  111. events() {
  112. return [{
  113. 'click .js-select-background'(evt) {
  114. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  115. const newColor = this.currentData().toString();
  116. currentBoard.setColor(newColor);
  117. evt.preventDefault();
  118. },
  119. }];
  120. },
  121. }).register('boardChangeColorPopup');
  122. const CreateBoard = BlazeComponent.extendComponent({
  123. template() {
  124. return 'createBoard';
  125. },
  126. onCreated() {
  127. this.visibilityMenuIsOpen = new ReactiveVar(false);
  128. this.visibility = new ReactiveVar('private');
  129. this.boardId = new ReactiveVar('');
  130. },
  131. visibilityCheck() {
  132. return this.currentData() === this.visibility.get();
  133. },
  134. setVisibility(visibility) {
  135. this.visibility.set(visibility);
  136. this.visibilityMenuIsOpen.set(false);
  137. },
  138. toggleVisibilityMenu() {
  139. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  140. },
  141. onSubmit(evt) {
  142. evt.preventDefault();
  143. const title = this.find('.js-new-board-title').value;
  144. const visibility = this.visibility.get();
  145. this.boardId.set(Boards.insert({
  146. title,
  147. permission: visibility,
  148. }));
  149. Utils.goBoardId(this.boardId.get());
  150. },
  151. events() {
  152. return [{
  153. 'click .js-select-visibility'() {
  154. this.setVisibility(this.currentData());
  155. },
  156. 'click .js-change-visibility': this.toggleVisibilityMenu,
  157. 'click .js-import': Popup.open('boardImportBoard'),
  158. submit: this.onSubmit,
  159. 'click .js-import-board': Popup.open('chooseBoardSource'),
  160. }];
  161. },
  162. }).register('createBoardPopup');
  163. BlazeComponent.extendComponent({
  164. template() {
  165. return 'chooseBoardSource';
  166. },
  167. }).register('chooseBoardSourcePopup');
  168. (class HeaderBarCreateBoard extends CreateBoard {
  169. onSubmit(evt) {
  170. super.onSubmit(evt);
  171. // Immediately star boards crated with the headerbar popup.
  172. Meteor.user().toggleBoardStar(this.boardId.get());
  173. }
  174. }).register('headerBarCreateBoardPopup');
  175. BlazeComponent.extendComponent({
  176. visibilityCheck() {
  177. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  178. return this.currentData() === currentBoard.permission;
  179. },
  180. selectBoardVisibility() {
  181. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  182. const visibility = this.currentData();
  183. currentBoard.setVisibility(visibility);
  184. Popup.close();
  185. },
  186. events() {
  187. return [{
  188. 'click .js-select-visibility': this.selectBoardVisibility,
  189. }];
  190. },
  191. }).register('boardChangeVisibilityPopup');
  192. BlazeComponent.extendComponent({
  193. watchLevel() {
  194. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  195. return currentBoard.getWatchLevel(Meteor.userId());
  196. },
  197. watchCheck() {
  198. return this.currentData() === this.watchLevel();
  199. },
  200. events() {
  201. return [{
  202. 'click .js-select-watch'() {
  203. const level = this.currentData();
  204. Meteor.call('watch', 'board', Session.get('currentBoard'), level, (err, ret) => {
  205. if (!err && ret) Popup.close();
  206. });
  207. },
  208. }];
  209. },
  210. }).register('boardChangeWatchPopup');
  211. BlazeComponent.extendComponent({
  212. integrations() {
  213. const boardId = Session.get('currentBoard');
  214. return Integrations.find({ boardId: `${boardId}` }).fetch();
  215. },
  216. integration(id) {
  217. const boardId = Session.get('currentBoard');
  218. return Integrations.findOne({ _id: id, boardId: `${boardId}` });
  219. },
  220. events() {
  221. return [{
  222. 'submit'(evt) {
  223. evt.preventDefault();
  224. const url = evt.target.url.value;
  225. const boardId = Session.get('currentBoard');
  226. let id = null;
  227. let integration = null;
  228. if (evt.target.id) {
  229. id = evt.target.id.value;
  230. integration = this.integration(id);
  231. if (url) {
  232. Integrations.update(integration._id, {
  233. $set: {
  234. url: `${url}`,
  235. },
  236. });
  237. } else {
  238. Integrations.remove(integration._id);
  239. }
  240. } else if (url) {
  241. Integrations.insert({
  242. userId: Meteor.userId(),
  243. enabled: true,
  244. type: 'outgoing-webhooks',
  245. url: `${url}`,
  246. boardId: `${boardId}`,
  247. activities: ['all'],
  248. });
  249. }
  250. Popup.close();
  251. },
  252. }];
  253. },
  254. }).register('outgoingWebhooksPopup');