2
0

boardHeader.js 13 KB

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