boardHeader.js 12 KB

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