boardHeader.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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-open-search-view'() {
  129. Sidebar.setView('search');
  130. },
  131. 'click .js-multiselection-activate'() {
  132. const currentCard = Session.get('currentCard');
  133. MultiSelection.activate();
  134. if (currentCard) {
  135. MultiSelection.add(currentCard);
  136. }
  137. },
  138. 'click .js-multiselection-reset'(event) {
  139. event.stopPropagation();
  140. MultiSelection.disable();
  141. },
  142. 'click .js-log-in'() {
  143. FlowRouter.go('atSignIn');
  144. },
  145. },
  146. ];
  147. },
  148. }).register('boardHeaderBar');
  149. Template.boardHeaderBar.helpers({
  150. canModifyBoard() {
  151. return (
  152. Meteor.user() &&
  153. Meteor.user().isBoardMember() &&
  154. !Meteor.user().isCommentOnly()
  155. );
  156. },
  157. boardView() {
  158. return Utils.boardView();
  159. },
  160. });
  161. Template.boardChangeViewPopup.events({
  162. 'click .js-open-lists-view'() {
  163. Utils.setBoardView('board-view-lists');
  164. Popup.close();
  165. },
  166. 'click .js-open-swimlanes-view'() {
  167. Utils.setBoardView('board-view-swimlanes');
  168. Popup.close();
  169. },
  170. 'click .js-open-cal-view'() {
  171. Utils.setBoardView('board-view-cal');
  172. Popup.close();
  173. },
  174. });
  175. const CreateBoard = BlazeComponent.extendComponent({
  176. template() {
  177. return 'createBoard';
  178. },
  179. onCreated() {
  180. this.visibilityMenuIsOpen = new ReactiveVar(false);
  181. this.visibility = new ReactiveVar('private');
  182. this.boardId = new ReactiveVar('');
  183. },
  184. visibilityCheck() {
  185. return this.currentData() === this.visibility.get();
  186. },
  187. setVisibility(visibility) {
  188. this.visibility.set(visibility);
  189. this.visibilityMenuIsOpen.set(false);
  190. },
  191. toggleVisibilityMenu() {
  192. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  193. },
  194. onSubmit(event) {
  195. event.preventDefault();
  196. const title = this.find('.js-new-board-title').value;
  197. const visibility = this.visibility.get();
  198. this.boardId.set(
  199. Boards.insert({
  200. title,
  201. permission: visibility,
  202. }),
  203. );
  204. Swimlanes.insert({
  205. title: 'Default',
  206. boardId: this.boardId.get(),
  207. });
  208. Utils.goBoardId(this.boardId.get());
  209. },
  210. events() {
  211. return [
  212. {
  213. 'click .js-select-visibility'() {
  214. this.setVisibility(this.currentData());
  215. },
  216. 'click .js-change-visibility': this.toggleVisibilityMenu,
  217. 'click .js-import': Popup.open('boardImportBoard'),
  218. submit: this.onSubmit,
  219. 'click .js-import-board': Popup.open('chooseBoardSource'),
  220. 'click .js-board-template': Popup.open('searchElement'),
  221. },
  222. ];
  223. },
  224. }).register('createBoardPopup');
  225. (class HeaderBarCreateBoard extends CreateBoard {
  226. onSubmit(event) {
  227. super.onSubmit(event);
  228. // Immediately star boards crated with the headerbar popup.
  229. Meteor.user().toggleBoardStar(this.boardId.get());
  230. }
  231. }.register('headerBarCreateBoardPopup'));
  232. BlazeComponent.extendComponent({
  233. visibilityCheck() {
  234. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  235. return this.currentData() === currentBoard.permission;
  236. },
  237. selectBoardVisibility() {
  238. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  239. const visibility = this.currentData();
  240. currentBoard.setVisibility(visibility);
  241. Popup.close();
  242. },
  243. events() {
  244. return [
  245. {
  246. 'click .js-select-visibility': this.selectBoardVisibility,
  247. },
  248. ];
  249. },
  250. }).register('boardChangeVisibilityPopup');
  251. BlazeComponent.extendComponent({
  252. watchLevel() {
  253. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  254. return currentBoard.getWatchLevel(Meteor.userId());
  255. },
  256. watchCheck() {
  257. return this.currentData() === this.watchLevel();
  258. },
  259. events() {
  260. return [
  261. {
  262. 'click .js-select-watch'() {
  263. const level = this.currentData();
  264. Meteor.call(
  265. 'watch',
  266. 'board',
  267. Session.get('currentBoard'),
  268. level,
  269. (err, ret) => {
  270. if (!err && ret) Popup.close();
  271. },
  272. );
  273. },
  274. },
  275. ];
  276. },
  277. }).register('boardChangeWatchPopup');
  278. /*
  279. BlazeComponent.extendComponent({
  280. onCreated() {
  281. //this.sortBy = new ReactiveVar();
  282. ////this.sortDirection = new ReactiveVar();
  283. //this.setSortBy();
  284. this.downClass = DOWNCLS;
  285. this.upClass = UPCLS;
  286. },
  287. allowedSortValues() {
  288. const types = [];
  289. const pushed = {};
  290. Meteor.user()
  291. .getListSortTypes()
  292. .forEach(type => {
  293. const key = type.replace(/^-/, '');
  294. if (pushed[key] === undefined) {
  295. types.push({
  296. name: key,
  297. label: `list-label-${key}`,
  298. shortLabel: `list-label-short-${key}`,
  299. });
  300. pushed[key] = 1;
  301. }
  302. });
  303. return types;
  304. },
  305. Direction() {
  306. return Meteor.user().getListSortByDirection() === -1
  307. ? this.downClass
  308. : this.upClass;
  309. },
  310. sortby() {
  311. return Meteor.user().getListSortBy();
  312. },
  313. setSortBy(type = null) {
  314. const user = Meteor.user();
  315. if (type === null) {
  316. type = user._getListSortBy();
  317. } else {
  318. let value = '';
  319. if (type.map) {
  320. // is an array
  321. value = (type[1] === -1 ? '-' : '') + type[0];
  322. }
  323. Meteor.call('setListSortBy', value);
  324. }
  325. //this.sortBy.set(type[0]);
  326. //this.sortDirection.set(type[1]);
  327. },
  328. events() {
  329. return [
  330. {
  331. 'click .js-sort-by'(evt) {
  332. evt.preventDefault();
  333. const target = evt.target;
  334. const sortby = target.getAttribute('name');
  335. const down = !!target.querySelector(`.${this.upClass}`);
  336. const direction = down ? -1 : 1;
  337. this.setSortBy([sortby, direction]);
  338. if (Utils.isMiniScreen) {
  339. Popup.close();
  340. }
  341. },
  342. },
  343. ];
  344. },
  345. }).register('listsortPopup');
  346. */
  347. BlazeComponent.extendComponent({
  348. events() {
  349. return [
  350. {
  351. 'click .js-sort-due'() {
  352. const sortBy = {
  353. dueAt: 1,
  354. };
  355. Session.set('sortBy', sortBy);
  356. sortCardsBy.set(TAPi18n.__('due-date'));
  357. Popup.close();
  358. },
  359. 'click .js-sort-title'() {
  360. const sortBy = {
  361. title: 1,
  362. };
  363. Session.set('sortBy', sortBy);
  364. sortCardsBy.set(TAPi18n.__('title'));
  365. Popup.close();
  366. },
  367. 'click .js-sort-created-asc'() {
  368. const sortBy = {
  369. createdAt: 1,
  370. };
  371. Session.set('sortBy', sortBy);
  372. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  373. Popup.close();
  374. },
  375. 'click .js-sort-created-desc'() {
  376. const sortBy = {
  377. createdAt: -1,
  378. };
  379. Session.set('sortBy', sortBy);
  380. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  381. Popup.close();
  382. },
  383. 'click .js-sort-default'() {
  384. const sortBy = {
  385. sort: 1,
  386. };
  387. Session.set('sortBy', sortBy);
  388. sortCardsBy.set(TAPi18n.__('default'));
  389. Popup.close();
  390. },
  391. },
  392. ];
  393. },
  394. }).register('cardsSortPopup');