boardHeader.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. const DOWNCLS = 'fa-sort-down';
  3. const UPCLS = 'fa-sort-up';
  4. */
  5. const sortCardsBy = new ReactiveVar('');
  6. Template.boardMenuPopup.events({
  7. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  8. 'click .js-custom-fields'() {
  9. Sidebar.setView('customFields');
  10. Popup.close();
  11. },
  12. 'click .js-open-archives'() {
  13. Sidebar.setView('archives');
  14. Popup.close();
  15. },
  16. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  17. 'click .js-change-language': Popup.open('changeLanguage'),
  18. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  19. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  20. currentBoard.archive();
  21. // XXX We should have some kind of notification on top of the page to
  22. // confirm that the board was successfully archived.
  23. FlowRouter.go('home');
  24. }),
  25. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  26. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  27. Popup.close();
  28. Boards.remove(currentBoard._id);
  29. FlowRouter.go('home');
  30. }),
  31. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  32. 'click .js-import-board': Popup.open('chooseBoardSource'),
  33. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  34. 'click .js-card-settings': Popup.open('boardCardSettings'),
  35. });
  36. Template.boardChangeTitlePopup.events({
  37. submit(event, templateInstance) {
  38. const newTitle = templateInstance
  39. .$('.js-board-name')
  40. .val()
  41. .trim();
  42. const newDesc = templateInstance
  43. .$('.js-board-desc')
  44. .val()
  45. .trim();
  46. if (newTitle) {
  47. this.rename(newTitle);
  48. this.setDescription(newDesc);
  49. Popup.close();
  50. }
  51. event.preventDefault();
  52. },
  53. });
  54. BlazeComponent.extendComponent({
  55. watchLevel() {
  56. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  57. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  58. },
  59. isStarred() {
  60. const boardId = Session.get('currentBoard');
  61. const user = Meteor.user();
  62. return user && user.hasStarred(boardId);
  63. },
  64. // Only show the star counter if the number of star is greater than 2
  65. showStarCounter() {
  66. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  67. return currentBoard && currentBoard.stars >= 2;
  68. },
  69. /*
  70. showSort() {
  71. return Meteor.user().hasSortBy();
  72. },
  73. directionClass() {
  74. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  75. },
  76. changeDirection() {
  77. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  78. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  79. },
  80. currentDirection() {
  81. return Meteor.user().getListSortByDirection();
  82. },
  83. currentListSortBy() {
  84. return Meteor.user().getListSortBy();
  85. },
  86. listSortShortDesc() {
  87. return `list-label-short-${this.currentListSortBy()}`;
  88. },
  89. */
  90. events() {
  91. return [
  92. {
  93. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  94. 'click .js-star-board'() {
  95. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  96. },
  97. 'click .js-open-board-menu': Popup.open('boardMenu'),
  98. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  99. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  100. 'click .js-open-archived-board'() {
  101. Modal.open('archivedBoards');
  102. },
  103. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  104. 'click .js-toggle-sidebar'() {
  105. Sidebar.toggle();
  106. },
  107. 'click .js-open-filter-view'() {
  108. Sidebar.setView('filter');
  109. },
  110. 'click .js-sort-cards': Popup.open('cardsSort'),
  111. /*
  112. 'click .js-open-sort-view'(evt) {
  113. const target = evt.target;
  114. if (target.tagName === 'I') {
  115. // click on the text, popup choices
  116. this.changeDirection();
  117. } else {
  118. // change the sort order
  119. Popup.open('listsort')(evt);
  120. }
  121. },
  122. */
  123. 'click .js-filter-reset'(event) {
  124. event.stopPropagation();
  125. Sidebar.setView();
  126. Filter.reset();
  127. },
  128. 'click .js-sort-reset'() {
  129. Session.set('sortBy', '');
  130. },
  131. 'click .js-open-search-view'() {
  132. Sidebar.setView('search');
  133. },
  134. 'click .js-multiselection-activate'() {
  135. const currentCard = Session.get('currentCard');
  136. MultiSelection.activate();
  137. if (currentCard) {
  138. MultiSelection.add(currentCard);
  139. }
  140. },
  141. 'click .js-multiselection-reset'(event) {
  142. event.stopPropagation();
  143. MultiSelection.disable();
  144. },
  145. 'click .js-log-in'() {
  146. FlowRouter.go('atSignIn');
  147. },
  148. },
  149. ];
  150. },
  151. }).register('boardHeaderBar');
  152. Template.boardHeaderBar.helpers({
  153. canModifyBoard() {
  154. return (
  155. Meteor.user() &&
  156. Meteor.user().isBoardMember() &&
  157. !Meteor.user().isCommentOnly()
  158. );
  159. },
  160. boardView() {
  161. return Utils.boardView();
  162. },
  163. isSortActive() {
  164. return Session.get('sortBy') ? true : false;
  165. },
  166. });
  167. Template.boardChangeViewPopup.events({
  168. 'click .js-open-lists-view'() {
  169. Utils.setBoardView('board-view-lists');
  170. Popup.close();
  171. },
  172. 'click .js-open-swimlanes-view'() {
  173. Utils.setBoardView('board-view-swimlanes');
  174. Popup.close();
  175. },
  176. 'click .js-open-cal-view'() {
  177. Utils.setBoardView('board-view-cal');
  178. Popup.close();
  179. },
  180. });
  181. const CreateBoard = BlazeComponent.extendComponent({
  182. template() {
  183. return 'createBoard';
  184. },
  185. onCreated() {
  186. this.visibilityMenuIsOpen = new ReactiveVar(false);
  187. this.visibility = new ReactiveVar('private');
  188. this.boardId = new ReactiveVar('');
  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. Meteor.user().toggleBoardStar(this.boardId.get());
  284. }
  285. }.register('headerBarCreateBoardPopup'));
  286. BlazeComponent.extendComponent({
  287. visibilityCheck() {
  288. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  289. return this.currentData() === currentBoard.permission;
  290. },
  291. selectBoardVisibility() {
  292. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  293. const visibility = this.currentData();
  294. currentBoard.setVisibility(visibility);
  295. Popup.close();
  296. },
  297. events() {
  298. return [
  299. {
  300. 'click .js-select-visibility': this.selectBoardVisibility,
  301. },
  302. ];
  303. },
  304. }).register('boardChangeVisibilityPopup');
  305. BlazeComponent.extendComponent({
  306. watchLevel() {
  307. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  308. return currentBoard.getWatchLevel(Meteor.userId());
  309. },
  310. watchCheck() {
  311. return this.currentData() === this.watchLevel();
  312. },
  313. events() {
  314. return [
  315. {
  316. 'click .js-select-watch'() {
  317. const level = this.currentData();
  318. Meteor.call(
  319. 'watch',
  320. 'board',
  321. Session.get('currentBoard'),
  322. level,
  323. (err, ret) => {
  324. if (!err && ret) Popup.close();
  325. },
  326. );
  327. },
  328. },
  329. ];
  330. },
  331. }).register('boardChangeWatchPopup');
  332. /*
  333. BlazeComponent.extendComponent({
  334. onCreated() {
  335. //this.sortBy = new ReactiveVar();
  336. ////this.sortDirection = new ReactiveVar();
  337. //this.setSortBy();
  338. this.downClass = DOWNCLS;
  339. this.upClass = UPCLS;
  340. },
  341. allowedSortValues() {
  342. const types = [];
  343. const pushed = {};
  344. Meteor.user()
  345. .getListSortTypes()
  346. .forEach(type => {
  347. const key = type.replace(/^-/, '');
  348. if (pushed[key] === undefined) {
  349. types.push({
  350. name: key,
  351. label: `list-label-${key}`,
  352. shortLabel: `list-label-short-${key}`,
  353. });
  354. pushed[key] = 1;
  355. }
  356. });
  357. return types;
  358. },
  359. Direction() {
  360. return Meteor.user().getListSortByDirection() === -1
  361. ? this.downClass
  362. : this.upClass;
  363. },
  364. sortby() {
  365. return Meteor.user().getListSortBy();
  366. },
  367. setSortBy(type = null) {
  368. const user = Meteor.user();
  369. if (type === null) {
  370. type = user._getListSortBy();
  371. } else {
  372. let value = '';
  373. if (type.map) {
  374. // is an array
  375. value = (type[1] === -1 ? '-' : '') + type[0];
  376. }
  377. Meteor.call('setListSortBy', value);
  378. }
  379. //this.sortBy.set(type[0]);
  380. //this.sortDirection.set(type[1]);
  381. },
  382. events() {
  383. return [
  384. {
  385. 'click .js-sort-by'(evt) {
  386. evt.preventDefault();
  387. const target = evt.target;
  388. const sortby = target.getAttribute('name');
  389. const down = !!target.querySelector(`.${this.upClass}`);
  390. const direction = down ? -1 : 1;
  391. this.setSortBy([sortby, direction]);
  392. if (Utils.isMiniScreen) {
  393. Popup.close();
  394. }
  395. },
  396. },
  397. ];
  398. },
  399. }).register('listsortPopup');
  400. */
  401. BlazeComponent.extendComponent({
  402. events() {
  403. return [
  404. {
  405. 'click .js-sort-due'() {
  406. const sortBy = {
  407. dueAt: 1,
  408. };
  409. Session.set('sortBy', sortBy);
  410. sortCardsBy.set(TAPi18n.__('due-date'));
  411. Popup.close();
  412. },
  413. 'click .js-sort-title'() {
  414. const sortBy = {
  415. title: 1,
  416. };
  417. Session.set('sortBy', sortBy);
  418. sortCardsBy.set(TAPi18n.__('title'));
  419. Popup.close();
  420. },
  421. 'click .js-sort-created-asc'() {
  422. const sortBy = {
  423. createdAt: 1,
  424. };
  425. Session.set('sortBy', sortBy);
  426. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  427. Popup.close();
  428. },
  429. 'click .js-sort-created-desc'() {
  430. const sortBy = {
  431. createdAt: -1,
  432. };
  433. Session.set('sortBy', sortBy);
  434. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  435. Popup.close();
  436. },
  437. },
  438. ];
  439. },
  440. }).register('cardsSortPopup');