2
0

boardHeader.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import dragscroll from '@wekanteam/dragscroll';
  4. /*
  5. const DOWNCLS = 'fa-sort-down';
  6. const UPCLS = 'fa-sort-up';
  7. */
  8. const sortCardsBy = new ReactiveVar('');
  9. Template.boardChangeTitlePopup.events({
  10. submit(event, templateInstance) {
  11. const newTitle = templateInstance
  12. .$('.js-board-name')
  13. .val()
  14. .trim();
  15. const newDesc = templateInstance
  16. .$('.js-board-desc')
  17. .val()
  18. .trim();
  19. if (newTitle) {
  20. this.rename(newTitle);
  21. this.setDescription(newDesc);
  22. Popup.back();
  23. }
  24. event.preventDefault();
  25. },
  26. });
  27. BlazeComponent.extendComponent({
  28. watchLevel() {
  29. const currentBoard = Utils.getCurrentBoard();
  30. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  31. },
  32. isStarred() {
  33. const boardId = Session.get('currentBoard');
  34. const user = ReactiveCache.getCurrentUser();
  35. return user && user.hasStarred(boardId);
  36. },
  37. // Only show the star counter if the number of star is greater than 2
  38. showStarCounter() {
  39. const currentBoard = Utils.getCurrentBoard();
  40. return currentBoard && currentBoard.stars >= 2;
  41. },
  42. /*
  43. showSort() {
  44. return ReactiveCache.getCurrentUser().hasSortBy();
  45. },
  46. directionClass() {
  47. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  48. },
  49. changeDirection() {
  50. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  51. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  52. },
  53. currentDirection() {
  54. return ReactiveCache.getCurrentUser().getListSortByDirection();
  55. },
  56. currentListSortBy() {
  57. return ReactiveCache.getCurrentUser().getListSortBy();
  58. },
  59. listSortShortDesc() {
  60. return `list-label-short-${this.currentListSortBy()}`;
  61. },
  62. */
  63. events() {
  64. return [
  65. {
  66. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  67. 'click .js-star-board'() {
  68. ReactiveCache.getCurrentUser().toggleBoardStar(Session.get('currentBoard'));
  69. },
  70. 'click .js-open-board-menu': Popup.open('boardMenu'),
  71. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  72. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  73. 'click .js-open-archived-board'() {
  74. Modal.open('archivedBoards');
  75. },
  76. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  77. 'click .js-toggle-sidebar'() {
  78. Sidebar.toggle();
  79. },
  80. 'click .js-open-filter-view'() {
  81. Sidebar.setView('filter');
  82. },
  83. 'click .js-sort-cards': Popup.open('cardsSort'),
  84. /*
  85. 'click .js-open-sort-view'(evt) {
  86. const target = evt.target;
  87. if (target.tagName === 'I') {
  88. // click on the text, popup choices
  89. this.changeDirection();
  90. } else {
  91. // change the sort order
  92. Popup.open('listsort')(evt);
  93. }
  94. },
  95. */
  96. 'click .js-filter-reset'(event) {
  97. event.stopPropagation();
  98. Sidebar.setView();
  99. Filter.reset();
  100. },
  101. 'click .js-sort-reset'() {
  102. Session.set('sortBy', '');
  103. },
  104. 'click .js-open-search-view'() {
  105. Sidebar.setView('search');
  106. },
  107. 'click .js-multiselection-activate'() {
  108. const currentCard = Utils.getCurrentCardId();
  109. MultiSelection.activate();
  110. if (currentCard) {
  111. MultiSelection.add(currentCard);
  112. }
  113. },
  114. 'click .js-multiselection-reset'(event) {
  115. event.stopPropagation();
  116. MultiSelection.disable();
  117. },
  118. 'click .js-log-in'() {
  119. FlowRouter.go('atSignIn');
  120. },
  121. },
  122. ];
  123. },
  124. }).register('boardHeaderBar');
  125. Template.boardHeaderBar.helpers({
  126. boardView() {
  127. return Utils.boardView();
  128. },
  129. isSortActive() {
  130. return Session.get('sortBy') ? true : false;
  131. },
  132. });
  133. Template.boardChangeViewPopup.events({
  134. 'click .js-open-lists-view'() {
  135. Utils.setBoardView('board-view-lists');
  136. Popup.back();
  137. },
  138. 'click .js-open-swimlanes-view'() {
  139. Utils.setBoardView('board-view-swimlanes');
  140. Popup.back();
  141. },
  142. 'click .js-open-cal-view'() {
  143. Utils.setBoardView('board-view-cal');
  144. Popup.back();
  145. },
  146. });
  147. const CreateBoard = BlazeComponent.extendComponent({
  148. template() {
  149. return 'createBoard';
  150. },
  151. onCreated() {
  152. this.visibilityMenuIsOpen = new ReactiveVar(false);
  153. this.visibility = new ReactiveVar('private');
  154. this.boardId = new ReactiveVar('');
  155. Meteor.subscribe('tableVisibilityModeSettings');
  156. },
  157. notAllowPrivateVisibilityOnly(){
  158. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  159. },
  160. visibilityCheck() {
  161. return this.currentData() === this.visibility.get();
  162. },
  163. setVisibility(visibility) {
  164. this.visibility.set(visibility);
  165. this.visibilityMenuIsOpen.set(false);
  166. },
  167. toggleVisibilityMenu() {
  168. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  169. },
  170. toggleAddTemplateContainer() {
  171. $('#add-template-container').toggleClass('is-checked');
  172. },
  173. onSubmit(event) {
  174. event.preventDefault();
  175. const title = this.find('.js-new-board-title').value;
  176. const addTemplateContainer = $('#add-template-container.is-checked').length > 0;
  177. if (addTemplateContainer) {
  178. //const templateContainerId = Meteor.call('setCreateTemplateContainer');
  179. //Utils.goBoardId(templateContainerId);
  180. //alert('niinku template ' + Meteor.call('setCreateTemplateContainer'));
  181. this.boardId.set(
  182. Boards.insert({
  183. // title: TAPi18n.__('templates'),
  184. title: title,
  185. permission: 'private',
  186. type: 'template-container',
  187. }),
  188. );
  189. // Insert the card templates swimlane
  190. Swimlanes.insert({
  191. // title: TAPi18n.__('card-templates-swimlane'),
  192. title: 'Card Templates',
  193. boardId: this.boardId.get(),
  194. sort: 1,
  195. type: 'template-container',
  196. }),
  197. // Insert the list templates swimlane
  198. Swimlanes.insert(
  199. {
  200. // title: TAPi18n.__('list-templates-swimlane'),
  201. title: 'List Templates',
  202. boardId: this.boardId.get(),
  203. sort: 2,
  204. type: 'template-container',
  205. },
  206. );
  207. // Insert the board templates swimlane
  208. Swimlanes.insert(
  209. {
  210. //title: TAPi18n.__('board-templates-swimlane'),
  211. title: 'Board Templates',
  212. boardId: this.boardId.get(),
  213. sort: 3,
  214. type: 'template-container',
  215. },
  216. );
  217. Utils.goBoardId(this.boardId.get());
  218. } else {
  219. const visibility = this.visibility.get();
  220. this.boardId.set(
  221. Boards.insert({
  222. title,
  223. permission: visibility,
  224. }),
  225. );
  226. Swimlanes.insert({
  227. title: 'Default',
  228. boardId: this.boardId.get(),
  229. });
  230. Utils.goBoardId(this.boardId.get());
  231. }
  232. },
  233. events() {
  234. return [
  235. {
  236. 'click .js-select-visibility'() {
  237. this.setVisibility(this.currentData());
  238. },
  239. 'click .js-change-visibility': this.toggleVisibilityMenu,
  240. 'click .js-import': Popup.open('boardImportBoard'),
  241. submit: this.onSubmit,
  242. 'click .js-import-board': Popup.open('chooseBoardSource'),
  243. 'click .js-board-template': Popup.open('searchElement'),
  244. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  245. },
  246. ];
  247. },
  248. }).register('createBoardPopup');
  249. (class HeaderBarCreateBoard extends CreateBoard {
  250. onSubmit(event) {
  251. super.onSubmit(event);
  252. // Immediately star boards crated with the headerbar popup.
  253. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  254. }
  255. }.register('headerBarCreateBoardPopup'));
  256. BlazeComponent.extendComponent({
  257. notAllowPrivateVisibilityOnly(){
  258. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  259. },
  260. visibilityCheck() {
  261. const currentBoard = Utils.getCurrentBoard();
  262. return this.currentData() === currentBoard.permission;
  263. },
  264. selectBoardVisibility() {
  265. const currentBoard = Utils.getCurrentBoard();
  266. const visibility = this.currentData();
  267. currentBoard.setVisibility(visibility);
  268. Popup.back();
  269. },
  270. events() {
  271. return [
  272. {
  273. 'click .js-select-visibility': this.selectBoardVisibility,
  274. },
  275. ];
  276. },
  277. }).register('boardChangeVisibilityPopup');
  278. BlazeComponent.extendComponent({
  279. watchLevel() {
  280. const currentBoard = Utils.getCurrentBoard();
  281. return currentBoard.getWatchLevel(Meteor.userId());
  282. },
  283. watchCheck() {
  284. return this.currentData() === this.watchLevel();
  285. },
  286. events() {
  287. return [
  288. {
  289. 'click .js-select-watch'() {
  290. const level = this.currentData();
  291. Meteor.call(
  292. 'watch',
  293. 'board',
  294. Session.get('currentBoard'),
  295. level,
  296. (err, ret) => {
  297. if (!err && ret) Popup.back();
  298. },
  299. );
  300. },
  301. },
  302. ];
  303. },
  304. }).register('boardChangeWatchPopup');
  305. /*
  306. BlazeComponent.extendComponent({
  307. onCreated() {
  308. //this.sortBy = new ReactiveVar();
  309. ////this.sortDirection = new ReactiveVar();
  310. //this.setSortBy();
  311. this.downClass = DOWNCLS;
  312. this.upClass = UPCLS;
  313. },
  314. allowedSortValues() {
  315. const types = [];
  316. const pushed = {};
  317. ReactiveCache.getCurrentUser()
  318. .getListSortTypes()
  319. .forEach(type => {
  320. const key = type.replace(/^-/, '');
  321. if (pushed[key] === undefined) {
  322. types.push({
  323. name: key,
  324. label: `list-label-${key}`,
  325. shortLabel: `list-label-short-${key}`,
  326. });
  327. pushed[key] = 1;
  328. }
  329. });
  330. return types;
  331. },
  332. Direction() {
  333. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  334. ? this.downClass
  335. : this.upClass;
  336. },
  337. sortby() {
  338. return ReactiveCache.getCurrentUser().getListSortBy();
  339. },
  340. setSortBy(type = null) {
  341. const user = ReactiveCache.getCurrentUser();
  342. if (type === null) {
  343. type = user._getListSortBy();
  344. } else {
  345. let value = '';
  346. if (type.map) {
  347. // is an array
  348. value = (type[1] === -1 ? '-' : '') + type[0];
  349. }
  350. Meteor.call('setListSortBy', value);
  351. }
  352. //this.sortBy.set(type[0]);
  353. //this.sortDirection.set(type[1]);
  354. },
  355. events() {
  356. return [
  357. {
  358. 'click .js-sort-by'(evt) {
  359. evt.preventDefault();
  360. const target = evt.target;
  361. const sortby = target.getAttribute('name');
  362. const down = !!target.querySelector(`.${this.upClass}`);
  363. const direction = down ? -1 : 1;
  364. this.setSortBy([sortby, direction]);
  365. if (Utils.isMiniScreen) {
  366. Popup.back();
  367. }
  368. },
  369. },
  370. ];
  371. },
  372. }).register('listsortPopup');
  373. */
  374. BlazeComponent.extendComponent({
  375. events() {
  376. return [
  377. {
  378. 'click .js-sort-due'() {
  379. const sortBy = {
  380. dueAt: 1,
  381. };
  382. Session.set('sortBy', sortBy);
  383. sortCardsBy.set(TAPi18n.__('due-date'));
  384. Popup.back();
  385. },
  386. 'click .js-sort-title'() {
  387. const sortBy = {
  388. title: 1,
  389. };
  390. Session.set('sortBy', sortBy);
  391. sortCardsBy.set(TAPi18n.__('title'));
  392. Popup.back();
  393. },
  394. 'click .js-sort-created-asc'() {
  395. const sortBy = {
  396. createdAt: 1,
  397. };
  398. Session.set('sortBy', sortBy);
  399. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  400. Popup.back();
  401. },
  402. 'click .js-sort-created-desc'() {
  403. const sortBy = {
  404. createdAt: -1,
  405. };
  406. Session.set('sortBy', sortBy);
  407. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  408. Popup.back();
  409. },
  410. },
  411. ];
  412. },
  413. }).register('cardsSortPopup');