boardHeader.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. onCreated() {
  56. // set sort to default
  57. Session.set('sortBy', '');
  58. },
  59. watchLevel() {
  60. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  61. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  62. },
  63. isStarred() {
  64. const boardId = Session.get('currentBoard');
  65. const user = Meteor.user();
  66. return user && user.hasStarred(boardId);
  67. },
  68. // Only show the star counter if the number of star is greater than 2
  69. showStarCounter() {
  70. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  71. return currentBoard && currentBoard.stars >= 2;
  72. },
  73. /*
  74. showSort() {
  75. return Meteor.user().hasSortBy();
  76. },
  77. directionClass() {
  78. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  79. },
  80. changeDirection() {
  81. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  82. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  83. },
  84. currentDirection() {
  85. return Meteor.user().getListSortByDirection();
  86. },
  87. currentListSortBy() {
  88. return Meteor.user().getListSortBy();
  89. },
  90. listSortShortDesc() {
  91. return `list-label-short-${this.currentListSortBy()}`;
  92. },
  93. */
  94. events() {
  95. return [
  96. {
  97. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  98. 'click .js-star-board'() {
  99. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  100. },
  101. 'click .js-open-board-menu': Popup.open('boardMenu'),
  102. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  103. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  104. 'click .js-open-archived-board'() {
  105. Modal.open('archivedBoards');
  106. },
  107. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  108. 'click .js-toggle-sidebar'() {
  109. Sidebar.toggle();
  110. },
  111. 'click .js-open-filter-view'() {
  112. Sidebar.setView('filter');
  113. },
  114. 'click .js-sort-cards': Popup.open('cardsSort'),
  115. /*
  116. 'click .js-open-sort-view'(evt) {
  117. const target = evt.target;
  118. if (target.tagName === 'I') {
  119. // click on the text, popup choices
  120. this.changeDirection();
  121. } else {
  122. // change the sort order
  123. Popup.open('listsort')(evt);
  124. }
  125. },
  126. */
  127. 'click .js-filter-reset'(event) {
  128. event.stopPropagation();
  129. Sidebar.setView();
  130. Filter.reset();
  131. },
  132. 'click .js-sort-reset'() {
  133. Session.set('sortBy', '');
  134. },
  135. 'click .js-open-search-view'() {
  136. Sidebar.setView('search');
  137. },
  138. 'click .js-multiselection-activate'() {
  139. const currentCard = Session.get('currentCard');
  140. MultiSelection.activate();
  141. if (currentCard) {
  142. MultiSelection.add(currentCard);
  143. }
  144. },
  145. 'click .js-multiselection-reset'(event) {
  146. event.stopPropagation();
  147. MultiSelection.disable();
  148. },
  149. 'click .js-log-in'() {
  150. FlowRouter.go('atSignIn');
  151. },
  152. },
  153. ];
  154. },
  155. }).register('boardHeaderBar');
  156. Template.boardHeaderBar.helpers({
  157. canModifyBoard() {
  158. return (
  159. Meteor.user() &&
  160. Meteor.user().isBoardMember() &&
  161. !Meteor.user().isCommentOnly()
  162. );
  163. },
  164. boardView() {
  165. return Utils.boardView();
  166. },
  167. isSortActive() {
  168. return Session.get('sortBy') ? true : false;
  169. },
  170. });
  171. Template.boardChangeViewPopup.events({
  172. 'click .js-open-lists-view'() {
  173. Utils.setBoardView('board-view-lists');
  174. Popup.close();
  175. },
  176. 'click .js-open-swimlanes-view'() {
  177. Utils.setBoardView('board-view-swimlanes');
  178. Popup.close();
  179. },
  180. 'click .js-open-cal-view'() {
  181. Utils.setBoardView('board-view-cal');
  182. Popup.close();
  183. },
  184. });
  185. const CreateBoard = BlazeComponent.extendComponent({
  186. template() {
  187. return 'createBoard';
  188. },
  189. onCreated() {
  190. this.visibilityMenuIsOpen = new ReactiveVar(false);
  191. this.visibility = new ReactiveVar('private');
  192. this.boardId = new ReactiveVar('');
  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. onSubmit(event) {
  205. event.preventDefault();
  206. const title = this.find('.js-new-board-title').value;
  207. const visibility = this.visibility.get();
  208. this.boardId.set(
  209. Boards.insert({
  210. title,
  211. permission: visibility,
  212. }),
  213. );
  214. Swimlanes.insert({
  215. title: 'Default',
  216. boardId: this.boardId.get(),
  217. });
  218. Utils.goBoardId(this.boardId.get());
  219. },
  220. events() {
  221. return [
  222. {
  223. 'click .js-select-visibility'() {
  224. this.setVisibility(this.currentData());
  225. },
  226. 'click .js-change-visibility': this.toggleVisibilityMenu,
  227. 'click .js-import': Popup.open('boardImportBoard'),
  228. submit: this.onSubmit,
  229. 'click .js-import-board': Popup.open('chooseBoardSource'),
  230. 'click .js-board-template': Popup.open('searchElement'),
  231. },
  232. ];
  233. },
  234. }).register('createBoardPopup');
  235. (class HeaderBarCreateBoard extends CreateBoard {
  236. onSubmit(event) {
  237. super.onSubmit(event);
  238. // Immediately star boards crated with the headerbar popup.
  239. Meteor.user().toggleBoardStar(this.boardId.get());
  240. }
  241. }.register('headerBarCreateBoardPopup'));
  242. BlazeComponent.extendComponent({
  243. visibilityCheck() {
  244. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  245. return this.currentData() === currentBoard.permission;
  246. },
  247. selectBoardVisibility() {
  248. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  249. const visibility = this.currentData();
  250. currentBoard.setVisibility(visibility);
  251. Popup.close();
  252. },
  253. events() {
  254. return [
  255. {
  256. 'click .js-select-visibility': this.selectBoardVisibility,
  257. },
  258. ];
  259. },
  260. }).register('boardChangeVisibilityPopup');
  261. BlazeComponent.extendComponent({
  262. watchLevel() {
  263. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  264. return currentBoard.getWatchLevel(Meteor.userId());
  265. },
  266. watchCheck() {
  267. return this.currentData() === this.watchLevel();
  268. },
  269. events() {
  270. return [
  271. {
  272. 'click .js-select-watch'() {
  273. const level = this.currentData();
  274. Meteor.call(
  275. 'watch',
  276. 'board',
  277. Session.get('currentBoard'),
  278. level,
  279. (err, ret) => {
  280. if (!err && ret) Popup.close();
  281. },
  282. );
  283. },
  284. },
  285. ];
  286. },
  287. }).register('boardChangeWatchPopup');
  288. /*
  289. BlazeComponent.extendComponent({
  290. onCreated() {
  291. //this.sortBy = new ReactiveVar();
  292. ////this.sortDirection = new ReactiveVar();
  293. //this.setSortBy();
  294. this.downClass = DOWNCLS;
  295. this.upClass = UPCLS;
  296. },
  297. allowedSortValues() {
  298. const types = [];
  299. const pushed = {};
  300. Meteor.user()
  301. .getListSortTypes()
  302. .forEach(type => {
  303. const key = type.replace(/^-/, '');
  304. if (pushed[key] === undefined) {
  305. types.push({
  306. name: key,
  307. label: `list-label-${key}`,
  308. shortLabel: `list-label-short-${key}`,
  309. });
  310. pushed[key] = 1;
  311. }
  312. });
  313. return types;
  314. },
  315. Direction() {
  316. return Meteor.user().getListSortByDirection() === -1
  317. ? this.downClass
  318. : this.upClass;
  319. },
  320. sortby() {
  321. return Meteor.user().getListSortBy();
  322. },
  323. setSortBy(type = null) {
  324. const user = Meteor.user();
  325. if (type === null) {
  326. type = user._getListSortBy();
  327. } else {
  328. let value = '';
  329. if (type.map) {
  330. // is an array
  331. value = (type[1] === -1 ? '-' : '') + type[0];
  332. }
  333. Meteor.call('setListSortBy', value);
  334. }
  335. //this.sortBy.set(type[0]);
  336. //this.sortDirection.set(type[1]);
  337. },
  338. events() {
  339. return [
  340. {
  341. 'click .js-sort-by'(evt) {
  342. evt.preventDefault();
  343. const target = evt.target;
  344. const sortby = target.getAttribute('name');
  345. const down = !!target.querySelector(`.${this.upClass}`);
  346. const direction = down ? -1 : 1;
  347. this.setSortBy([sortby, direction]);
  348. if (Utils.isMiniScreen) {
  349. Popup.close();
  350. }
  351. },
  352. },
  353. ];
  354. },
  355. }).register('listsortPopup');
  356. */
  357. BlazeComponent.extendComponent({
  358. events() {
  359. return [
  360. {
  361. 'click .js-sort-due'() {
  362. const sortBy = {
  363. dueAt: 1,
  364. };
  365. Session.set('sortBy', sortBy);
  366. sortCardsBy.set(TAPi18n.__('due-date'));
  367. Popup.close();
  368. },
  369. 'click .js-sort-title'() {
  370. const sortBy = {
  371. title: 1,
  372. };
  373. Session.set('sortBy', sortBy);
  374. sortCardsBy.set(TAPi18n.__('title'));
  375. Popup.close();
  376. },
  377. 'click .js-sort-created-asc'() {
  378. const sortBy = {
  379. createdAt: 1,
  380. };
  381. Session.set('sortBy', sortBy);
  382. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  383. Popup.close();
  384. },
  385. 'click .js-sort-created-desc'() {
  386. const sortBy = {
  387. createdAt: -1,
  388. };
  389. Session.set('sortBy', sortBy);
  390. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  391. Popup.close();
  392. },
  393. },
  394. ];
  395. },
  396. }).register('cardsSortPopup');