boardHeader.js 8.5 KB

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