main.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const Mn = require('backbone.marionette');
  2. const App = require('../../main');
  3. const SslPassthroughModel = require('../../../models/ssl-passthrough-host');
  4. const ListView = require('./list/main');
  5. const ErrorView = require('../../error/main');
  6. const EmptyView = require('../../empty/main');
  7. const template = require('./main.ejs');
  8. module.exports = Mn.View.extend({
  9. id: 'nginx-ssl-passthrough',
  10. template: template,
  11. ui: {
  12. list_region: '.list-region',
  13. add: '.add-item',
  14. help: '.help',
  15. dimmer: '.dimmer',
  16. disabled_info: '#ssl-passthrough-disabled-info'
  17. },
  18. regions: {
  19. list_region: '@ui.list_region'
  20. },
  21. events: {
  22. 'click @ui.add': function (e) {
  23. e.preventDefault();
  24. App.Controller.showNginxSslPassthroughForm();
  25. },
  26. 'click @ui.help': function (e) {
  27. e.preventDefault();
  28. App.Controller.showHelp(App.i18n('ssl-passthrough-hosts', 'help-title'), App.i18n('ssl-passthrough-hosts', 'help-content'));
  29. }
  30. },
  31. templateContext: {
  32. showAddButton: App.Cache.User.canManage('ssl_passthrough_hosts')
  33. },
  34. onRender: function () {
  35. let view = this;
  36. view.ui.disabled_info.hide();
  37. App.Api.Nginx.SslPassthroughHosts.getFeatureEnabled().then((response) => {
  38. console.debug(response)
  39. if (response.ssl_passthrough_enabled === false) {
  40. view.ui.disabled_info.show();
  41. } else {
  42. view.ui.disabled_info.hide();
  43. }
  44. });
  45. App.Api.Nginx.SslPassthroughHosts.getAll(['owner'])
  46. .then(response => {
  47. if (!view.isDestroyed()) {
  48. if (response && response.length) {
  49. view.showChildView('list_region', new ListView({
  50. collection: new SslPassthroughModel.Collection(response)
  51. }));
  52. } else {
  53. let manage = App.Cache.User.canManage('ssl_passthrough_hosts');
  54. view.showChildView('list_region', new EmptyView({
  55. title: App.i18n('ssl-passthrough-hosts', 'empty'),
  56. subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
  57. link: manage ? App.i18n('ssl-passthrough-hosts', 'add') : null,
  58. btn_color: 'blue',
  59. permission: 'ssl-passthrough-hosts',
  60. action: function () {
  61. App.Controller.showNginxSslPassthroughForm();
  62. }
  63. }));
  64. }
  65. }
  66. })
  67. .catch(err => {
  68. view.showChildView('list_region', new ErrorView({
  69. code: err.code,
  70. message: err.message,
  71. retry: function () {
  72. App.Controller.showNginxSslPassthrough();
  73. }
  74. }));
  75. console.error(err);
  76. })
  77. .then(() => {
  78. view.ui.dimmer.removeClass('active');
  79. });
  80. }
  81. });