boardHeader.js 12 KB

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