1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 06:09:42 +02:00
documize/gui/app/pods/customize/users/controller.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
import Ember from 'ember';
import NotifierMixin from '../../../mixins/notifier';
export default Ember.Controller.extend(NotifierMixin, {
userService: Ember.inject.service('user'),
newUser: { firstname: "", lastname: "", email: "", active: true },
actions: {
add(user) {
Ember.set(this, 'newUser', user);
2016-07-07 18:54:16 -07:00
return this.get('userService')
2016-07-07 18:54:16 -07:00
.add(this.get('newUser'))
.then((user) => {
this.showNotification('Added');
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);
});
},
2017-04-17 19:24:14 +01:00
onDelete(userId) {
2016-07-07 18:54:16 -07:00
let self = this;
2017-04-17 19:24:14 +01:00
this.get('userService').remove(userId).then(function () {
2016-07-07 18:54:16 -07:00
self.showNotification('Deleted');
2017-04-12 18:00:52 +01:00
self.get('userService').getComplete().then(function (users) {
2016-07-07 18:54:16 -07:00
self.set('model', users);
});
});
},
onSave(user) {
let self = this;
this.get('userService').save(user).then(function () {
self.showNotification('Saved');
2017-04-12 18:00:52 +01:00
self.get('userService').getComplete().then(function (users) {
2016-07-07 18:54:16 -07:00
self.set('model', users);
});
});
},
onPassword(user, password) {
2016-11-20 13:41:43 -08:00
this.get('userService').updatePassword(user.id, password);
2016-07-07 18:54:16 -07:00
this.showNotification('Password changed');
}
}
});