sidebar.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. Sidebar = null;
  2. var defaultView = 'home';
  3. var viewTitles = {
  4. filter: 'filter-cards',
  5. multiselection: 'multi-selection'
  6. };
  7. BlazeComponent.extendComponent({
  8. template: function() {
  9. return 'sidebar';
  10. },
  11. mixins: function() {
  12. return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
  13. },
  14. onCreated: function() {
  15. this._isOpen = new ReactiveVar(! Session.get('currentCard'));
  16. this._view = new ReactiveVar(defaultView);
  17. Sidebar = this;
  18. },
  19. onDestroyed: function() {
  20. Sidebar = null;
  21. },
  22. isOpen: function() {
  23. return this._isOpen.get();
  24. },
  25. open: function() {
  26. if (! this._isOpen.get()) {
  27. this._isOpen.set(true);
  28. }
  29. },
  30. hide: function() {
  31. if (this._isOpen.get()) {
  32. this._isOpen.set(false);
  33. }
  34. },
  35. toogle: function() {
  36. this._isOpen.set(! this._isOpen.get());
  37. },
  38. calculateNextPeak: function() {
  39. var altitude = this.find('.js-board-sidebar-content').scrollHeight;
  40. this.callFirstWith(this, 'setNextPeak', altitude);
  41. },
  42. reachNextPeak: function() {
  43. var activitiesComponent = this.componentChildren('activities')[0];
  44. activitiesComponent.loadNextPage();
  45. },
  46. isTongueHidden: function() {
  47. return this.isOpen() && this.getView() !== defaultView;
  48. },
  49. getView: function() {
  50. return this._view.get();
  51. },
  52. setView: function(view) {
  53. view = _.isString(view) ? view : defaultView;
  54. this._view.set(view);
  55. this.open();
  56. },
  57. isDefaultView: function() {
  58. return this.getView() === defaultView;
  59. },
  60. getViewTemplate: function() {
  61. return this.getView() + 'Sidebar';
  62. },
  63. getViewTitle: function() {
  64. return TAPi18n.__(viewTitles[this.getView()]);
  65. },
  66. // Board members can assign people or labels by drag-dropping elements from
  67. // the sidebar to the cards on the board. In order to re-initialize the
  68. // jquery-ui plugin any time a draggable member or label is modified or
  69. // removed we use a autorun function and register a dependency on the both
  70. // members and labels fields of the current board document.
  71. onRendered: function() {
  72. var self = this;
  73. if (! Meteor.userId() || ! Meteor.user().isBoardMember())
  74. return;
  75. self.autorun(function() {
  76. var currentBoardId = Tracker.nonreactive(function() {
  77. return Session.get('currentBoard');
  78. });
  79. Boards.findOne(currentBoardId, {
  80. fields: {
  81. members: 1,
  82. labels: 1
  83. }
  84. });
  85. Tracker.afterFlush(function() {
  86. self.$('.js-member,.js-label').draggable({
  87. appendTo: 'body',
  88. helper: 'clone',
  89. revert: 'invalid',
  90. revertDuration: 150,
  91. snap: false,
  92. snapMode: 'both',
  93. start: function() {
  94. EscapeActions.executeLowerThan('popup');
  95. }
  96. });
  97. });
  98. });
  99. },
  100. events: function() {
  101. // XXX Hacky, we need some kind of `super`
  102. var mixinEvents = this.getMixin(Mixins.InfiniteScrolling).events();
  103. return mixinEvents.concat([{
  104. 'click .js-toogle-sidebar': this.toogle,
  105. 'click .js-back-home': this.setView
  106. }]);
  107. }
  108. }).register('sidebar');
  109. EscapeActions.register('sidebarView',
  110. function() { Sidebar.setView(defaultView); },
  111. function() { return Sidebar && Sidebar.getView() !== defaultView; }
  112. );