boardHeader.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. const DOWNCLS = 'fa-sort-down';
  3. const UPCLS = 'fa-sort-up';
  4. */
  5. Template.boardMenuPopup.events({
  6. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  7. 'click .js-custom-fields'() {
  8. Sidebar.setView('customFields');
  9. Popup.close();
  10. },
  11. 'click .js-open-archives'() {
  12. Sidebar.setView('archives');
  13. Popup.close();
  14. },
  15. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  16. 'click .js-change-language': Popup.open('changeLanguage'),
  17. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  18. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  19. currentBoard.archive();
  20. // XXX We should have some kind of notification on top of the page to
  21. // confirm that the board was successfully archived.
  22. FlowRouter.go('home');
  23. }),
  24. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  25. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  26. Popup.close();
  27. Boards.remove(currentBoard._id);
  28. FlowRouter.go('home');
  29. }),
  30. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  31. 'click .js-import-board': Popup.open('chooseBoardSource'),
  32. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  33. 'click .js-card-settings': Popup.open('boardCardSettings'),
  34. });
  35. Template.boardMenuPopup.helpers({
  36. exportUrl() {
  37. const params = {
  38. boardId: Session.get('currentBoard'),
  39. };
  40. const queryParams = {
  41. authToken: Accounts._storedLoginToken(),
  42. };
  43. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  44. },
  45. exportFilename() {
  46. const boardId = Session.get('currentBoard');
  47. return `wekan-export-board-${boardId}.json`;
  48. },
  49. });
  50. Template.boardChangeTitlePopup.events({
  51. submit(event, templateInstance) {
  52. const newTitle = templateInstance
  53. .$('.js-board-name')
  54. .val()
  55. .trim();
  56. const newDesc = templateInstance
  57. .$('.js-board-desc')
  58. .val()
  59. .trim();
  60. if (newTitle) {
  61. this.rename(newTitle);
  62. this.setDescription(newDesc);
  63. Popup.close();
  64. }
  65. event.preventDefault();
  66. },
  67. });
  68. BlazeComponent.extendComponent({
  69. watchLevel() {
  70. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  71. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  72. },
  73. isStarred() {
  74. const boardId = Session.get('currentBoard');
  75. const user = Meteor.user();
  76. return user && user.hasStarred(boardId);
  77. },
  78. // Only show the star counter if the number of star is greater than 2
  79. showStarCounter() {
  80. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  81. return currentBoard && currentBoard.stars >= 2;
  82. },
  83. /*
  84. showSort() {
  85. return Meteor.user().hasSortBy();
  86. },
  87. directionClass() {
  88. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  89. },
  90. changeDirection() {
  91. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  92. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  93. },
  94. currentDirection() {
  95. return Meteor.user().getListSortByDirection();
  96. },
  97. currentListSortBy() {
  98. return Meteor.user().getListSortBy();
  99. },
  100. listSortShortDesc() {
  101. return `list-label-short-${this.currentListSortBy()}`;
  102. },
  103. */
  104. events() {
  105. return [
  106. {
  107. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  108. 'click .js-star-board'() {
  109. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  110. },
  111. 'click .js-open-board-menu': Popup.open('boardMenu'),
  112. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  113. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  114. 'click .js-open-archived-board'() {
  115. Modal.open('archivedBoards');
  116. },
  117. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  118. 'click .js-toggle-sidebar'() {
  119. Sidebar.toggle();
  120. },
  121. 'click .js-open-filter-view'() {
  122. Sidebar.setView('filter');
  123. },
  124. /*
  125. 'click .js-open-sort-view'(evt) {
  126. const target = evt.target;
  127. if (target.tagName === 'I') {
  128. // click on the text, popup choices
  129. this.changeDirection();
  130. } else {
  131. // change the sort order
  132. Popup.open('listsort')(evt);
  133. }
  134. },
  135. */
  136. 'click .js-filter-reset'(event) {
  137. event.stopPropagation();
  138. Sidebar.setView();
  139. Filter.reset();
  140. },
  141. 'click .js-open-search-view'() {
  142. Sidebar.setView('search');
  143. },
  144. 'click .js-multiselection-activate'() {
  145. const currentCard = Session.get('currentCard');
  146. MultiSelection.activate();
  147. if (currentCard) {
  148. MultiSelection.add(currentCard);
  149. }
  150. },
  151. 'click .js-multiselection-reset'(event) {
  152. event.stopPropagation();
  153. MultiSelection.disable();
  154. },
  155. 'click .js-log-in'() {
  156. FlowRouter.go('atSignIn');
  157. },
  158. },
  159. ];
  160. },
  161. }).register('boardHeaderBar');
  162. Template.boardHeaderBar.helpers({
  163. canModifyBoard() {
  164. return (
  165. Meteor.user() &&
  166. Meteor.user().isBoardMember() &&
  167. !Meteor.user().isCommentOnly()
  168. );
  169. },
  170. boardView() {
  171. return Utils.boardView();
  172. },
  173. });
  174. Template.boardChangeViewPopup.events({
  175. 'click .js-open-lists-view'() {
  176. Utils.setBoardView('board-view-lists');
  177. Popup.close();
  178. },
  179. 'click .js-open-swimlanes-view'() {
  180. Utils.setBoardView('board-view-swimlanes');
  181. Popup.close();
  182. },
  183. 'click .js-open-cal-view'() {
  184. Utils.setBoardView('board-view-cal');
  185. Popup.close();
  186. },
  187. });
  188. const CreateBoard = BlazeComponent.extendComponent({
  189. template() {
  190. return 'createBoard';
  191. },
  192. onCreated() {
  193. this.visibilityMenuIsOpen = new ReactiveVar(false);
  194. this.visibility = new ReactiveVar('private');
  195. this.boardId = new ReactiveVar('');
  196. },
  197. visibilityCheck() {
  198. return this.currentData() === this.visibility.get();
  199. },
  200. setVisibility(visibility) {
  201. this.visibility.set(visibility);
  202. this.visibilityMenuIsOpen.set(false);
  203. },
  204. toggleVisibilityMenu() {
  205. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  206. },
  207. onSubmit(event) {
  208. event.preventDefault();
  209. const title = this.find('.js-new-board-title').value;
  210. const visibility = this.visibility.get();
  211. this.boardId.set(
  212. Boards.insert({
  213. title,
  214. permission: visibility,
  215. }),
  216. );
  217. Swimlanes.insert({
  218. title: 'Default',
  219. boardId: this.boardId.get(),
  220. });
  221. Utils.goBoardId(this.boardId.get());
  222. },
  223. events() {
  224. return [
  225. {
  226. 'click .js-select-visibility'() {
  227. this.setVisibility(this.currentData());
  228. },
  229. 'click .js-change-visibility': this.toggleVisibilityMenu,
  230. 'click .js-import': Popup.open('boardImportBoard'),
  231. submit: this.onSubmit,
  232. 'click .js-import-board': Popup.open('chooseBoardSource'),
  233. 'click .js-board-template': Popup.open('searchElement'),
  234. },
  235. ];
  236. },
  237. }).register('createBoardPopup');
  238. (class HeaderBarCreateBoard extends CreateBoard {
  239. onSubmit(event) {
  240. super.onSubmit(event);
  241. // Immediately star boards crated with the headerbar popup.
  242. Meteor.user().toggleBoardStar(this.boardId.get());
  243. }
  244. }.register('headerBarCreateBoardPopup'));
  245. BlazeComponent.extendComponent({
  246. visibilityCheck() {
  247. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  248. return this.currentData() === currentBoard.permission;
  249. },
  250. selectBoardVisibility() {
  251. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  252. const visibility = this.currentData();
  253. currentBoard.setVisibility(visibility);
  254. Popup.close();
  255. },
  256. events() {
  257. return [
  258. {
  259. 'click .js-select-visibility': this.selectBoardVisibility,
  260. },
  261. ];
  262. },
  263. }).register('boardChangeVisibilityPopup');
  264. BlazeComponent.extendComponent({
  265. watchLevel() {
  266. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  267. return currentBoard.getWatchLevel(Meteor.userId());
  268. },
  269. watchCheck() {
  270. return this.currentData() === this.watchLevel();
  271. },
  272. events() {
  273. return [
  274. {
  275. 'click .js-select-watch'() {
  276. const level = this.currentData();
  277. Meteor.call(
  278. 'watch',
  279. 'board',
  280. Session.get('currentBoard'),
  281. level,
  282. (err, ret) => {
  283. if (!err && ret) Popup.close();
  284. },
  285. );
  286. },
  287. },
  288. ];
  289. },
  290. }).register('boardChangeWatchPopup');
  291. /*
  292. BlazeComponent.extendComponent({
  293. onCreated() {
  294. //this.sortBy = new ReactiveVar();
  295. ////this.sortDirection = new ReactiveVar();
  296. //this.setSortBy();
  297. this.downClass = DOWNCLS;
  298. this.upClass = UPCLS;
  299. },
  300. allowedSortValues() {
  301. const types = [];
  302. const pushed = {};
  303. Meteor.user()
  304. .getListSortTypes()
  305. .forEach(type => {
  306. const key = type.replace(/^-/, '');
  307. if (pushed[key] === undefined) {
  308. types.push({
  309. name: key,
  310. label: `list-label-${key}`,
  311. shortLabel: `list-label-short-${key}`,
  312. });
  313. pushed[key] = 1;
  314. }
  315. });
  316. return types;
  317. },
  318. Direction() {
  319. return Meteor.user().getListSortByDirection() === -1
  320. ? this.downClass
  321. : this.upClass;
  322. },
  323. sortby() {
  324. return Meteor.user().getListSortBy();
  325. },
  326. setSortBy(type = null) {
  327. const user = Meteor.user();
  328. if (type === null) {
  329. type = user._getListSortBy();
  330. } else {
  331. let value = '';
  332. if (type.map) {
  333. // is an array
  334. value = (type[1] === -1 ? '-' : '') + type[0];
  335. }
  336. Meteor.call('setListSortBy', value);
  337. }
  338. //this.sortBy.set(type[0]);
  339. //this.sortDirection.set(type[1]);
  340. },
  341. events() {
  342. return [
  343. {
  344. 'click .js-sort-by'(evt) {
  345. evt.preventDefault();
  346. const target = evt.target;
  347. const sortby = target.getAttribute('name');
  348. const down = !!target.querySelector(`.${this.upClass}`);
  349. const direction = down ? -1 : 1;
  350. this.setSortBy([sortby, direction]);
  351. if (Utils.isMiniScreen) {
  352. Popup.close();
  353. }
  354. },
  355. },
  356. ];
  357. },
  358. }).register('listsortPopup');
  359. */