mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
add bulk users
This commit is contained in:
parent
7e6d6366da
commit
0b5ed8fd9e
11 changed files with 627 additions and 410 deletions
|
@ -9,48 +9,41 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
import { set } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Controller from '@ember/controller';
|
||||
|
||||
export default Controller.extend({
|
||||
userService: service('user'),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.newUser = { firstname: "", lastname: "", email: "", active: true };
|
||||
loadUsers() {
|
||||
this.get('userService').getComplete().then((users) => {
|
||||
this.set('model', users);
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
add(user) {
|
||||
set(this, 'newUser', user);
|
||||
|
||||
return this.get('userService')
|
||||
.add(this.get('newUser'))
|
||||
.then((user) => {
|
||||
this.get('model').pushObject(user);
|
||||
})
|
||||
.catch(function (error) {
|
||||
let msg = error.status === 409 ? 'Unable to add duplicate user' : 'Unable to add user';
|
||||
this.showNotification(msg);
|
||||
});
|
||||
onAddUser(user) {
|
||||
return this.get('userService').add(user).then((user) => {
|
||||
this.get('model').pushObject(user);
|
||||
});
|
||||
},
|
||||
|
||||
onAddUsers(list) {
|
||||
return this.get('userService').addBulk(list).then(() => {
|
||||
this.loadUsers();
|
||||
});
|
||||
},
|
||||
|
||||
onDelete(userId) {
|
||||
let self = this;
|
||||
this.get('userService').remove(userId).then(function () {
|
||||
self.get('userService').getComplete().then(function (users) {
|
||||
self.set('model', users);
|
||||
});
|
||||
this.get('userService').remove(userId).then( () => {
|
||||
this.loadUsers();
|
||||
});
|
||||
},
|
||||
|
||||
onSave(user) {
|
||||
let self = this;
|
||||
this.get('userService').save(user).then(function () {
|
||||
|
||||
self.get('userService').getComplete().then(function (users) {
|
||||
self.set('model', users);
|
||||
this.get('userService').save(user).then(() => {
|
||||
this.get('userService').getComplete().then((users) => {
|
||||
this.set('model', users);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue