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

79 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
2018-07-08 21:22:10 -04:00
const Mn = require('backbone.marionette');
const StreamModel = require('../../../models/stream');
const Api = require('../../api');
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');
module.exports = Mn.View.extend({
2018-07-08 21:22:10 -04:00
id: 'nginx-streams',
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.showNginxStreamForm();
}
},
templateContext: {
showAddButton: Cache.User.canManage('streams')
},
2018-07-08 21:22:10 -04:00
onRender: function () {
let view = this;
Api.Nginx.RedirectionHosts.getAll()
.then(response => {
if (!view.isDestroyed()) {
if (response && response.length) {
view.showChildView('list_region', new ListView({
collection: new StreamModel.Collection(response)
}));
} else {
let manage = Cache.User.canManage('streams');
2018-07-08 21:22:10 -04:00
view.showChildView('list_region', new EmptyView({
2018-07-08 22:21:03 -04:00
title: 'There are no Streams',
subtitle: manage ? 'Why don\'t you create one?' : 'And you don\'t have permission to create one.',
link: manage ? 'Add Stream' : null,
2018-07-08 22:21:03 -04:00
btn_color: 'blue',
action: function () {
2018-07-08 21:22:10 -04:00
Controller.showNginxStreamForm();
}
}));
}
}
})
.catch(err => {
view.showChildView('list_region', new ErrorView({
code: err.code,
message: err.message,
retry: function () {
Controller.showNginxStream();
}
}));
console.error(err);
})
.then(() => {
view.ui.dimmer.removeClass('active');
});
}
});