channel.js 2.1 KB

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