2
0

boardHeader.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. Template.boardMenuPopup.events({
  2. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  3. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  4. 'click .js-change-language': Popup.open('setLanguage')
  5. });
  6. Template.boardChangeTitlePopup.events({
  7. submit: function(evt, t) {
  8. var title = t.$('.js-board-name').val().trim();
  9. if (title) {
  10. Boards.update(this._id, {
  11. $set: {
  12. title: title
  13. }
  14. });
  15. Popup.close();
  16. }
  17. evt.preventDefault();
  18. }
  19. });
  20. BlazeComponent.extendComponent({
  21. template: function() {
  22. return 'headerBoard';
  23. },
  24. isStarred: function() {
  25. var currentBoard = this.currentData();
  26. var user = Meteor.user();
  27. return currentBoard && user && user.hasStarred(currentBoard._id);
  28. },
  29. // Only show the star counter if the number of star is greater than 2
  30. showStarCounter: function() {
  31. var currentBoard = this.currentData();
  32. return currentBoard && currentBoard.stars > 2;
  33. },
  34. events: function() {
  35. return [{
  36. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  37. 'click .js-star-board': function() {
  38. Meteor.user().toggleBoardStar(Session.get('currentBoard'));
  39. },
  40. 'click .js-open-board-menu': Popup.open('boardMenu'),
  41. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  42. 'click .js-open-filter-view': function() {
  43. Sidebar.setView('filter');
  44. },
  45. 'click .js-filter-reset': function(evt) {
  46. evt.stopPropagation();
  47. Sidebar.setView();
  48. Filter.reset();
  49. },
  50. 'click .js-multiselection-activate': function() {
  51. var currentCard = Session.get('currentCard');
  52. MultiSelection.activate();
  53. if (currentCard) {
  54. MultiSelection.add(currentCard);
  55. }
  56. },
  57. 'click .js-multiselection-reset': function(evt) {
  58. evt.stopPropagation();
  59. MultiSelection.disable();
  60. }
  61. }];
  62. }
  63. }).register('headerBoard');
  64. BlazeComponent.extendComponent({
  65. template: function() {
  66. return 'boardChangeColorPopup';
  67. },
  68. backgroundColors: function() {
  69. return Boards.simpleSchema()._schema.color.allowedValues;
  70. },
  71. isSelected: function() {
  72. var currentBoard = Boards.findOne(Session.get('currentBoard'));
  73. return currentBoard.color === this.currentData().toString();
  74. },
  75. events: function() {
  76. return [{
  77. 'click .js-select-background': function(evt) {
  78. var currentBoardId = Session.get('currentBoard');
  79. Boards.update(currentBoardId, {
  80. $set: {
  81. color: this.currentData().toString()
  82. }
  83. });
  84. evt.preventDefault();
  85. }
  86. }];
  87. }
  88. }).register('boardChangeColorPopup');
  89. BlazeComponent.extendComponent({
  90. template: function() {
  91. return 'createBoardPopup';
  92. },
  93. onCreated: function() {
  94. this.visibilityMenuIsOpen = new ReactiveVar(false);
  95. this.visibility = new ReactiveVar('private');
  96. },
  97. visibilityCheck: function() {
  98. return this.currentData() === this.visibility.get();
  99. },
  100. setVisibility: function(visibility) {
  101. this.visibility.set(visibility);
  102. this.visibilityMenuIsOpen.set(false);
  103. },
  104. toogleVisibilityMenu: function() {
  105. this.visibilityMenuIsOpen.set(! this.visibilityMenuIsOpen.get());
  106. },
  107. onSubmit: function(evt) {
  108. evt.preventDefault();
  109. var title = this.find('.js-new-board-title').value;
  110. var visibility = this.visibility.get();
  111. var boardId = Boards.insert({
  112. title: title,
  113. permission: visibility
  114. });
  115. Utils.goBoardId(boardId);
  116. },
  117. events: function() {
  118. return [{
  119. 'click .js-select-visibility': function() {
  120. this.setVisibility(this.currentData());
  121. },
  122. 'click .js-change-visibility': this.toogleVisibilityMenu,
  123. submit: this.onSubmit
  124. }];
  125. }
  126. }).register('createBoardPopup');
  127. BlazeComponent.extendComponent({
  128. template: function() {
  129. return 'boardChangeVisibilityPopup';
  130. },
  131. visibilityCheck: function() {
  132. var currentBoard = Boards.findOne(Session.get('currentBoard'));
  133. return this.currentData() === currentBoard.permission;
  134. },
  135. selectBoardVisibility: function() {
  136. Boards.update(Session.get('currentBoard'), {
  137. $set: {
  138. permission: this.currentData()
  139. }
  140. });
  141. Popup.close();
  142. },
  143. events: function() {
  144. return [{
  145. 'click .js-select-visibility': this.selectBoardVisibility
  146. }];
  147. }
  148. }).register('boardChangeVisibilityPopup');