boardHeader.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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-delete-board': Popup.afterConfirm('deleteBoard', function() {
  21. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  22. Popup.close();
  23. Boards.remove(currentBoard._id);
  24. FlowRouter.go('home');
  25. }),
  26. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  27. 'click .js-import-board': Popup.open('chooseBoardSource'),
  28. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  29. });
  30. Template.boardMenuPopup.helpers({
  31. exportUrl() {
  32. const params = {
  33. boardId: Session.get('currentBoard'),
  34. };
  35. const queryParams = {
  36. authToken: Accounts._storedLoginToken(),
  37. };
  38. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  39. },
  40. exportFilename() {
  41. const boardId = Session.get('currentBoard');
  42. return `wekan-export-board-${boardId}.json`;
  43. },
  44. });
  45. Template.boardChangeTitlePopup.events({
  46. submit(evt, tpl) {
  47. const newTitle = tpl.$('.js-board-name').val().trim();
  48. const newDesc = tpl.$('.js-board-desc').val().trim();
  49. if (newTitle) {
  50. this.rename(newTitle);
  51. this.setDescription(newDesc);
  52. Popup.close();
  53. }
  54. evt.preventDefault();
  55. },
  56. });
  57. BlazeComponent.extendComponent({
  58. watchLevel() {
  59. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  60. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  61. },
  62. isStarred() {
  63. const boardId = Session.get('currentBoard');
  64. const user = Meteor.user();
  65. return user && user.hasStarred(boardId);
  66. },
  67. // Only show the star counter if the number of star is greater than 2
  68. showStarCounter() {
  69. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  70. return currentBoard && currentBoard.stars >= 2;
  71. },
  72. events() {
  73. return [{
  74. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  75. 'click .js-star-board'() {
  76. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  77. },
  78. 'click .js-open-board-menu': Popup.open('boardMenu'),
  79. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  80. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  81. 'click .js-open-archived-board'() {
  82. Modal.open('archivedBoards');
  83. },
  84. 'click .js-toggle-board-view'() {
  85. const currentUser = Meteor.user();
  86. if (currentUser.profile.boardView === 'board-view-swimlanes') {
  87. currentUser.setBoardView('board-view-cal');
  88. } else if (currentUser.profile.boardView === 'board-view-lists') {
  89. currentUser.setBoardView('board-view-swimlanes');
  90. } else if (currentUser.profile.boardView === 'board-view-cal') {
  91. currentUser.setBoardView('board-view-lists');
  92. }
  93. },
  94. 'click .js-open-filter-view'() {
  95. Sidebar.setView('filter');
  96. },
  97. 'click .js-filter-reset'(evt) {
  98. evt.stopPropagation();
  99. Sidebar.setView();
  100. Filter.reset();
  101. },
  102. 'click .js-open-search-view'() {
  103. Sidebar.setView('search');
  104. },
  105. 'click .js-multiselection-activate'() {
  106. const currentCard = Session.get('currentCard');
  107. MultiSelection.activate();
  108. if (currentCard) {
  109. MultiSelection.add(currentCard);
  110. }
  111. },
  112. 'click .js-multiselection-reset'(evt) {
  113. evt.stopPropagation();
  114. MultiSelection.disable();
  115. },
  116. 'click .js-log-in'() {
  117. FlowRouter.go('atSignIn');
  118. },
  119. }];
  120. },
  121. }).register('boardHeaderBar');
  122. Template.boardHeaderBar.helpers({
  123. canModifyBoard() {
  124. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  125. },
  126. });
  127. BlazeComponent.extendComponent({
  128. backgroundColors() {
  129. return Boards.simpleSchema()._schema.color.allowedValues;
  130. },
  131. isSelected() {
  132. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  133. return currentBoard.color === this.currentData().toString();
  134. },
  135. events() {
  136. return [{
  137. 'click .js-select-background'(evt) {
  138. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  139. const newColor = this.currentData().toString();
  140. currentBoard.setColor(newColor);
  141. evt.preventDefault();
  142. },
  143. }];
  144. },
  145. }).register('boardChangeColorPopup');
  146. BlazeComponent.extendComponent({
  147. onCreated() {
  148. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  149. },
  150. allowsSubtasks() {
  151. return this.currentBoard.allowsSubtasks;
  152. },
  153. isBoardSelected() {
  154. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  155. },
  156. isNullBoardSelected() {
  157. return (this.currentBoard.subtasksDefaultBoardId === null) || (this.currentBoard.subtasksDefaultBoardId === undefined);
  158. },
  159. boards() {
  160. return Boards.find({
  161. archived: false,
  162. 'members.userId': Meteor.userId(),
  163. }, {
  164. sort: ['title'],
  165. });
  166. },
  167. lists() {
  168. return Lists.find({
  169. boardId: this.currentBoard._id,
  170. archived: false,
  171. }, {
  172. sort: ['title'],
  173. });
  174. },
  175. hasLists() {
  176. return this.lists().count() > 0;
  177. },
  178. isListSelected() {
  179. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  180. },
  181. presentParentTask() {
  182. let result = this.currentBoard.presentParentTask;
  183. if ((result === null) || (result === undefined)) {
  184. result = 'no-parent';
  185. }
  186. return result;
  187. },
  188. events() {
  189. return [{
  190. 'click .js-field-has-subtasks'(evt) {
  191. evt.preventDefault();
  192. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  193. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  194. $('.js-field-has-subtasks .materialCheckBox').toggleClass('is-checked', this.currentBoard.allowsSubtasks);
  195. $('.js-field-has-subtasks').toggleClass('is-checked', this.currentBoard.allowsSubtasks);
  196. $('.js-field-deposit-board').prop('disabled', !this.currentBoard.allowsSubtasks);
  197. },
  198. 'change .js-field-deposit-board'(evt) {
  199. let value = evt.target.value;
  200. if (value === 'null') {
  201. value = null;
  202. }
  203. this.currentBoard.setSubtasksDefaultBoardId(value);
  204. evt.preventDefault();
  205. },
  206. 'change .js-field-deposit-list'(evt) {
  207. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  208. evt.preventDefault();
  209. },
  210. 'click .js-field-show-parent-in-minicard'(evt) {
  211. const value = evt.target.id || $(evt.target).parent()[0].id || $(evt.target).parent()[0].parent()[0].id;
  212. const options = [
  213. 'prefix-with-full-path',
  214. 'prefix-with-parent',
  215. 'subtext-with-full-path',
  216. 'subtext-with-parent',
  217. 'no-parent'];
  218. options.forEach(function(element) {
  219. if (element !== value) {
  220. $(`#${element} .materialCheckBox`).toggleClass('is-checked', false);
  221. $(`#${element}`).toggleClass('is-checked', false);
  222. }
  223. });
  224. $(`#${value} .materialCheckBox`).toggleClass('is-checked', true);
  225. $(`#${value}`).toggleClass('is-checked', true);
  226. this.currentBoard.setPresentParentTask(value);
  227. evt.preventDefault();
  228. },
  229. }];
  230. },
  231. }).register('boardSubtaskSettingsPopup');
  232. const CreateBoard = BlazeComponent.extendComponent({
  233. template() {
  234. return 'createBoard';
  235. },
  236. onCreated() {
  237. this.visibilityMenuIsOpen = new ReactiveVar(false);
  238. this.visibility = new ReactiveVar('private');
  239. this.boardId = new ReactiveVar('');
  240. },
  241. visibilityCheck() {
  242. return this.currentData() === this.visibility.get();
  243. },
  244. setVisibility(visibility) {
  245. this.visibility.set(visibility);
  246. this.visibilityMenuIsOpen.set(false);
  247. },
  248. toggleVisibilityMenu() {
  249. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  250. },
  251. onSubmit(evt) {
  252. evt.preventDefault();
  253. const title = this.find('.js-new-board-title').value;
  254. const visibility = this.visibility.get();
  255. this.boardId.set(Boards.insert({
  256. title,
  257. permission: visibility,
  258. }));
  259. Swimlanes.insert({
  260. title: 'Default',
  261. boardId: this.boardId.get(),
  262. });
  263. Utils.goBoardId(this.boardId.get());
  264. },
  265. events() {
  266. return [{
  267. 'click .js-select-visibility'() {
  268. this.setVisibility(this.currentData());
  269. },
  270. 'click .js-change-visibility': this.toggleVisibilityMenu,
  271. 'click .js-import': Popup.open('boardImportBoard'),
  272. submit: this.onSubmit,
  273. 'click .js-import-board': Popup.open('chooseBoardSource'),
  274. }];
  275. },
  276. }).register('createBoardPopup');
  277. BlazeComponent.extendComponent({
  278. template() {
  279. return 'chooseBoardSource';
  280. },
  281. }).register('chooseBoardSourcePopup');
  282. (class HeaderBarCreateBoard extends CreateBoard {
  283. onSubmit(evt) {
  284. super.onSubmit(evt);
  285. // Immediately star boards crated with the headerbar popup.
  286. Meteor.user().toggleBoardStar(this.boardId.get());
  287. }
  288. }).register('headerBarCreateBoardPopup');
  289. BlazeComponent.extendComponent({
  290. visibilityCheck() {
  291. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  292. return this.currentData() === currentBoard.permission;
  293. },
  294. selectBoardVisibility() {
  295. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  296. const visibility = this.currentData();
  297. currentBoard.setVisibility(visibility);
  298. Popup.close();
  299. },
  300. events() {
  301. return [{
  302. 'click .js-select-visibility': this.selectBoardVisibility,
  303. }];
  304. },
  305. }).register('boardChangeVisibilityPopup');
  306. BlazeComponent.extendComponent({
  307. watchLevel() {
  308. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  309. return currentBoard.getWatchLevel(Meteor.userId());
  310. },
  311. watchCheck() {
  312. return this.currentData() === this.watchLevel();
  313. },
  314. events() {
  315. return [{
  316. 'click .js-select-watch'() {
  317. const level = this.currentData();
  318. Meteor.call('watch', 'board', Session.get('currentBoard'), level, (err, ret) => {
  319. if (!err && ret) Popup.close();
  320. });
  321. },
  322. }];
  323. },
  324. }).register('boardChangeWatchPopup');
  325. BlazeComponent.extendComponent({
  326. integrations() {
  327. const boardId = Session.get('currentBoard');
  328. return Integrations.find({ boardId: `${boardId}` }).fetch();
  329. },
  330. integration(id) {
  331. const boardId = Session.get('currentBoard');
  332. return Integrations.findOne({ _id: id, boardId: `${boardId}` });
  333. },
  334. events() {
  335. return [{
  336. 'submit'(evt) {
  337. evt.preventDefault();
  338. const url = evt.target.url.value;
  339. const boardId = Session.get('currentBoard');
  340. let id = null;
  341. let integration = null;
  342. if (evt.target.id) {
  343. id = evt.target.id.value;
  344. integration = this.integration(id);
  345. if (url) {
  346. Integrations.update(integration._id, {
  347. $set: {
  348. url: `${url}`,
  349. },
  350. });
  351. } else {
  352. Integrations.remove(integration._id);
  353. }
  354. } else if (url) {
  355. Integrations.insert({
  356. userId: Meteor.userId(),
  357. enabled: true,
  358. type: 'outgoing-webhooks',
  359. url: `${url}`,
  360. boardId: `${boardId}`,
  361. activities: ['all'],
  362. });
  363. }
  364. Popup.close();
  365. },
  366. }];
  367. },
  368. }).register('outgoingWebhooksPopup');