boardHeader.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. 'click .js-open-rules-view'() {
  188. Modal.openWide('rulesMain');
  189. Popup.close();
  190. },
  191. });
  192. const CreateBoard = BlazeComponent.extendComponent({
  193. template() {
  194. return 'createBoard';
  195. },
  196. onCreated() {
  197. this.visibilityMenuIsOpen = new ReactiveVar(false);
  198. this.visibility = new ReactiveVar('private');
  199. this.boardId = new ReactiveVar('');
  200. },
  201. visibilityCheck() {
  202. return this.currentData() === this.visibility.get();
  203. },
  204. setVisibility(visibility) {
  205. this.visibility.set(visibility);
  206. this.visibilityMenuIsOpen.set(false);
  207. },
  208. toggleVisibilityMenu() {
  209. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  210. },
  211. onSubmit(event) {
  212. event.preventDefault();
  213. const title = this.find('.js-new-board-title').value;
  214. const visibility = this.visibility.get();
  215. this.boardId.set(
  216. Boards.insert({
  217. title,
  218. permission: visibility,
  219. }),
  220. );
  221. Swimlanes.insert({
  222. title: 'Default',
  223. boardId: this.boardId.get(),
  224. });
  225. Utils.goBoardId(this.boardId.get());
  226. },
  227. events() {
  228. return [
  229. {
  230. 'click .js-select-visibility'() {
  231. this.setVisibility(this.currentData());
  232. },
  233. 'click .js-change-visibility': this.toggleVisibilityMenu,
  234. 'click .js-import': Popup.open('boardImportBoard'),
  235. submit: this.onSubmit,
  236. 'click .js-import-board': Popup.open('chooseBoardSource'),
  237. 'click .js-board-template': Popup.open('searchElement'),
  238. },
  239. ];
  240. },
  241. }).register('createBoardPopup');
  242. (class HeaderBarCreateBoard extends CreateBoard {
  243. onSubmit(event) {
  244. super.onSubmit(event);
  245. // Immediately star boards crated with the headerbar popup.
  246. Meteor.user().toggleBoardStar(this.boardId.get());
  247. }
  248. }.register('headerBarCreateBoardPopup'));
  249. BlazeComponent.extendComponent({
  250. visibilityCheck() {
  251. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  252. return this.currentData() === currentBoard.permission;
  253. },
  254. selectBoardVisibility() {
  255. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  256. const visibility = this.currentData();
  257. currentBoard.setVisibility(visibility);
  258. Popup.close();
  259. },
  260. events() {
  261. return [
  262. {
  263. 'click .js-select-visibility': this.selectBoardVisibility,
  264. },
  265. ];
  266. },
  267. }).register('boardChangeVisibilityPopup');
  268. BlazeComponent.extendComponent({
  269. watchLevel() {
  270. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  271. return currentBoard.getWatchLevel(Meteor.userId());
  272. },
  273. watchCheck() {
  274. return this.currentData() === this.watchLevel();
  275. },
  276. events() {
  277. return [
  278. {
  279. 'click .js-select-watch'() {
  280. const level = this.currentData();
  281. Meteor.call(
  282. 'watch',
  283. 'board',
  284. Session.get('currentBoard'),
  285. level,
  286. (err, ret) => {
  287. if (!err && ret) Popup.close();
  288. },
  289. );
  290. },
  291. },
  292. ];
  293. },
  294. }).register('boardChangeWatchPopup');
  295. /*
  296. BlazeComponent.extendComponent({
  297. onCreated() {
  298. //this.sortBy = new ReactiveVar();
  299. ////this.sortDirection = new ReactiveVar();
  300. //this.setSortBy();
  301. this.downClass = DOWNCLS;
  302. this.upClass = UPCLS;
  303. },
  304. allowedSortValues() {
  305. const types = [];
  306. const pushed = {};
  307. Meteor.user()
  308. .getListSortTypes()
  309. .forEach(type => {
  310. const key = type.replace(/^-/, '');
  311. if (pushed[key] === undefined) {
  312. types.push({
  313. name: key,
  314. label: `list-label-${key}`,
  315. shortLabel: `list-label-short-${key}`,
  316. });
  317. pushed[key] = 1;
  318. }
  319. });
  320. return types;
  321. },
  322. Direction() {
  323. return Meteor.user().getListSortByDirection() === -1
  324. ? this.downClass
  325. : this.upClass;
  326. },
  327. sortby() {
  328. return Meteor.user().getListSortBy();
  329. },
  330. setSortBy(type = null) {
  331. const user = Meteor.user();
  332. if (type === null) {
  333. type = user._getListSortBy();
  334. } else {
  335. let value = '';
  336. if (type.map) {
  337. // is an array
  338. value = (type[1] === -1 ? '-' : '') + type[0];
  339. }
  340. Meteor.call('setListSortBy', value);
  341. }
  342. //this.sortBy.set(type[0]);
  343. //this.sortDirection.set(type[1]);
  344. },
  345. events() {
  346. return [
  347. {
  348. 'click .js-sort-by'(evt) {
  349. evt.preventDefault();
  350. const target = evt.target;
  351. const sortby = target.getAttribute('name');
  352. const down = !!target.querySelector(`.${this.upClass}`);
  353. const direction = down ? -1 : 1;
  354. this.setSortBy([sortby, direction]);
  355. if (Utils.isMiniScreen) {
  356. Popup.close();
  357. }
  358. },
  359. },
  360. ];
  361. },
  362. }).register('listsortPopup');
  363. */