boardHeader.js 7.7 KB

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