boardHeader.js 10 KB

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