boardHeader.js 4.5 KB

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