item.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const Mn = require('backbone.marionette');
  2. const App = require('../../../main');
  3. const template = require('./item.ejs');
  4. module.exports = Mn.View.extend({
  5. template: template,
  6. tagName: 'tr',
  7. ui: {
  8. able: 'a.able',
  9. edit: 'a.edit',
  10. delete: 'a.delete'
  11. },
  12. events: {
  13. 'click @ui.able': function (e) {
  14. e.preventDefault();
  15. let id = this.model.get('id');
  16. App.Api.Nginx.Streams[this.model.get('enabled') ? 'disable' : 'enable'](id)
  17. .then(() => {
  18. return App.Api.Nginx.Streams.get(id)
  19. .then(row => {
  20. this.model.set(row);
  21. });
  22. });
  23. },
  24. 'click @ui.edit': function (e) {
  25. e.preventDefault();
  26. App.Controller.showNginxStreamForm(this.model);
  27. },
  28. 'click @ui.delete': function (e) {
  29. e.preventDefault();
  30. App.Controller.showNginxStreamDeleteConfirm(this.model);
  31. }
  32. },
  33. templateContext: {
  34. canManage: App.Cache.User.canManage('streams'),
  35. isOnline: function () {
  36. return typeof this.meta.nginx_online === 'undefined' ? null : this.meta.nginx_online;
  37. },
  38. getOfflineError: function () {
  39. return this.meta.nginx_err || '';
  40. }
  41. },
  42. initialize: function () {
  43. this.listenTo(this.model, 'change', this.render);
  44. }
  45. });