boardHeader.js 10 KB

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