boardHeader.js 8.4 KB

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