github.com/nsqio/nsq@v1.3.0/nsqadmin/static/js/views/topic.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 TopicView = BaseView.extend({ 13 className: 'topic container-fluid', 14 15 template: require('./spinner.hbs'), 16 17 events: { 18 'click .topic-actions button': 'topicAction' 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('./topic.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 topicAction: 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('name') + '</em>?'; 40 bootbox.confirm(txt, function(result) { 41 if (result !== true) { 42 return; 43 } 44 if (action === 'delete') { 45 $.ajax(this.model.url(), {'method': 'DELETE'}) 46 .done(function() { window.location = AppState.basePath('/'); }); 47 } else { 48 $.post(this.model.url(), JSON.stringify({'action': action})) 49 .done(function() { window.location.reload(true); }) 50 .fail(this.handleAJAXError.bind(this)); 51 } 52 }.bind(this)); 53 } 54 }); 55 56 module.exports = TopicView;