2
0

boardHeader.js 12 KB

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