boardHeader.js 12 KB

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