nginx-proxy-manager/src/frontend/js/app/nginx/proxy/main.js

84 lines
2.8 KiB
JavaScript
Raw Normal View History

'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');
module.exports = Mn.View.extend({
2018-07-08 21:22:10 -04:00
id: 'nginx-proxy',
template: template,
2018-07-08 21:22:10 -04:00
ui: {
list_region: '.list-region',
add: '.add-item',
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();
},
'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
}
},
templateContext: {
2018-07-18 02:55:09 -04:00
showAddButton: App.Cache.User.canManage('proxy_hosts')
},
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-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,
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');
});
}
});