Add / edit Users

This commit is contained in:
Jamie Curnow 2018-06-20 16:57:34 +10:00
parent bfc319cff9
commit 446921111e
2 changed files with 10 additions and 15 deletions

View File

@ -39,6 +39,8 @@ const internalUser = {
.insertAndFetch(data); .insertAndFetch(data);
}) })
.then(user => { .then(user => {
return internalUser.get(access, {id: user.id});
/*
return authModel return authModel
.query() .query()
.insert({ .insert({
@ -48,8 +50,9 @@ const internalUser = {
meta: {} meta: {}
}) })
.then(() => { .then(() => {
return internalUser.get(access, {id: user.id, expand: ['services']}); return internalUser.get(access, {id: user.id});
}); });
*/
}); });
}, },
@ -110,7 +113,7 @@ const internalUser = {
}); });
}) })
.then(() => { .then(() => {
return internalUser.get(access, {id: data.id, expand: ['services']}); return internalUser.get(access, {id: data.id});
}); });
}, },

View File

@ -22,23 +22,15 @@ module.exports = Mn.View.extend({
}, },
events: { events: {
/*
'click @ui.cancel': function (e) {
e.preventDefault();
App.UI.closeModal();
},
*/
'submit @ui.form': function (e) { 'click @ui.save': function (e) {
e.preventDefault(); e.preventDefault();
let view = this; let view = this;
let data = this.ui.form.serializeJSON(); let data = this.ui.form.serializeJSON();
// Manipulate // Manipulate
data.roles = []; data.roles = [];
if ( if ((this.model.get('id') === Cache.User.get('id') && this.model.isAdmin()) || (typeof data.is_admin !== 'undefined' && data.is_admin)) {
(this.model.get('id') === Cache.User.get('id') && this.model.isAdmin()) ||
(typeof data.is_admin !== 'undefined' && data.is_admin)) {
data.roles.push('admin'); data.roles.push('admin');
delete data.is_admin; delete data.is_admin;
} }
@ -59,12 +51,12 @@ module.exports = Mn.View.extend({
Cache.User.set(result); Cache.User.set(result);
} }
view.model.set(result);
App.UI.closeModal();
if (view.model.get('id') !== Cache.User.get('id')) { if (view.model.get('id') !== Cache.User.get('id')) {
Controller.showUsers(); Controller.showUsers();
} }
view.model.set(result);
App.UI.closeModal();
}) })
.catch(err => { .catch(err => {
alert(err.message); alert(err.message);