boardHeader.js 13 KB

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