boardHeader.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. import { Cookies } from 'meteor/ostrio:cookies';
  171. const cookies = new Cookies();
  172. if (cookies.get('boardView') === 'board-view-lists') {
  173. return 'board-view-lists';
  174. } else if (cookies.get('boardView') === 'board-view-swimlanes') {
  175. return 'board-view-swimlanes';
  176. } else if (cookies.get('boardView') === 'board-view-collapse') {
  177. return 'board-view-collapse';
  178. } else if (cookies.get('boardView') === 'board-view-cal') {
  179. return 'board-view-cal';
  180. } else {
  181. return false;
  182. }
  183. },
  184. collapseSwimlane() {
  185. import { Cookies } from 'meteor/ostrio:cookies';
  186. const cookies = new Cookies();
  187. if (cookies.has('collapseSwimlane')) {
  188. return true;
  189. } else {
  190. return false;
  191. }
  192. },
  193. });
  194. Template.boardChangeViewPopup.events({
  195. 'click .js-open-lists-view'() {
  196. import { Cookies } from 'meteor/ostrio:cookies';
  197. const cookies = new Cookies();
  198. if (cookies.get('boardView') !== 'board-view-lists') {
  199. cookies.set('boardView', 'board-view-lists');
  200. const currentUser = Meteor.user();
  201. if (currentUser) {
  202. Meteor.user().setBoardView('board-view-lists');
  203. }
  204. }
  205. Popup.close();
  206. },
  207. 'click .js-open-swimlanes-view'() {
  208. import { Cookies } from 'meteor/ostrio:cookies';
  209. const cookies = new Cookies();
  210. if (cookies.get('boardView') !== 'board-view-swimlanes') {
  211. cookies.set('boardView', 'board-view-swimlanes');
  212. cookies.remove('collapseSwimlane');
  213. const currentUser = Meteor.user();
  214. if (currentUser) {
  215. Meteor.user().setBoardView('board-view-swimlanes');
  216. }
  217. }
  218. Popup.close();
  219. },
  220. 'click .js-open-collapse-view'() {
  221. import { Cookies } from 'meteor/ostrio:cookies';
  222. const cookies = new Cookies();
  223. if (cookies.get('boardView') !== 'board-view-swimlanes') {
  224. cookies.set('boardView', 'board-view-swimlanes');
  225. cookies.set('collapseSwimlane', 'true');
  226. const currentUser = Meteor.user();
  227. if (currentUser) {
  228. Meteor.user().setBoardView('board-view-swimlanes');
  229. }
  230. }
  231. Popup.close();
  232. },
  233. 'click .js-open-cal-view'() {
  234. import { Cookies } from 'meteor/ostrio:cookies';
  235. const cookies = new Cookies();
  236. cookies.set('boardView', 'board-view-cal');
  237. const currentUser = Meteor.user();
  238. if (currentUser) {
  239. Meteor.user().setBoardView('board-view-cal');
  240. }
  241. Popup.close();
  242. },
  243. 'click .js-open-rules-view'() {
  244. Modal.openWide('rulesMain');
  245. Popup.close();
  246. },
  247. });
  248. const CreateBoard = BlazeComponent.extendComponent({
  249. template() {
  250. return 'createBoard';
  251. },
  252. onCreated() {
  253. this.visibilityMenuIsOpen = new ReactiveVar(false);
  254. this.visibility = new ReactiveVar('private');
  255. this.boardId = new ReactiveVar('');
  256. },
  257. visibilityCheck() {
  258. return this.currentData() === this.visibility.get();
  259. },
  260. setVisibility(visibility) {
  261. this.visibility.set(visibility);
  262. this.visibilityMenuIsOpen.set(false);
  263. },
  264. toggleVisibilityMenu() {
  265. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  266. },
  267. onSubmit(event) {
  268. event.preventDefault();
  269. const title = this.find('.js-new-board-title').value;
  270. const visibility = this.visibility.get();
  271. this.boardId.set(
  272. Boards.insert({
  273. title,
  274. permission: visibility,
  275. }),
  276. );
  277. Swimlanes.insert({
  278. title: 'Default',
  279. boardId: this.boardId.get(),
  280. });
  281. Utils.goBoardId(this.boardId.get());
  282. },
  283. events() {
  284. return [
  285. {
  286. 'click .js-select-visibility'() {
  287. this.setVisibility(this.currentData());
  288. },
  289. 'click .js-change-visibility': this.toggleVisibilityMenu,
  290. 'click .js-import': Popup.open('boardImportBoard'),
  291. submit: this.onSubmit,
  292. 'click .js-import-board': Popup.open('chooseBoardSource'),
  293. 'click .js-board-template': Popup.open('searchElement'),
  294. },
  295. ];
  296. },
  297. }).register('createBoardPopup');
  298. (class HeaderBarCreateBoard extends CreateBoard {
  299. onSubmit(event) {
  300. super.onSubmit(event);
  301. // Immediately star boards crated with the headerbar popup.
  302. Meteor.user().toggleBoardStar(this.boardId.get());
  303. }
  304. }.register('headerBarCreateBoardPopup'));
  305. BlazeComponent.extendComponent({
  306. visibilityCheck() {
  307. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  308. return this.currentData() === currentBoard.permission;
  309. },
  310. selectBoardVisibility() {
  311. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  312. const visibility = this.currentData();
  313. currentBoard.setVisibility(visibility);
  314. Popup.close();
  315. },
  316. events() {
  317. return [
  318. {
  319. 'click .js-select-visibility': this.selectBoardVisibility,
  320. },
  321. ];
  322. },
  323. }).register('boardChangeVisibilityPopup');
  324. BlazeComponent.extendComponent({
  325. watchLevel() {
  326. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  327. return currentBoard.getWatchLevel(Meteor.userId());
  328. },
  329. watchCheck() {
  330. return this.currentData() === this.watchLevel();
  331. },
  332. events() {
  333. return [
  334. {
  335. 'click .js-select-watch'() {
  336. const level = this.currentData();
  337. Meteor.call(
  338. 'watch',
  339. 'board',
  340. Session.get('currentBoard'),
  341. level,
  342. (err, ret) => {
  343. if (!err && ret) Popup.close();
  344. },
  345. );
  346. },
  347. },
  348. ];
  349. },
  350. }).register('boardChangeWatchPopup');
  351. /*
  352. BlazeComponent.extendComponent({
  353. onCreated() {
  354. //this.sortBy = new ReactiveVar();
  355. ////this.sortDirection = new ReactiveVar();
  356. //this.setSortBy();
  357. this.downClass = DOWNCLS;
  358. this.upClass = UPCLS;
  359. },
  360. allowedSortValues() {
  361. const types = [];
  362. const pushed = {};
  363. Meteor.user()
  364. .getListSortTypes()
  365. .forEach(type => {
  366. const key = type.replace(/^-/, '');
  367. if (pushed[key] === undefined) {
  368. types.push({
  369. name: key,
  370. label: `list-label-${key}`,
  371. shortLabel: `list-label-short-${key}`,
  372. });
  373. pushed[key] = 1;
  374. }
  375. });
  376. return types;
  377. },
  378. Direction() {
  379. return Meteor.user().getListSortByDirection() === -1
  380. ? this.downClass
  381. : this.upClass;
  382. },
  383. sortby() {
  384. return Meteor.user().getListSortBy();
  385. },
  386. setSortBy(type = null) {
  387. const user = Meteor.user();
  388. if (type === null) {
  389. type = user._getListSortBy();
  390. } else {
  391. let value = '';
  392. if (type.map) {
  393. // is an array
  394. value = (type[1] === -1 ? '-' : '') + type[0];
  395. }
  396. Meteor.call('setListSortBy', value);
  397. }
  398. //this.sortBy.set(type[0]);
  399. //this.sortDirection.set(type[1]);
  400. },
  401. events() {
  402. return [
  403. {
  404. 'click .js-sort-by'(evt) {
  405. evt.preventDefault();
  406. const target = evt.target;
  407. const sortby = target.getAttribute('name');
  408. const down = !!target.querySelector(`.${this.upClass}`);
  409. const direction = down ? -1 : 1;
  410. this.setSortBy([sortby, direction]);
  411. if (Utils.isMiniScreen) {
  412. Popup.close();
  413. }
  414. },
  415. },
  416. ];
  417. },
  418. }).register('listsortPopup');
  419. */