github.com/nsqio/nsq@v1.3.0/nsqadmin/static/js/views/header.js (about)

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