mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
79 lines
2.0 KiB
JavaScript
79 lines
2.0 KiB
JavaScript
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({
|
|
id: 'users',
|
|
template: template,
|
|
|
|
ui: {
|
|
list_region: '.list-region',
|
|
add: '.add-item',
|
|
dimmer: '.dimmer',
|
|
search: '.search-form',
|
|
query: 'input[name="source-query"]'
|
|
},
|
|
|
|
fetch: App.Api.Users.getAll,
|
|
|
|
showData: function(response) {
|
|
this.showChildView('list_region', new ListView({
|
|
collection: new UserModel.Collection(response)
|
|
}));
|
|
},
|
|
|
|
showError: function(err) {
|
|
this.showChildView('list_region', new ErrorView({
|
|
code: err.code,
|
|
message: err.message,
|
|
retry: function () {
|
|
App.Controller.showUsers();
|
|
}
|
|
}));
|
|
|
|
console.error(err);
|
|
},
|
|
|
|
regions: {
|
|
list_region: '@ui.list_region'
|
|
},
|
|
|
|
events: {
|
|
'click @ui.add': function (e) {
|
|
e.preventDefault();
|
|
App.Controller.showUserForm(new UserModel.Model());
|
|
},
|
|
|
|
'submit @ui.search': function (e) {
|
|
e.preventDefault();
|
|
let query = this.ui.query.val();
|
|
|
|
this.fetch(['permissions'], query)
|
|
.then(response => this.showData(response))
|
|
.catch(err => {
|
|
this.showError(err);
|
|
});
|
|
}
|
|
},
|
|
|
|
onRender: function () {
|
|
let view = this;
|
|
|
|
view.fetch(['permissions'])
|
|
.then(response => {
|
|
if (!view.isDestroyed() && response && response.length) {
|
|
view.showData(response);
|
|
}
|
|
})
|
|
.catch(err => {
|
|
view.showError(err);
|
|
})
|
|
.then(() => {
|
|
view.ui.dimmer.removeClass('active');
|
|
});
|
|
}
|
|
});
|