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

72 lines
2.2 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 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();
}
},
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 {
view.showChildView('list_region', new EmptyView({
2018-07-08 22:21:03 -04:00
title: 'There are no Streams',
subtitle: 'Why don\'t you create one?',
link: 'Add Stream',
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');
});
}
});