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

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-07-18 02:55:09 -04:00
const Mn = require('backbone.marionette');
const App = require('../main');
const UserModel = require('../../models/user');
const ListView = require('./list/main');
const ErrorView = require('../error/main');
const template = require('./main.ejs');
module.exports = Mn.View.extend({
2018-07-08 21:22:10 -04:00
id: 'users',
template: template,
ui: {
list_region: '.list-region',
2018-07-08 21:22:10 -04:00
add: '.add-item',
dimmer: '.dimmer'
},
regions: {
list_region: '@ui.list_region'
},
events: {
2018-07-08 21:22:10 -04:00
'click @ui.add': function (e) {
e.preventDefault();
2018-07-18 02:55:09 -04:00
App.Controller.showUserForm(new UserModel.Model());
}
},
onRender: function () {
let view = this;
2018-07-18 02:55:09 -04:00
App.Api.Users.getAll(['permissions'])
.then(response => {
if (!view.isDestroyed() && response && response.length) {
view.showChildView('list_region', new ListView({
collection: new UserModel.Collection(response)
}));
}
})
.catch(err => {
2018-07-08 21:22:10 -04:00
view.showChildView('list_region', new ErrorView({
2018-07-18 02:55:09 -04:00
code: err.code,
message: err.message,
retry: function () {
App.Controller.showUsers();
}
2018-07-08 21:22:10 -04:00
}));
console.error(err);
})
.then(() => {
view.ui.dimmer.removeClass('active');
});
}
});