mirror of
https://github.com/documize/community.git
synced 2025-07-22 14:49:42 +02:00
Use computed macros
This commit is contained in:
parent
ab94dabbd2
commit
bb89ad90f2
11 changed files with 57 additions and 142 deletions
|
@ -8,32 +8,23 @@ const {
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
email: "",
|
email: "",
|
||||||
sayThanks: false,
|
sayThanks: false,
|
||||||
emptyEmail: computed('email', 'emptyEmailError', {
|
emailEmpty: computed.empty('email'),
|
||||||
get() {
|
hasEmptyEmailError: computed.and('emailEmpty', 'emailIsEmpty'),
|
||||||
if (isEmpty(this.get('email')) && this.get('emptyEmailError')) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
forgot() {
|
forgot() {
|
||||||
let email = this.get('email');
|
let email = this.get('email');
|
||||||
|
|
||||||
if (isEmpty(email)) {
|
if (isEmpty(email)) {
|
||||||
Ember.set(this, 'emptyEmailError', true);
|
Ember.set(this, 'emailIsEmpty', true);
|
||||||
return $("#email").focus();
|
return $("#email").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.get('forgot')(email).then(() => {
|
this.get('forgot')(email).then(() => {
|
||||||
Ember.set(this, 'sayThanks', true);
|
Ember.set(this, 'sayThanks', true);
|
||||||
Ember.set(this, 'email', '');
|
Ember.set(this, 'email', '');
|
||||||
}).catch((error) => {
|
Ember.set(this, 'emailIsEmpty', false);
|
||||||
let message = error.message;
|
})
|
||||||
console.log(message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,50 +2,35 @@ import Ember from 'ember';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isEmpty,
|
isEmpty,
|
||||||
isPresent,
|
|
||||||
computed,
|
computed,
|
||||||
get,
|
get,
|
||||||
set
|
set
|
||||||
} = Ember;
|
} = Ember;
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
titleInputError: computed('titleError', 'model.title', {
|
titleEmpty: computed.empty('model.title'),
|
||||||
get() {
|
messageEmpty: computed.empty('model.message'),
|
||||||
let error = get(this, 'titleError');
|
hasTitleInputError: computed.and('titleEmpty', 'titleError'),
|
||||||
let title = this.get('model.title');
|
hasMessageInputError: computed.and('messageEmpty', 'messageError'),
|
||||||
if (isPresent(error) || isEmpty(title)) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
messageInputError: computed('messageError', 'model.message', {
|
|
||||||
get() {
|
|
||||||
let error = get(this, 'messageError');
|
|
||||||
let message = this.get('model.message');
|
|
||||||
if (isPresent(error) || isEmpty(message)) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
if (isEmpty(this.model.get('title'))) {
|
if (isEmpty(this.model.get('title'))) {
|
||||||
set(this, 'titleError', 'error');
|
set(this, 'titleError', true);
|
||||||
return $("#siteTitle").focus();
|
return $("#siteTitle").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty(this.model.get('message'))) {
|
if (isEmpty(this.model.get('message'))) {
|
||||||
set(this, 'messageError', 'error');
|
set(this, 'messageError', true);
|
||||||
return $("#siteMessage").focus();
|
return $("#siteMessage").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.model.set('allowAnonymousAccess', Ember.$("#allowAnonymousAccess").prop('checked'));
|
this.model.set('allowAnonymousAccess', Ember.$("#allowAnonymousAccess").prop('checked'));
|
||||||
this.get('save')();
|
this.get('save')().then(() => {
|
||||||
|
this.showNotification('Saved');
|
||||||
|
set(this, 'titleError', false);
|
||||||
|
set(this, 'messageError', false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,26 +13,10 @@ export default Ember.Component.extend({
|
||||||
password: "",
|
password: "",
|
||||||
passwordConfirm: "",
|
passwordConfirm: "",
|
||||||
mustMatch: false,
|
mustMatch: false,
|
||||||
passwordEmpty: computed('passwordError', {
|
passwordEmpty: computed.empty('password'),
|
||||||
get() {
|
confirmEmpty: computed.empty('passwordConfirm'),
|
||||||
let error = this.get('passwordError');
|
hasPasswordError: computed.and('passwordEmpty', 'passwordIsEmpty'),
|
||||||
if (isPresent(error)) {
|
hasConfirmError: computed.and('confirmEmpty', 'passwordConfirmIsEmpty'),
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
confirmEmpty: computed('passwordConfirmError', {
|
|
||||||
get() {
|
|
||||||
let error = this.get('passwordConfirmError');
|
|
||||||
if (isPresent(error)) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
reset() {
|
reset() {
|
||||||
|
@ -40,23 +24,26 @@ export default Ember.Component.extend({
|
||||||
let passwordConfirm = this.get('passwordConfirm');
|
let passwordConfirm = this.get('passwordConfirm');
|
||||||
|
|
||||||
if (isEmpty(password)) {
|
if (isEmpty(password)) {
|
||||||
set(this, 'passwordError', "error");
|
set(this, 'passwordIsEmpty', true);
|
||||||
return $("#newPassword").focus();
|
return $("#newPassword").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty(passwordConfirm)) {
|
if (isEmpty(passwordConfirm)) {
|
||||||
set(this, 'passwordConfirmError', "error");
|
set(this, 'passwordConfirmIsEmpty', true);
|
||||||
return $("#passwordConfirm").focus();
|
return $("#passwordConfirm").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEqual(password, passwordConfirm)) {
|
if (!isEqual(password, passwordConfirm)) {
|
||||||
set(this, 'passwordError', "error");
|
set(this, 'hasPasswordError', true);
|
||||||
set(this, 'passwordConfirmError', "error");
|
set(this, 'hasConfirmError', true);
|
||||||
set(this, 'mustMatch', true);
|
set(this, 'mustMatch', true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.get('reset')(password);
|
this.get('reset')(password).then(() => {
|
||||||
|
set(this, 'passwordIsEmpty', false);
|
||||||
|
set(this, 'passwordConfirmIsEmpty', false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,33 +9,9 @@ const {
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
password: { password: "", confirmation: "" },
|
password: { password: "", confirmation: "" },
|
||||||
hasFirstnameError: computed('model.firstname', {
|
hasFirstnameError: computed.empty('model.firstname'),
|
||||||
get() {
|
hasLastnameError: computed.empty('model.lastname'),
|
||||||
if (isEmpty(this.get('model.firstname'))) {
|
hasEmailError: computed.empty('model.email'),
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
hasLastnameError: computed('model.lastname', {
|
|
||||||
get() {
|
|
||||||
if (isEmpty(this.get('model.lastname'))) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
hasEmailError: computed('model.email', {
|
|
||||||
get() {
|
|
||||||
if (isEmpty(this.get('model.email'))) {
|
|
||||||
return `error`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
hasPasswordError: computed('passwordError', 'password.password', {
|
hasPasswordError: computed('passwordError', 'password.password', {
|
||||||
get() {
|
get() {
|
||||||
if (isPresent(this.get('passwordError'))) {
|
if (isPresent(this.get('passwordError'))) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isPresent,
|
|
||||||
isEmpty,
|
isEmpty,
|
||||||
computed,
|
computed,
|
||||||
set,
|
set,
|
||||||
|
@ -10,52 +9,25 @@ const {
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
newUser: { firstname: "", lastname: "", email: "", active: true },
|
newUser: { firstname: "", lastname: "", email: "", active: true },
|
||||||
userFirstnameError: computed('firstnameError', 'newUser.firstname', {
|
firstnameEmpty: computed.empty('newUser.firstname'),
|
||||||
get() {
|
lastnameEmpty: computed.empty('newUser.lastname'),
|
||||||
let error = get(this, 'firstnameError');
|
emailEmpty: computed.empty('newUser.email'),
|
||||||
let firstname = get(this, 'newUser.firstname');
|
hasFirstnameEmptyError: computed.and('firstnameEmpty', 'firstnameError'),
|
||||||
if (isPresent(error) && isEmpty(firstname)) {
|
hasLastnameEmptyError: computed.and('lastnameEmpty', 'lastnameError'),
|
||||||
return `error`;
|
hasEmailEmptyError: computed.and('emailEmpty', 'emailError'),
|
||||||
}
|
|
||||||
|
|
||||||
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: {
|
actions: {
|
||||||
add() {
|
add() {
|
||||||
if (isEmpty(this.newUser.firstname)) {
|
if (isEmpty(this.newUser.firstname)) {
|
||||||
set(this, 'firstnameError', 'error');
|
set(this, 'firstnameError', true);
|
||||||
return $("#newUserFirstname").focus();
|
return $("#newUserFirstname").focus();
|
||||||
}
|
}
|
||||||
if (isEmpty(this.newUser.lastname)) {
|
if (isEmpty(this.newUser.lastname)) {
|
||||||
set(this, 'lastnameError', 'error');
|
set(this, 'lastnameError', true);
|
||||||
return $("#newUserLastname").focus();
|
return $("#newUserLastname").focus();
|
||||||
}
|
}
|
||||||
if (isEmpty(this.newUser.email) || is.not.email(this.newUser.email)) {
|
if (isEmpty(this.newUser.email) || is.not.email(this.newUser.email)) {
|
||||||
set(this, 'emailError', 'error');
|
set(this, 'emailError', true);
|
||||||
return $("#newUserEmail").focus();
|
return $("#newUserEmail").focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +35,9 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
get(this, 'add')(user).then(() => {
|
get(this, 'add')(user).then(() => {
|
||||||
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
||||||
|
set(this, 'firstnameError', false);
|
||||||
|
set(this, 'lastnameError', false);
|
||||||
|
set(this, 'emailError', false);
|
||||||
$("#newUserFirstname").focus();
|
$("#newUserFirstname").focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,9 @@ export default Ember.Controller.extend(NotifierMixin, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
this.get('orgService').save(this.model);
|
return this.get('orgService').save(this.model).then(() => {
|
||||||
this.showNotification('Saved');
|
this.showNotification('Saved');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Email</label>
|
<label>Email</label>
|
||||||
{{focus-input type="email" value=email id="email" class=emptyEmail}}
|
{{focus-input type="email" value=email id="email" class=(if hasEmptyEmailError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix" />
|
<div class="clearfix" />
|
||||||
<div class="margin-top-10 margin-bottom-20">
|
<div class="margin-top-10 margin-bottom-20">
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Title</label>
|
<label>Title</label>
|
||||||
<div class="tip">Describe the title of this Documize instance</div>
|
<div class="tip">Describe the title of this Documize instance</div>
|
||||||
{{focus-input id="siteTitle" type="text" value=model.title class=titleInputError}}
|
{{focus-input id="siteTitle" type="text" value=model.title class=(if hasTitleInputError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Message</label>
|
<label>Message</label>
|
||||||
<div class="tip">Describe the purpose of this Documize instance</div>
|
<div class="tip">Describe the purpose of this Documize instance</div>
|
||||||
{{textarea id="siteMessage" rows="3" value=model.message class=messageInputError}}
|
{{textarea id="siteMessage" rows="3" value=model.message class=(if hasMessageInputError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Anonymous Access</label>
|
<label>Anonymous Access</label>
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>New Password</label>
|
<label>New Password</label>
|
||||||
<div class="tip">Choose a strong password</div>
|
<div class="tip">Choose a strong password</div>
|
||||||
{{focus-input type="password" value=password id="newPassword" class=passwordError}}
|
{{focus-input type="password" value=password id="newPassword" class=(if hasPasswordError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Confirm Password</label>
|
<label>Confirm Password</label>
|
||||||
<div class="tip">Please type your new password again</div>
|
<div class="tip">Please type your new password again</div>
|
||||||
{{input type="password" value=passwordConfirm id="passwordConfirm" class=confirmEmpty}}
|
{{input type="password" value=passwordConfirm id="passwordConfirm" class=(if hasConfirmError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix" />
|
<div class="clearfix" />
|
||||||
<div class="margin-top-10 margin-bottom-20">
|
<div class="margin-top-10 margin-bottom-20">
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
<form>
|
<form>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Firstname</label>
|
<label>Firstname</label>
|
||||||
{{focus-input id="firstname" type="text" value=model.firstname class=hasFirstnameError}}
|
{{focus-input id="firstname" type="text" value=model.firstname class=(if hasFirstnameError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Lastname</label>
|
<label>Lastname</label>
|
||||||
{{input id="lastname" type="text" value=model.lastname class=hasLastnameError}}
|
{{input id="lastname" type="text" value=model.lastname class=(if hasLastnameError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Email</label>
|
<label>Email</label>
|
||||||
{{input id="email" type="text" value=model.email class=hasEmailError}}
|
{{input id="email" type="text" value=model.email class=(if hasEmailError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Password</label>
|
<label>Password</label>
|
||||||
|
|
|
@ -5,15 +5,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Firstname</label>
|
<label>Firstname</label>
|
||||||
{{focus-input id="newUserFirstname" type="text" value=newUser.firstname class=userFirstnameError}}
|
{{focus-input id="newUserFirstname" type="text" value=newUser.firstname class=(if hasFirstnameEmptyError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Lastname</label>
|
<label>Lastname</label>
|
||||||
{{input id="newUserLastname" type="text" value=newUser.lastname class=userLastnameError}}
|
{{input id="newUserLastname" type="text" value=newUser.lastname class=(if hasLastnameEmptyError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>Email</label>
|
<label>Email</label>
|
||||||
{{input id="newUserEmail" type="text" value=newUser.email class=userEmailError}}
|
{{input id="newUserEmail" type="text" value=newUser.email class=(if hasEmailEmptyError 'error')}}
|
||||||
</div>
|
</div>
|
||||||
<div class="regular-button button-blue" {{ action 'add' }}>Add</div>
|
<div class="regular-button button-blue" {{ action 'add' }}>Add</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue