boardHeader.js 8.5 KB

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