item.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: {
  40. canManage: App.Cache.User.canManage('certificates'),
  41. isExpired: function () {
  42. return moment(this.expires_on).isBefore(moment());
  43. },
  44. dns_providers: dns_providers
  45. },
  46. initialize: function () {
  47. this.listenTo(this.model, 'change', this.render);
  48. }
  49. });