mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09: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({
|
||||
email: "",
|
||||
sayThanks: false,
|
||||
emptyEmail: computed('email', 'emptyEmailError', {
|
||||
get() {
|
||||
if (isEmpty(this.get('email')) && this.get('emptyEmailError')) {
|
||||
return `error`;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}),
|
||||
emailEmpty: computed.empty('email'),
|
||||
hasEmptyEmailError: computed.and('emailEmpty', 'emailIsEmpty'),
|
||||
|
||||
actions: {
|
||||
forgot() {
|
||||
let email = this.get('email');
|
||||
|
||||
if (isEmpty(email)) {
|
||||
Ember.set(this, 'emptyEmailError', true);
|
||||
Ember.set(this, 'emailIsEmpty', true);
|
||||
return $("#email").focus();
|
||||
}
|
||||
|
||||
this.get('forgot')(email).then(() => {
|
||||
Ember.set(this, 'sayThanks', true);
|
||||
Ember.set(this, 'email', '');
|
||||
}).catch((error) => {
|
||||
let message = error.message;
|
||||
console.log(message);
|
||||
});
|
||||
Ember.set(this, 'emailIsEmpty', false);
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,50 +2,35 @@ import Ember from 'ember';
|
|||
|
||||
const {
|
||||
isEmpty,
|
||||
isPresent,
|
||||
computed,
|
||||
get,
|
||||
set
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Component.extend({
|
||||
titleInputError: computed('titleError', 'model.title', {
|
||||
get() {
|
||||
let error = get(this, 'titleError');
|
||||
let title = this.get('model.title');
|
||||
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;
|
||||
}
|
||||
}),
|
||||
titleEmpty: computed.empty('model.title'),
|
||||
messageEmpty: computed.empty('model.message'),
|
||||
hasTitleInputError: computed.and('titleEmpty', 'titleError'),
|
||||
hasMessageInputError: computed.and('messageEmpty', 'messageError'),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
if (isEmpty(this.model.get('title'))) {
|
||||
set(this, 'titleError', 'error');
|
||||
set(this, 'titleError', true);
|
||||
return $("#siteTitle").focus();
|
||||
}
|
||||
|
||||
if (isEmpty(this.model.get('message'))) {
|
||||
set(this, 'messageError', 'error');
|
||||
set(this, 'messageError', true);
|
||||
return $("#siteMessage").focus();
|
||||
}
|
||||
|
||||
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: "",
|
||||
passwordConfirm: "",
|
||||
mustMatch: false,
|
||||
passwordEmpty: computed('passwordError', {
|
||||
get() {
|
||||
let error = this.get('passwordError');
|
||||
if (isPresent(error)) {
|
||||
return `error`;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}),
|
||||
confirmEmpty: computed('passwordConfirmError', {
|
||||
get() {
|
||||
let error = this.get('passwordConfirmError');
|
||||
if (isPresent(error)) {
|
||||
return `error`;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}),
|
||||
passwordEmpty: computed.empty('password'),
|
||||
confirmEmpty: computed.empty('passwordConfirm'),
|
||||
hasPasswordError: computed.and('passwordEmpty', 'passwordIsEmpty'),
|
||||
hasConfirmError: computed.and('confirmEmpty', 'passwordConfirmIsEmpty'),
|
||||
|
||||
actions: {
|
||||
reset() {
|
||||
|
@ -40,23 +24,26 @@ export default Ember.Component.extend({
|
|||
let passwordConfirm = this.get('passwordConfirm');
|
||||
|
||||
if (isEmpty(password)) {
|
||||
set(this, 'passwordError', "error");
|
||||
set(this, 'passwordIsEmpty', true);
|
||||
return $("#newPassword").focus();
|
||||
}
|
||||
|
||||
if (isEmpty(passwordConfirm)) {
|
||||
set(this, 'passwordConfirmError', "error");
|
||||
set(this, 'passwordConfirmIsEmpty', true);
|
||||
return $("#passwordConfirm").focus();
|
||||
}
|
||||
|
||||
if (!isEqual(password, passwordConfirm)) {
|
||||
set(this, 'passwordError', "error");
|
||||
set(this, 'passwordConfirmError', "error");
|
||||
set(this, 'hasPasswordError', true);
|
||||
set(this, 'hasConfirmError', true);
|
||||
set(this, 'mustMatch', true);
|
||||
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({
|
||||
password: { password: "", confirmation: "" },
|
||||
hasFirstnameError: computed('model.firstname', {
|
||||
get() {
|
||||
if (isEmpty(this.get('model.firstname'))) {
|
||||
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;
|
||||
}
|
||||
}),
|
||||
hasFirstnameError: computed.empty('model.firstname'),
|
||||
hasLastnameError: computed.empty('model.lastname'),
|
||||
hasEmailError: computed.empty('model.email'),
|
||||
hasPasswordError: computed('passwordError', 'password.password', {
|
||||
get() {
|
||||
if (isPresent(this.get('passwordError'))) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
const {
|
||||
isPresent,
|
||||
isEmpty,
|
||||
computed,
|
||||
set,
|
||||
|
@ -10,52 +9,25 @@ const {
|
|||
|
||||
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;
|
||||
}
|
||||
}),
|
||||
firstnameEmpty: computed.empty('newUser.firstname'),
|
||||
lastnameEmpty: computed.empty('newUser.lastname'),
|
||||
emailEmpty: computed.empty('newUser.email'),
|
||||
hasFirstnameEmptyError: computed.and('firstnameEmpty', 'firstnameError'),
|
||||
hasLastnameEmptyError: computed.and('lastnameEmpty', 'lastnameError'),
|
||||
hasEmailEmptyError: computed.and('emailEmpty', 'emailError'),
|
||||
|
||||
actions: {
|
||||
add() {
|
||||
if (isEmpty(this.newUser.firstname)) {
|
||||
set(this, 'firstnameError', 'error');
|
||||
set(this, 'firstnameError', true);
|
||||
return $("#newUserFirstname").focus();
|
||||
}
|
||||
if (isEmpty(this.newUser.lastname)) {
|
||||
set(this, 'lastnameError', 'error');
|
||||
set(this, 'lastnameError', true);
|
||||
return $("#newUserLastname").focus();
|
||||
}
|
||||
if (isEmpty(this.newUser.email) || is.not.email(this.newUser.email)) {
|
||||
set(this, 'emailError', 'error');
|
||||
set(this, 'emailError', true);
|
||||
return $("#newUserEmail").focus();
|
||||
}
|
||||
|
||||
|
@ -63,6 +35,9 @@ export default Ember.Component.extend({
|
|||
|
||||
get(this, 'add')(user).then(() => {
|
||||
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
||||
set(this, 'firstnameError', false);
|
||||
set(this, 'lastnameError', false);
|
||||
set(this, 'emailError', false);
|
||||
$("#newUserFirstname").focus();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
|
||||
actions: {
|
||||
save() {
|
||||
this.get('orgService').save(this.model);
|
||||
this.showNotification('Saved');
|
||||
return this.get('orgService').save(this.model).then(() => {
|
||||
this.showNotification('Saved');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{{else}}
|
||||
<div class="input-control">
|
||||
<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 class="clearfix" />
|
||||
<div class="margin-top-10 margin-bottom-20">
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
<div class="input-control">
|
||||
<label>Title</label>
|
||||
<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 class="input-control">
|
||||
<label>Message</label>
|
||||
<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 class="input-control">
|
||||
<label>Anonymous Access</label>
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<div class="input-control">
|
||||
<label>New Password</label>
|
||||
<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 class="input-control">
|
||||
<label>Confirm Password</label>
|
||||
<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 class="clearfix" />
|
||||
<div class="margin-top-10 margin-bottom-20">
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
<form>
|
||||
<div class="input-control">
|
||||
<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 class="input-control">
|
||||
<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 class="input-control">
|
||||
<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 class="input-control">
|
||||
<label>Password</label>
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
</div>
|
||||
<div class="input-control">
|
||||
<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 class="input-control">
|
||||
<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 class="input-control">
|
||||
<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 class="regular-button button-blue" {{ action 'add' }}>Add</div>
|
||||
</form>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue