2018-06-25 21:56:10 -04:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
const Mn = require('backbone.marionette');
|
|
|
|
const ProxyHostModel = require('../../../models/proxy-host');
|
|
|
|
const Api = require('../../api');
|
2018-07-10 04:23:14 -04:00
|
|
|
const Cache = require('../../cache');
|
2018-07-08 21:22:10 -04:00
|
|
|
const Controller = require('../../controller');
|
|
|
|
const ListView = require('./list/main');
|
|
|
|
const ErrorView = require('../../error/main');
|
|
|
|
const template = require('./main.ejs');
|
|
|
|
const EmptyView = require('../../empty/main');
|
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',
|
|
|
|
dimmer: '.dimmer'
|
|
|
|
},
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
list_region: '@ui.list_region'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click @ui.add': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
Controller.showNginxProxyForm();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-10 04:23:14 -04:00
|
|
|
templateContext: {
|
|
|
|
showAddButton: Cache.User.canManage('proxy_hosts')
|
|
|
|
},
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
onRender: function () {
|
|
|
|
let view = this;
|
|
|
|
|
|
|
|
Api.Nginx.ProxyHosts.getAll()
|
|
|
|
.then(response => {
|
|
|
|
if (!view.isDestroyed()) {
|
|
|
|
if (response && response.length) {
|
|
|
|
view.showChildView('list_region', new ListView({
|
|
|
|
collection: new ProxyHostModel.Collection(response)
|
|
|
|
}));
|
|
|
|
} else {
|
2018-07-10 04:23:14 -04:00
|
|
|
let manage = Cache.User.canManage('proxy_hosts');
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
view.showChildView('list_region', new EmptyView({
|
2018-07-10 04:23:14 -04:00
|
|
|
title: 'There are no Proxy Hosts',
|
|
|
|
subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
|
|
|
|
link: manage ? 'Add Proxy Host' : null,
|
|
|
|
btn_color: 'success',
|
|
|
|
permission: 'proxy_hosts',
|
|
|
|
action: function () {
|
2018-07-08 21:22:10 -04:00
|
|
|
Controller.showNginxProxyForm();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
view.showChildView('list_region', new ErrorView({
|
|
|
|
code: err.code,
|
|
|
|
message: err.message,
|
|
|
|
retry: function () {
|
|
|
|
Controller.showNginxProxy();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
view.ui.dimmer.removeClass('active');
|
|
|
|
});
|
|
|
|
}
|
2018-06-25 21:56:10 -04:00
|
|
|
});
|