boardHeader.js 7.6 KB

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