item.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const Mn = require('backbone.marionette');
  2. const moment = require('moment');
  3. const App = require('../../../main');
  4. const template = require('./item.ejs');
  5. const dns_providers = require('../../../../../../global/certbot-dns-plugins');
  6. module.exports = Mn.View.extend({
  7. template: template,
  8. tagName: 'tr',
  9. ui: {
  10. host_link: '.host-link',
  11. renew: 'a.renew',
  12. delete: 'a.delete',
  13. download: 'a.download',
  14. test: 'a.test'
  15. },
  16. events: {
  17. 'click @ui.renew': function (e) {
  18. e.preventDefault();
  19. App.Controller.showNginxCertificateRenew(this.model);
  20. },
  21. 'click @ui.delete': function (e) {
  22. e.preventDefault();
  23. App.Controller.showNginxCertificateDeleteConfirm(this.model);
  24. },
  25. 'click @ui.host_link': function (e) {
  26. e.preventDefault();
  27. let win = window.open($(e.currentTarget).attr('rel'), '_blank');
  28. win.focus();
  29. },
  30. 'click @ui.download': function (e) {
  31. e.preventDefault();
  32. App.Api.Nginx.Certificates.download(this.model.get('id'));
  33. },
  34. 'click @ui.test': function (e) {
  35. e.preventDefault();
  36. App.Controller.showNginxCertificateTestReachability(this.model);
  37. },
  38. },
  39. templateContext: function () {
  40. return {
  41. canManage: App.Cache.User.canManage('certificates'),
  42. isExpired: function () {
  43. return moment(this.expires_on).isBefore(moment());
  44. },
  45. dns_providers: dns_providers,
  46. active_domain_names: function () {
  47. const { proxy_hosts = [], redirect_hosts = [], dead_hosts = [] } = this;
  48. return [...proxy_hosts, ...redirect_hosts, ...dead_hosts].reduce((acc, host) => {
  49. acc.push(...(host.domain_names || []));
  50. return acc;
  51. }, []);
  52. }
  53. };
  54. },
  55. initialize: function () {
  56. this.listenTo(this.model, 'change', this.render);
  57. }
  58. });