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');
|
2018-06-20 02:51:18 -04:00
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
2018-07-08 21:22:10 -04:00
|
|
|
id: 'users',
|
|
|
|
template: template,
|
2018-06-20 02:51:18 -04:00
|
|
|
|
|
|
|
ui: {
|
|
|
|
list_region: '.list-region',
|
2018-07-08 21:22:10 -04:00
|
|
|
add: '.add-item',
|
2018-06-20 02:51:18 -04:00
|
|
|
dimmer: '.dimmer'
|
|
|
|
},
|
|
|
|
|
|
|
|
regions: {
|
|
|
|
list_region: '@ui.list_region'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
2018-07-08 21:22:10 -04:00
|
|
|
'click @ui.add': function (e) {
|
2018-06-20 02:51:18 -04:00
|
|
|
e.preventDefault();
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Controller.showUserForm(new UserModel.Model());
|
2018-06-20 02:51:18 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onRender: function () {
|
|
|
|
let view = this;
|
|
|
|
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Api.Users.getAll(['permissions'])
|
2018-06-20 02:51:18 -04:00
|
|
|
.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');
|
2018-06-20 02:51:18 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|