2018-07-09 01:22:10 +00:00
|
|
|
const Mn = require('backbone.marionette');
|
2018-07-18 06:55:09 +00:00
|
|
|
const App = require('../../main');
|
2018-07-09 01:22:10 +00:00
|
|
|
const ProxyHostModel = require('../../../models/proxy-host');
|
|
|
|
const ListView = require('./list/main');
|
|
|
|
const ErrorView = require('../../error/main');
|
|
|
|
const EmptyView = require('../../empty/main');
|
2018-07-18 06:55:09 +00:00
|
|
|
const template = require('./main.ejs');
|
2018-06-26 01:56:10 +00:00
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
2018-07-09 01:22:10 +00:00
|
|
|
id: 'nginx-proxy',
|
2018-06-26 01:56:10 +00:00
|
|
|
template: template,
|
2018-07-09 01:22:10 +00:00
|
|
|
|
|
|
|
ui: {
|
|
|
|
list_region: '.list-region',
|
|
|
|
add: '.add-item',
|
2018-08-01 11:18:17 +00:00
|
|
|
help: '.help',
|
2022-02-12 03:38:15 +00:00
|
|
|
dimmer: '.dimmer',
|
|
|
|
search: '.search-form',
|
|
|
|
query: 'input[name="source-query"]'
|
|
|
|
},
|
|
|
|
|
|
|
|
fetch: App.Api.Nginx.ProxyHosts.getAll,
|
|
|
|
|
|
|
|
showData: function(response) {
|
|
|
|
this.showChildView('list_region', new ListView({
|
|
|
|
collection: new ProxyHostModel.Collection(response)
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
showError: function(err) {
|
|
|
|
this.showChildView('list_region', new ErrorView({
|
|
|
|
code: err.code,
|
|
|
|
message: err.message,
|
|
|
|
retry: function () {
|
|
|
|
App.Controller.showNginxProxy();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
},
|
|
|
|
|
|
|
|
showEmpty: function() {
|
|
|
|
let manage = App.Cache.User.canManage('proxy_hosts');
|
|
|
|
|
|
|
|
this.showChildView('list_region', new EmptyView({
|
|
|
|
title: App.i18n('proxy-hosts', 'empty'),
|
|
|
|
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
|
|
|
|
link: manage ? App.i18n('proxy-hosts', 'add') : null,
|
|
|
|
btn_color: 'success',
|
|
|
|
permission: 'proxy_hosts',
|
|
|
|
action: function () {
|
|
|
|
App.Controller.showNginxProxyForm();
|
|
|
|
}
|
|
|
|
}));
|
2018-07-09 01:22:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
list_region: '@ui.list_region'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click @ui.add': function (e) {
|
|
|
|
e.preventDefault();
|
2018-07-18 06:55:09 +00:00
|
|
|
App.Controller.showNginxProxyForm();
|
2018-08-01 11:18:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'click @ui.help': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
App.Controller.showHelp(App.i18n('proxy-hosts', 'help-title'), App.i18n('proxy-hosts', 'help-content'));
|
2022-02-12 03:38:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'submit @ui.search': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
let query = this.ui.query.val();
|
|
|
|
|
2022-02-12 04:52:47 +00:00
|
|
|
this.fetch(['owner', 'access_list', 'certificate'], query)
|
2022-02-12 03:38:15 +00:00
|
|
|
.then(response => this.showData(response))
|
|
|
|
.catch(err => {
|
|
|
|
this.showError(err);
|
|
|
|
});
|
2018-07-09 01:22:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-10 08:23:14 +00:00
|
|
|
templateContext: {
|
2018-07-18 06:55:09 +00:00
|
|
|
showAddButton: App.Cache.User.canManage('proxy_hosts')
|
2018-07-10 08:23:14 +00:00
|
|
|
},
|
|
|
|
|
2018-07-09 01:22:10 +00:00
|
|
|
onRender: function () {
|
|
|
|
let view = this;
|
|
|
|
|
2022-02-12 03:38:15 +00:00
|
|
|
view.fetch(['owner', 'access_list', 'certificate'])
|
2018-07-09 01:22:10 +00:00
|
|
|
.then(response => {
|
|
|
|
if (!view.isDestroyed()) {
|
|
|
|
if (response && response.length) {
|
2022-02-12 03:38:15 +00:00
|
|
|
view.showData(response);
|
2018-07-09 01:22:10 +00:00
|
|
|
} else {
|
2022-02-12 03:38:15 +00:00
|
|
|
view.showEmpty();
|
2018-07-09 01:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2022-02-12 03:38:15 +00:00
|
|
|
view.showError(err);
|
2018-07-09 01:22:10 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
view.ui.dimmer.removeClass('active');
|
|
|
|
});
|
|
|
|
}
|
2018-06-26 01:56:10 +00:00
|
|
|
});
|