mirror of
https://github.com/documize/community.git
synced 2025-07-30 02:29:43 +02:00
Refactor user settings to use component
This commit is contained in:
parent
fadbb57188
commit
ab94dabbd2
5 changed files with 96 additions and 46 deletions
70
app/app/components/user-settings.js
Normal file
70
app/app/components/user-settings.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
const {
|
||||||
|
isPresent,
|
||||||
|
isEmpty,
|
||||||
|
computed,
|
||||||
|
set,
|
||||||
|
get
|
||||||
|
} = Ember;
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
newUser: { firstname: "", lastname: "", email: "", active: true },
|
||||||
|
userFirstnameError: computed('firstnameError', 'newUser.firstname', {
|
||||||
|
get() {
|
||||||
|
let error = get(this, 'firstnameError');
|
||||||
|
let firstname = get(this, 'newUser.firstname');
|
||||||
|
if (isPresent(error) && isEmpty(firstname)) {
|
||||||
|
return `error`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
userLastnameError: computed('lastnameError', 'newUser.lastname', {
|
||||||
|
get() {
|
||||||
|
let error = get(this, 'lastnameError');
|
||||||
|
let lastname = get(this, 'newUser.lastname');
|
||||||
|
if (isPresent(error) && isEmpty(lastname)) {
|
||||||
|
return `error`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
userEmailError: computed('emailError', 'newUser.email', {
|
||||||
|
get() {
|
||||||
|
let error = get(this, 'emailError');
|
||||||
|
let email = get(this, 'newUser.email');
|
||||||
|
if (isPresent(error)) {
|
||||||
|
return `error`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
add() {
|
||||||
|
if (isEmpty(this.newUser.firstname)) {
|
||||||
|
set(this, 'firstnameError', 'error');
|
||||||
|
return $("#newUserFirstname").focus();
|
||||||
|
}
|
||||||
|
if (isEmpty(this.newUser.lastname)) {
|
||||||
|
set(this, 'lastnameError', 'error');
|
||||||
|
return $("#newUserLastname").focus();
|
||||||
|
}
|
||||||
|
if (isEmpty(this.newUser.email) || is.not.email(this.newUser.email)) {
|
||||||
|
set(this, 'emailError', 'error');
|
||||||
|
return $("#newUserEmail").focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = get(this, 'newUser');
|
||||||
|
|
||||||
|
get(this, 'add')(user).then(() => {
|
||||||
|
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
||||||
|
$("#newUserFirstname").focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -12,10 +12,6 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import NotifierMixin from "../../../mixins/notifier";
|
import NotifierMixin from "../../../mixins/notifier";
|
||||||
|
|
||||||
const {
|
|
||||||
isEmpty
|
|
||||||
} = Ember;
|
|
||||||
|
|
||||||
export default Ember.Controller.extend(NotifierMixin, {
|
export default Ember.Controller.extend(NotifierMixin, {
|
||||||
orgService: Ember.inject.service('organization'),
|
orgService: Ember.inject.service('organization'),
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
//
|
//
|
||||||
// This software (Documize Community Edition) is licensed under
|
// This software (Documize Community Edition) is licensed under
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
//
|
//
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
// by contacting <sales@documize.com>.
|
// by contacting <sales@documize.com>.
|
||||||
//
|
//
|
||||||
// https://documize.com
|
// https://documize.com
|
||||||
|
|
||||||
|
@ -17,30 +17,13 @@ export default Ember.Controller.extend(NotifierMixin, {
|
||||||
newUser: { firstname: "", lastname: "", email: "", active: true },
|
newUser: { firstname: "", lastname: "", email: "", active: true },
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
add: function () {
|
add(user) {
|
||||||
if (is.empty(this.newUser.firstname)) {
|
Ember.set(this, 'newUser', user);
|
||||||
$("#newUserFirstname").addClass("error").focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (is.empty(this.newUser.lastname)) {
|
|
||||||
$("#newUserLastname").addClass("error").focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (is.empty(this.newUser.email) || is.not.email(this.newUser.email)) {
|
|
||||||
$("#newUserEmail").addClass("error").focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#newUserFirstname").removeClass("error");
|
return this.get('userService')
|
||||||
$("#newUserLastname").removeClass("error");
|
|
||||||
$("#newUserEmail").removeClass("error");
|
|
||||||
|
|
||||||
this.get('userService')
|
|
||||||
.add(this.get('newUser'))
|
.add(this.get('newUser'))
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
this.showNotification('Added');
|
this.showNotification('Added');
|
||||||
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
|
||||||
$("#newUserFirstname").focus();
|
|
||||||
this.get('model').pushObject(user);
|
this.get('model').pushObject(user);
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
@ -76,4 +59,4 @@ export default Ember.Controller.extend(NotifierMixin, {
|
||||||
this.showNotification('Password changed');
|
this.showNotification('Password changed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +1,5 @@
|
||||||
<div class="input-form form-borderless">
|
<div class="input-form form-borderless">
|
||||||
<form>
|
{{user-settings add=(action 'add')}}
|
||||||
<div class="heading">
|
|
||||||
<div class="title">Add User</div>
|
|
||||||
<div class="tip">New users receive an invitation email with a random password</div>
|
|
||||||
</div>
|
|
||||||
<div class="input-control">
|
|
||||||
<label>Firstname</label>
|
|
||||||
{{focus-input id="newUserFirstname" type="text" value=newUser.firstname}}
|
|
||||||
</div>
|
|
||||||
<div class="input-control">
|
|
||||||
<label>Lastname</label>
|
|
||||||
{{input id="newUserLastname" type="text" value=newUser.lastname}}
|
|
||||||
</div>
|
|
||||||
<div class="input-control">
|
|
||||||
<label>Email</label>
|
|
||||||
{{input id="newUserEmail" type="text" value=newUser.email}}
|
|
||||||
</div>
|
|
||||||
<div class="regular-button button-blue" {{ action 'add' }}>Add</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="clearfix" /> {{settings/user-list users=model onDelete=(action "onDelete") onSave=(action "onSave") onPassword=(action "onPassword")}}
|
<div class="clearfix" /> {{settings/user-list users=model onDelete=(action "onDelete") onSave=(action "onSave") onPassword=(action "onPassword")}}
|
||||||
|
|
19
app/app/templates/components/user-settings.hbs
Normal file
19
app/app/templates/components/user-settings.hbs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<form>
|
||||||
|
<div class="heading">
|
||||||
|
<div class="title">Add User</div>
|
||||||
|
<div class="tip">New users receive an invitation email with a random password</div>
|
||||||
|
</div>
|
||||||
|
<div class="input-control">
|
||||||
|
<label>Firstname</label>
|
||||||
|
{{focus-input id="newUserFirstname" type="text" value=newUser.firstname class=userFirstnameError}}
|
||||||
|
</div>
|
||||||
|
<div class="input-control">
|
||||||
|
<label>Lastname</label>
|
||||||
|
{{input id="newUserLastname" type="text" value=newUser.lastname class=userLastnameError}}
|
||||||
|
</div>
|
||||||
|
<div class="input-control">
|
||||||
|
<label>Email</label>
|
||||||
|
{{input id="newUserEmail" type="text" value=newUser.email class=userEmailError}}
|
||||||
|
</div>
|
||||||
|
<div class="regular-button button-blue" {{ action 'add' }}>Add</div>
|
||||||
|
</form>
|
Loading…
Add table
Add a link
Reference in a new issue