2018-07-08 21:22:10 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Mn = require('backbone.marionette');
|
2018-07-25 18:23:32 -04:00
|
|
|
const App = require('../../main');
|
2018-07-08 21:22:10 -04:00
|
|
|
const DeadHostModel = require('../../../models/dead-host');
|
|
|
|
const ListView = require('./list/main');
|
|
|
|
const ErrorView = require('../../error/main');
|
|
|
|
const EmptyView = require('../../empty/main');
|
2018-07-25 18:23:32 -04:00
|
|
|
const template = require('./main.ejs');
|
2018-07-08 21:22:10 -04:00
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
|
|
|
id: 'nginx-dead',
|
|
|
|
template: template,
|
|
|
|
|
|
|
|
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-25 18:23:32 -04:00
|
|
|
App.Controller.showNginxDeadForm();
|
2018-08-01 07:18:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
'click @ui.help': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
App.Controller.showHelp(App.i18n('dead-hosts', 'help-title'), App.i18n('dead-hosts', 'help-content'));
|
2018-07-08 21:22:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-07-10 04:23:14 -04:00
|
|
|
templateContext: {
|
2018-07-25 18:23:32 -04:00
|
|
|
showAddButton: App.Cache.User.canManage('dead_hosts')
|
2018-07-10 04:23:14 -04:00
|
|
|
},
|
|
|
|
|
2018-07-08 21:22:10 -04:00
|
|
|
onRender: function () {
|
|
|
|
let view = this;
|
|
|
|
|
2018-07-25 18:23:32 -04:00
|
|
|
App.Api.Nginx.DeadHosts.getAll(['owner'])
|
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 DeadHostModel.Collection(response)
|
|
|
|
}));
|
|
|
|
} else {
|
2018-07-25 18:23:32 -04:00
|
|
|
let manage = App.Cache.User.canManage('dead_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-25 18:23:32 -04:00
|
|
|
title: App.i18n('dead-hosts', 'empty'),
|
|
|
|
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
|
|
|
|
link: manage ? App.i18n('dead-hosts', 'add') : null,
|
|
|
|
btn_color: 'danger',
|
|
|
|
permission: 'dead_hosts',
|
|
|
|
action: function () {
|
|
|
|
App.Controller.showNginxDeadForm();
|
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-25 18:23:32 -04:00
|
|
|
App.Controller.showNginxDead();
|
2018-07-08 21:22:10 -04:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
view.ui.dimmer.removeClass('active');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|