boardHeader.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. Swimlanes.insert({
  150. title: 'Default',
  151. boardId: this.boardId.get(),
  152. });
  153. Utils.goBoardId(this.boardId.get());
  154. },
  155. events() {
  156. return [{
  157. 'click .js-select-visibility'() {
  158. this.setVisibility(this.currentData());
  159. },
  160. 'click .js-change-visibility': this.toggleVisibilityMenu,
  161. 'click .js-import': Popup.open('boardImportBoard'),
  162. submit: this.onSubmit,
  163. 'click .js-import-board': Popup.open('chooseBoardSource'),
  164. }];
  165. },
  166. }).register('createBoardPopup');
  167. BlazeComponent.extendComponent({
  168. template() {
  169. return 'chooseBoardSource';
  170. },
  171. }).register('chooseBoardSourcePopup');
  172. (class HeaderBarCreateBoard extends CreateBoard {
  173. onSubmit(evt) {
  174. super.onSubmit(evt);
  175. // Immediately star boards crated with the headerbar popup.
  176. Meteor.user().toggleBoardStar(this.boardId.get());
  177. }
  178. }).register('headerBarCreateBoardPopup');
  179. BlazeComponent.extendComponent({
  180. visibilityCheck() {
  181. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  182. return this.currentData() === currentBoard.permission;
  183. },
  184. selectBoardVisibility() {
  185. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  186. const visibility = this.currentData();
  187. currentBoard.setVisibility(visibility);
  188. Popup.close();
  189. },
  190. events() {
  191. return [{
  192. 'click .js-select-visibility': this.selectBoardVisibility,
  193. }];
  194. },
  195. }).register('boardChangeVisibilityPopup');
  196. BlazeComponent.extendComponent({
  197. watchLevel() {
  198. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  199. return currentBoard.getWatchLevel(Meteor.userId());
  200. },
  201. watchCheck() {
  202. return this.currentData() === this.watchLevel();
  203. },
  204. events() {
  205. return [{
  206. 'click .js-select-watch'() {
  207. const level = this.currentData();
  208. Meteor.call('watch', 'board', Session.get('currentBoard'), level, (err, ret) => {
  209. if (!err && ret) Popup.close();
  210. });
  211. },
  212. }];
  213. },
  214. }).register('boardChangeWatchPopup');
  215. BlazeComponent.extendComponent({
  216. integrations() {
  217. const boardId = Session.get('currentBoard');
  218. return Integrations.find({ boardId: `${boardId}` }).fetch();
  219. },
  220. integration(id) {
  221. const boardId = Session.get('currentBoard');
  222. return Integrations.findOne({ _id: id, boardId: `${boardId}` });
  223. },
  224. events() {
  225. return [{
  226. 'submit'(evt) {
  227. evt.preventDefault();
  228. const url = evt.target.url.value;
  229. const boardId = Session.get('currentBoard');
  230. let id = null;
  231. let integration = null;
  232. if (evt.target.id) {
  233. id = evt.target.id.value;
  234. integration = this.integration(id);
  235. if (url) {
  236. Integrations.update(integration._id, {
  237. $set: {
  238. url: `${url}`,
  239. },
  240. });
  241. } else {
  242. Integrations.remove(integration._id);
  243. }
  244. } else if (url) {
  245. Integrations.insert({
  246. userId: Meteor.userId(),
  247. enabled: true,
  248. type: 'outgoing-webhooks',
  249. url: `${url}`,
  250. boardId: `${boardId}`,
  251. activities: ['all'],
  252. });
  253. }
  254. Popup.close();
  255. },
  256. }];
  257. },
  258. }).register('outgoingWebhooksPopup');