item.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. host_link: '.host-link'
  12. },
  13. events: {
  14. 'click @ui.able': function (e) {
  15. e.preventDefault();
  16. let id = this.model.get('id');
  17. App.Api.Nginx.DeadHosts[this.model.get('enabled') ? 'disable' : 'enable'](id)
  18. .then(() => {
  19. return App.Api.Nginx.DeadHosts.get(id)
  20. .then(row => {
  21. this.model.set(row);
  22. });
  23. });
  24. },
  25. 'click @ui.edit': function (e) {
  26. e.preventDefault();
  27. App.Controller.showNginxDeadForm(this.model);
  28. },
  29. 'click @ui.delete': function (e) {
  30. e.preventDefault();
  31. App.Controller.showNginxDeadDeleteConfirm(this.model);
  32. },
  33. 'click @ui.host_link': function (e) {
  34. e.preventDefault();
  35. let win = window.open($(e.currentTarget).attr('rel'), '_blank');
  36. win.focus();
  37. }
  38. },
  39. templateContext: {
  40. canManage: App.Cache.User.canManage('dead_hosts'),
  41. isOnline: function () {
  42. return typeof this.meta.nginx_online === 'undefined' ? null : this.meta.nginx_online;
  43. },
  44. getOfflineError: function () {
  45. return this.meta.nginx_err || '';
  46. }
  47. },
  48. initialize: function () {
  49. this.listenTo(this.model, 'change', this.render);
  50. }
  51. });