boardHeader.js 4.9 KB

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