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

     1  var $ = require('jquery');
     2  
     3  window.jQuery = $;
     4  var bootstrap = require('bootstrap'); //eslint-disable-line no-unused-vars
     5  var bootbox = require('bootbox');
     6  
     7  var Pubsub = require('../lib/pubsub');
     8  var AppState = require('../app_state');
     9  
    10  var BaseView = require('./base');
    11  
    12  var ChannelView = BaseView.extend({
    13      className: 'channel container-fluid',
    14  
    15      template: require('./spinner.hbs'),
    16  
    17      events: {
    18          'click .channel-actions button': 'channelAction'
    19      },
    20  
    21      initialize: function() {
    22          BaseView.prototype.initialize.apply(this, arguments);
    23          this.listenTo(AppState, 'change:graph_interval', this.render);
    24          var isAdmin = this.model.get('isAdmin');
    25          this.model.fetch()
    26              .done(function(data) {
    27                  this.template = require('./channel.hbs');
    28                  this.render({'message': data['message'], 'isAdmin': isAdmin});
    29              }.bind(this))
    30              .fail(this.handleViewError.bind(this))
    31              .always(Pubsub.trigger.bind(Pubsub, 'view:ready'));
    32      },
    33  
    34      channelAction: function(e) {
    35          e.preventDefault();
    36          e.stopPropagation();
    37          var action = $(e.currentTarget).data('action');
    38          var txt = 'Are you sure you want to <strong>' +
    39              action + '</strong> <em>' + this.model.get('topic') +
    40              '/' + this.model.get('name') + '</em>?';
    41          bootbox.confirm(txt, function(result) {
    42              if (result !== true) {
    43                  return;
    44              }
    45              if (action === 'delete') {
    46                  var topic = this.model.get('topic');
    47                  $.ajax(this.model.url(), {'method': 'DELETE'})
    48                      .done(function() {
    49                          window.location = AppState.basePath('/topics/' +
    50                              encodeURIComponent(topic));
    51                      })
    52                      .fail(this.handleAJAXError.bind(this));
    53              } else {
    54                  $.post(this.model.url(), JSON.stringify({'action': action}))
    55                      .done(function() { window.location.reload(true); })
    56                      .fail(this.handleAJAXError.bind(this));
    57              }
    58          }.bind(this));
    59      }
    60  });
    61  
    62  module.exports = ChannelView;