header.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var _ = require('underscore');
  2. var $ = require('jquery');
  3. var AppState = require('../app_state');
  4. var BaseView = require('./base');
  5. var HeaderView = BaseView.extend({
  6. className: 'header',
  7. template: require('./header.hbs'),
  8. events: {
  9. 'click .dropdown-menu li': 'onGraphIntervalClick'
  10. },
  11. initialize: function() {
  12. BaseView.prototype.initialize.apply(this, arguments);
  13. this.listenTo(AppState, 'change:graph_interval', this.render);
  14. },
  15. getRenderCtx: function() {
  16. return _.extend(BaseView.prototype.getRenderCtx.apply(this, arguments), {
  17. 'graph_intervals': ['1h', '2h', '12h', '24h', '48h', '168h', 'off'],
  18. 'graph_interval': AppState.get('graph_interval')
  19. });
  20. },
  21. onReset: function() {
  22. this.render();
  23. this.$('.dropdown-toggle').dropdown();
  24. },
  25. onGraphIntervalClick: function(e) {
  26. e.stopPropagation();
  27. AppState.set('graph_interval', $(e.target).text());
  28. }
  29. });
  30. module.exports = HeaderView;