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

80 lines
2.3 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-12-14 15:47:41 +00:00
import Notifier from '../../mixins/notifier';
import stringUtil from '../../utils/string';
2018-03-01 10:58:55 +00:00
import Component from '@ember/component';
2022-03-03 19:42:37 -05:00
import { inject as service } from '@ember/service';
2016-07-07 18:54:16 -07:00
2018-12-14 15:47:41 +00:00
export default Component.extend(AuthProvider, ModalMixin, Notifier, {
2018-03-01 10:58:55 +00:00
bulkUsers: '',
newUser: null,
2022-03-03 19:42:37 -05:00
i18n: service(),
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 (_.isEmpty(this.get('newUser.firstname'))) {
2018-03-01 10:58:55 +00:00
$("#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 (_.isEmpty(this.get('newUser.lastname'))) {
2018-03-01 10:58:55 +00:00
$("#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
if (_.isEmpty(this.get('newUser.email')) || !stringUtil.isEmail(this.get('newUser.email'))) {
2018-03-01 10:58:55 +00:00
$("#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 });
2022-03-03 19:42:37 -05:00
this.notifySuccess(this.i18n.localize('added'));
2018-03-01 10:58:55 +00:00
});
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 (_.isEmpty(this.get('bulkUsers'))) {
2018-03-01 10:58:55 +00:00
$("#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', '');
2022-03-03 19:42:37 -05:00
this.notifySuccess(this.i18n.localize('added'));
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
}
}
});