boardHeader.js 13 KB

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