1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
documize/gui/app/components/customize/user-admin.js

74 lines
2 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 $ from 'jquery';
import AuthProvider from '../../mixins/auth';
2017-12-11 14:39:12 +00:00
import ModalMixin from '../../mixins/modal';
2018-03-01 10:58:55 +00:00
import Component from '@ember/component';
2016-07-07 18:54:16 -07:00
2017-12-11 14:39:12 +00:00
export default Component.extend(AuthProvider, ModalMixin, {
2018-03-01 10:58:55 +00:00
bulkUsers: '',
newUser: null,
2016-07-07 18:54:16 -07:00
init() {
this._super(...arguments);
this.set('newUser', { firstname: '', lastname: '', email: '', editor: true, viewUsers: true, active: true });
},
2016-07-07 18:54:16 -07:00
actions: {
2018-03-01 10:58:55 +00:00
onOpenUserModal() {
this.modalOpen("#add-user-modal", {"show": true}, '#newUserFirstname');
2016-07-07 18:54:16 -07:00
},
2018-03-01 10:58:55 +00:00
onAddUser() {
if (is.empty(this.get('newUser.firstname'))) {
$("#newUserFirstname").addClass('is-invalid').focus();
2016-07-07 18:54:16 -07:00
return;
}
2018-03-01 10:58:55 +00:00
$("#newUserFirstname").removeClass('is-invalid');
if (is.empty(this.get('newUser.lastname'))) {
$("#newUserLastname").addClass('is-invalid').focus();
2016-07-07 18:54:16 -07:00
return;
}
2018-03-01 10:58:55 +00:00
$("#newUserLastname").removeClass('is-invalid');
2016-07-07 18:54:16 -07:00
2018-03-01 10:58:55 +00:00
if (is.empty(this.get('newUser.email')) || is.not.email(this.get('newUser.email'))) {
$("#newUserEmail").addClass('is-invalid').focus();
return;
2016-07-07 18:54:16 -07:00
}
2018-03-01 10:58:55 +00:00
$("#newUserEmail").removeClass('is-invalid');
2016-07-07 18:54:16 -07:00
2018-03-01 10:58:55 +00:00
let user = this.get('newUser');
2018-03-01 10:58:55 +00:00
this.get('onAddUser')(user).then(() => {
this.set('newUser', { firstname: '', lastname: '', email: '', active: true });
});
2017-11-29 10:31:00 +00:00
2018-03-01 10:58:55 +00:00
this.modalClose("#add-user-modal");
2017-04-17 19:24:14 +01:00
},
2018-03-01 10:58:55 +00:00
onAddUsers() {
if (is.empty(this.get('bulkUsers'))) {
$("#bulkUsers").addClass('is-invalid').focus();
return;
}
$("#bulkUsers").removeClass('is-invalid');
2018-03-01 10:58:55 +00:00
this.get('onAddUsers')(this.get('bulkUsers')).then(() => {
this.set('bulkUsers', '');
2017-04-17 19:24:14 +01:00
});
2018-03-01 10:58:55 +00:00
this.modalClose("#add-user-modal");
2016-07-07 18:54:16 -07:00
}
}
});