boardHeader.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. const DOWNCLS = 'fa-sort-down';
  3. const UPCLS = 'fa-sort-up';
  4. */
  5. Template.boardMenuPopup.events({
  6. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  7. 'click .js-custom-fields'() {
  8. Sidebar.setView('customFields');
  9. Popup.close();
  10. },
  11. 'click .js-open-archives'() {
  12. Sidebar.setView('archives');
  13. Popup.close();
  14. },
  15. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  16. 'click .js-change-language': Popup.open('changeLanguage'),
  17. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  18. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  19. currentBoard.archive();
  20. // XXX We should have some kind of notification on top of the page to
  21. // confirm that the board was successfully archived.
  22. FlowRouter.go('home');
  23. }),
  24. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  25. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  26. Popup.close();
  27. Boards.remove(currentBoard._id);
  28. FlowRouter.go('home');
  29. }),
  30. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  31. 'click .js-import-board': Popup.open('chooseBoardSource'),
  32. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  33. 'click .js-card-settings': Popup.open('boardCardSettings'),
  34. });
  35. Template.boardChangeTitlePopup.events({
  36. submit(event, templateInstance) {
  37. const newTitle = templateInstance
  38. .$('.js-board-name')
  39. .val()
  40. .trim();
  41. const newDesc = templateInstance
  42. .$('.js-board-desc')
  43. .val()
  44. .trim();
  45. if (newTitle) {
  46. this.rename(newTitle);
  47. this.setDescription(newDesc);
  48. Popup.close();
  49. }
  50. event.preventDefault();
  51. },
  52. });
  53. BlazeComponent.extendComponent({
  54. watchLevel() {
  55. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  56. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  57. },
  58. isStarred() {
  59. const boardId = Session.get('currentBoard');
  60. const user = Meteor.user();
  61. return user && user.hasStarred(boardId);
  62. },
  63. // Only show the star counter if the number of star is greater than 2
  64. showStarCounter() {
  65. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  66. return currentBoard && currentBoard.stars >= 2;
  67. },
  68. /*
  69. showSort() {
  70. return Meteor.user().hasSortBy();
  71. },
  72. directionClass() {
  73. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  74. },
  75. changeDirection() {
  76. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  77. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  78. },
  79. currentDirection() {
  80. return Meteor.user().getListSortByDirection();
  81. },
  82. currentListSortBy() {
  83. return Meteor.user().getListSortBy();
  84. },
  85. listSortShortDesc() {
  86. return `list-label-short-${this.currentListSortBy()}`;
  87. },
  88. */
  89. events() {
  90. return [
  91. {
  92. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  93. 'click .js-star-board'() {
  94. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  95. },
  96. 'click .js-open-board-menu': Popup.open('boardMenu'),
  97. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  98. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  99. 'click .js-open-archived-board'() {
  100. Modal.open('archivedBoards');
  101. },
  102. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  103. 'click .js-toggle-sidebar'() {
  104. Sidebar.toggle();
  105. },
  106. 'click .js-open-filter-view'() {
  107. Sidebar.setView('filter');
  108. },
  109. /*
  110. 'click .js-open-sort-view'(evt) {
  111. const target = evt.target;
  112. if (target.tagName === 'I') {
  113. // click on the text, popup choices
  114. this.changeDirection();
  115. } else {
  116. // change the sort order
  117. Popup.open('listsort')(evt);
  118. }
  119. },
  120. */
  121. 'click .js-filter-reset'(event) {
  122. event.stopPropagation();
  123. Sidebar.setView();
  124. Filter.reset();
  125. },
  126. 'click .js-open-search-view'() {
  127. Sidebar.setView('search');
  128. },
  129. 'click .js-multiselection-activate'() {
  130. const currentCard = Session.get('currentCard');
  131. MultiSelection.activate();
  132. if (currentCard) {
  133. MultiSelection.add(currentCard);
  134. }
  135. },
  136. 'click .js-multiselection-reset'(event) {
  137. event.stopPropagation();
  138. MultiSelection.disable();
  139. },
  140. 'click .js-log-in'() {
  141. FlowRouter.go('atSignIn');
  142. },
  143. },
  144. ];
  145. },
  146. }).register('boardHeaderBar');
  147. Template.boardHeaderBar.helpers({
  148. canModifyBoard() {
  149. return (
  150. Meteor.user() &&
  151. Meteor.user().isBoardMember() &&
  152. !Meteor.user().isCommentOnly()
  153. );
  154. },
  155. boardView() {
  156. return Utils.boardView();
  157. },
  158. });
  159. Template.boardChangeViewPopup.events({
  160. 'click .js-open-lists-view'() {
  161. Utils.setBoardView('board-view-lists');
  162. Popup.close();
  163. },
  164. 'click .js-open-swimlanes-view'() {
  165. Utils.setBoardView('board-view-swimlanes');
  166. Popup.close();
  167. },
  168. 'click .js-open-cal-view'() {
  169. Utils.setBoardView('board-view-cal');
  170. Popup.close();
  171. },
  172. });
  173. const CreateBoard = BlazeComponent.extendComponent({
  174. template() {
  175. return 'createBoard';
  176. },
  177. onCreated() {
  178. this.visibilityMenuIsOpen = new ReactiveVar(false);
  179. this.visibility = new ReactiveVar('private');
  180. this.boardId = new ReactiveVar('');
  181. },
  182. visibilityCheck() {
  183. return this.currentData() === this.visibility.get();
  184. },
  185. setVisibility(visibility) {
  186. this.visibility.set(visibility);
  187. this.visibilityMenuIsOpen.set(false);
  188. },
  189. toggleVisibilityMenu() {
  190. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  191. },
  192. onSubmit(event) {
  193. event.preventDefault();
  194. const title = this.find('.js-new-board-title').value;
  195. const visibility = this.visibility.get();
  196. this.boardId.set(
  197. Boards.insert({
  198. title,
  199. permission: visibility,
  200. }),
  201. );
  202. Swimlanes.insert({
  203. title: 'Default',
  204. boardId: this.boardId.get(),
  205. });
  206. Utils.goBoardId(this.boardId.get());
  207. },
  208. events() {
  209. return [
  210. {
  211. 'click .js-select-visibility'() {
  212. this.setVisibility(this.currentData());
  213. },
  214. 'click .js-change-visibility': this.toggleVisibilityMenu,
  215. 'click .js-import': Popup.open('boardImportBoard'),
  216. submit: this.onSubmit,
  217. 'click .js-import-board': Popup.open('chooseBoardSource'),
  218. 'click .js-board-template': Popup.open('searchElement'),
  219. },
  220. ];
  221. },
  222. }).register('createBoardPopup');
  223. (class HeaderBarCreateBoard extends CreateBoard {
  224. onSubmit(event) {
  225. super.onSubmit(event);
  226. // Immediately star boards crated with the headerbar popup.
  227. Meteor.user().toggleBoardStar(this.boardId.get());
  228. }
  229. }.register('headerBarCreateBoardPopup'));
  230. BlazeComponent.extendComponent({
  231. visibilityCheck() {
  232. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  233. return this.currentData() === currentBoard.permission;
  234. },
  235. selectBoardVisibility() {
  236. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  237. const visibility = this.currentData();
  238. currentBoard.setVisibility(visibility);
  239. Popup.close();
  240. },
  241. events() {
  242. return [
  243. {
  244. 'click .js-select-visibility': this.selectBoardVisibility,
  245. },
  246. ];
  247. },
  248. }).register('boardChangeVisibilityPopup');
  249. BlazeComponent.extendComponent({
  250. watchLevel() {
  251. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  252. return currentBoard.getWatchLevel(Meteor.userId());
  253. },
  254. watchCheck() {
  255. return this.currentData() === this.watchLevel();
  256. },
  257. events() {
  258. return [
  259. {
  260. 'click .js-select-watch'() {
  261. const level = this.currentData();
  262. Meteor.call(
  263. 'watch',
  264. 'board',
  265. Session.get('currentBoard'),
  266. level,
  267. (err, ret) => {
  268. if (!err && ret) Popup.close();
  269. },
  270. );
  271. },
  272. },
  273. ];
  274. },
  275. }).register('boardChangeWatchPopup');
  276. /*
  277. BlazeComponent.extendComponent({
  278. onCreated() {
  279. //this.sortBy = new ReactiveVar();
  280. ////this.sortDirection = new ReactiveVar();
  281. //this.setSortBy();
  282. this.downClass = DOWNCLS;
  283. this.upClass = UPCLS;
  284. },
  285. allowedSortValues() {
  286. const types = [];
  287. const pushed = {};
  288. Meteor.user()
  289. .getListSortTypes()
  290. .forEach(type => {
  291. const key = type.replace(/^-/, '');
  292. if (pushed[key] === undefined) {
  293. types.push({
  294. name: key,
  295. label: `list-label-${key}`,
  296. shortLabel: `list-label-short-${key}`,
  297. });
  298. pushed[key] = 1;
  299. }
  300. });
  301. return types;
  302. },
  303. Direction() {
  304. return Meteor.user().getListSortByDirection() === -1
  305. ? this.downClass
  306. : this.upClass;
  307. },
  308. sortby() {
  309. return Meteor.user().getListSortBy();
  310. },
  311. setSortBy(type = null) {
  312. const user = Meteor.user();
  313. if (type === null) {
  314. type = user._getListSortBy();
  315. } else {
  316. let value = '';
  317. if (type.map) {
  318. // is an array
  319. value = (type[1] === -1 ? '-' : '') + type[0];
  320. }
  321. Meteor.call('setListSortBy', value);
  322. }
  323. //this.sortBy.set(type[0]);
  324. //this.sortDirection.set(type[1]);
  325. },
  326. events() {
  327. return [
  328. {
  329. 'click .js-sort-by'(evt) {
  330. evt.preventDefault();
  331. const target = evt.target;
  332. const sortby = target.getAttribute('name');
  333. const down = !!target.querySelector(`.${this.upClass}`);
  334. const direction = down ? -1 : 1;
  335. this.setSortBy([sortby, direction]);
  336. if (Utils.isMiniScreen) {
  337. Popup.close();
  338. }
  339. },
  340. },
  341. ];
  342. },
  343. }).register('listsortPopup');
  344. */