2018-06-25 21:56:10 -04:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
const Mn = require('backbone.marionette');
|
2018-07-18 02:55:09 -04:00
|
|
|
const App = require('../../main');
|
2018-07-08 21:22:10 -04: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 02:55:09 -04:00
|
|
|
const template = require('./main.ejs');
|
2018-06-25 21:56:10 -04:00
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
2018-07-08 21:22:10 -04:00
|
|
|
id: 'nginx-proxy',
|
2018-06-25 21:56:10 -04:00
|
|
|
template: template,
|
2018-07-08 21:22:10 -04:00
|
|
|
|
|
|
|
ui: {
|
|
|
|
list_region: '.list-region',
|
|
|
|
add: '.add-item',
|
2018-08-01 07:18:17 -04:00
|
|
|
help: '.help',
|
2018-07-08 21:22:10 -04:00
|
|
|
dimmer: '.dimmer'
|
|
|
|
},
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
list_region: '@ui.list_region'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click @ui.add': function (e) {
|
|
|
|
e.preventDefault();
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Controller.showNginxProxyForm();
|
2018-08-01 07:18:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
'click @ui.help': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
App.Controller.showHelp(App.i18n('proxy-hosts', 'help-title'), App.i18n('proxy-hosts', 'help-content'));
|
2018-07-08 21:22:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-10 04:23:14 -04:00
|
|
|
templateContext: {
|
2018-07-18 02:55:09 -04:00
|
|
|
showAddButton: App.Cache.User.canManage('proxy_hosts')
|
2018-07-10 04:23:14 -04:00
|
|
|
},
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
onRender: function () {
|
|
|
|
let view = this;
|
|
|
|
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Api.Nginx.ProxyHosts.getAll(['owner', 'access_list'])
|
2018-07-08 21:22:10 -04:00
|
|
|
.then(response => {
|
|
|
|
if (!view.isDestroyed()) {
|
|
|
|
if (response && response.length) {
|
|
|
|
view.showChildView('list_region', new ListView({
|
|
|
|
collection: new ProxyHostModel.Collection(response)
|
|
|
|
}));
|
|
|
|
} else {
|
2018-07-18 02:55:09 -04:00
|
|
|
let manage = App.Cache.User.canManage('proxy_hosts');
|
2018-07-10 04:23:14 -04:00
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
view.showChildView('list_region', new EmptyView({
|
2018-07-18 02:55:09 -04:00
|
|
|
title: App.i18n('proxy-hosts', 'empty'),
|
|
|
|
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
|
|
|
|
link: manage ? App.i18n('proxy-hosts', 'add') : null,
|
2018-07-10 04:23:14 -04:00
|
|
|
btn_color: 'success',
|
|
|
|
permission: 'proxy_hosts',
|
|
|
|
action: function () {
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Controller.showNginxProxyForm();
|
2018-07-08 21:22:10 -04:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
view.showChildView('list_region', new ErrorView({
|
|
|
|
code: err.code,
|
|
|
|
message: err.message,
|
|
|
|
retry: function () {
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Controller.showNginxProxy();
|
2018-07-08 21:22:10 -04:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
view.ui.dimmer.removeClass('active');
|
|
|
|
});
|
|
|
|
}
|
2018-06-25 21:56:10 -04:00
|
|
|
});
|