item.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Mn = require('backbone.marionette');
  2. const moment = require('moment');
  3. const App = require('../../../main');
  4. const template = require('./item.ejs');
  5. module.exports = Mn.View.extend({
  6. template: template,
  7. tagName: 'tr',
  8. ui: {
  9. host_link: '.host-link',
  10. renew: 'a.renew',
  11. delete: 'a.delete'
  12. },
  13. events: {
  14. 'click @ui.renew': function (e) {
  15. e.preventDefault();
  16. App.Controller.showNginxCertificateRenew(this.model);
  17. },
  18. 'click @ui.delete': function (e) {
  19. e.preventDefault();
  20. App.Controller.showNginxCertificateDeleteConfirm(this.model);
  21. },
  22. 'click @ui.host_link': function (e) {
  23. e.preventDefault();
  24. let win = window.open($(e.currentTarget).attr('rel'), '_blank');
  25. win.focus();
  26. }
  27. },
  28. templateContext: {
  29. canManage: App.Cache.User.canManage('certificates'),
  30. isExpired: function () {
  31. return moment(this.expires_on).isBefore(moment());
  32. }
  33. },
  34. initialize: function () {
  35. this.listenTo(this.model, 'change', this.render);
  36. }
  37. });