From 727fec0d5faf8f53e59b4b8fc15c46b409b7b111 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 1 Aug 2016 15:07:46 +0200 Subject: [PATCH] Refactor setup route controller to remove jquery --- app/app/components/documize-setup.js | 33 ++++++++++++------- app/app/components/forgot-password.js | 13 +++++++- app/app/components/general-settings.js | 17 +++++++--- app/app/components/password-reset.js | 12 ++++++- app/app/components/user-profile.js | 17 ++++++++-- app/app/components/user-settings.js | 17 ++++++++-- app/app/pods/setup/controller.js | 8 ----- .../templates/components/documize-setup.hbs | 10 +++--- 8 files changed, 90 insertions(+), 37 deletions(-) diff --git a/app/app/components/documize-setup.js b/app/app/components/documize-setup.js index 22302b69..d81c1f97 100644 --- a/app/app/components/documize-setup.js +++ b/app/app/components/documize-setup.js @@ -1,9 +1,18 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { isEmpty, - isEqual, - isPresent, computed, set @@ -15,35 +24,35 @@ export default Ember.Component.extend({ lastnameEmpty: computed.empty('model.lastname'), emailEmpty: computed.empty('model.email'), passwordEmpty: computed.empty('model.password'), - hasPasswordError: computed.and('titleEmpty', 'titleError'), - hasConfirmError: computed.and('firstnameEmpty', 'adminFirstnameError'), - hasPasswordError: computed.and('lastnameEmpty', 'adminLastnameError'), - hasConfirmError: computed.and('emailEmpty', 'adminEmailError'), - hasPasswordError: computed.and('passwordEmpty', 'adminPasswordError'), + hasEmptyTitleError: computed.and('titleEmpty', 'titleError'), + hasEmptyFirstnameError: computed.and('firstnameEmpty', 'adminFirstnameError'), + hasEmptyLastnameError: computed.and('lastnameEmpty', 'adminLastnameError'), + hasEmptyEmailError: computed.and('emailEmpty', 'adminEmailError'), + hasEmptyPasswordError: computed.and('passwordEmpty', 'adminPasswordError'), actions: { save() { - if (isEmpty(this.model.title)) { + if (isEmpty(this.get('model.title'))) { set(this, 'titleError', true); return $("#siteTitle").focus(); } - if (isEmpty(this.model.firstname)) { + if (isEmpty(this.get('model.firstname'))) { set(this, 'adminFirstnameError', true); return $("#adminFirstname").focus(); } - if (isEmpty(this.model.lastname)) { + if (isEmpty(this.get('model.lastname'))) { set(this, 'adminLastnameError', true); return $("#adminLastname").focus(); } - if (isEmpty(this.model.email) || !is.email(this.model.email)) { + if (isEmpty(this.get('model.email')) || !is.email(this.get('model.email'))) { set(this, 'adminEmailError', true); return $("#adminEmail").focus(); } - if (isEmpty(this.model.password)) { + if (isEmpty(this.get('model.password'))) { set(this, 'adminPasswordError', true); return $("#adminPassword").focus(); } diff --git a/app/app/components/forgot-password.js b/app/app/components/forgot-password.js index f393f5cf..261a2748 100644 --- a/app/app/components/forgot-password.js +++ b/app/app/components/forgot-password.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { @@ -24,7 +35,7 @@ export default Ember.Component.extend({ Ember.set(this, 'sayThanks', true); Ember.set(this, 'email', ''); Ember.set(this, 'emailIsEmpty', false); - }) + }); } } }); diff --git a/app/app/components/general-settings.js b/app/app/components/general-settings.js index 8cd7f3da..41a2ebc5 100644 --- a/app/app/components/general-settings.js +++ b/app/app/components/general-settings.js @@ -1,9 +1,19 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { isEmpty, computed, - get, set } = Ember; @@ -15,19 +25,18 @@ export default Ember.Component.extend({ actions: { save() { - if (isEmpty(this.model.get('title'))) { + if (isEmpty(this.get('model.title'))) { set(this, 'titleError', true); return $("#siteTitle").focus(); } - if (isEmpty(this.model.get('message'))) { + if (isEmpty(this.get('model.message'))) { set(this, 'messageError', true); return $("#siteMessage").focus(); } this.model.set('allowAnonymousAccess', Ember.$("#allowAnonymousAccess").prop('checked')); this.get('save')().then(() => { - this.showNotification('Saved'); set(this, 'titleError', false); set(this, 'messageError', false); }); diff --git a/app/app/components/password-reset.js b/app/app/components/password-reset.js index a08bfb2f..49cca5c0 100644 --- a/app/app/components/password-reset.js +++ b/app/app/components/password-reset.js @@ -1,9 +1,19 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { isEmpty, isEqual, - isPresent, computed, set diff --git a/app/app/components/user-profile.js b/app/app/components/user-profile.js index 6db56177..4fd4ee31 100644 --- a/app/app/components/user-profile.js +++ b/app/app/components/user-profile.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { @@ -38,13 +49,13 @@ export default Ember.Component.extend({ let password = this.get('password.password'); let confirmation = this.get('password.confirmation'); - if (isEmpty(this.model.get('firstname'))) { + if (isEmpty(this.get('model.firstname'))) { return $("#firstname").focus(); } - if (isEmpty(this.model.get('lastname'))) { + if (isEmpty(this.get('model.lastname'))) { return $("#lastname").focus(); } - if (isEmpty(this.model.get('email'))) { + if (isEmpty(this.get('model.email'))) { return $("#email").focus(); } diff --git a/app/app/components/user-settings.js b/app/app/components/user-settings.js index e8f79a8d..593d608f 100644 --- a/app/app/components/user-settings.js +++ b/app/app/components/user-settings.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// 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 . +// +// https://documize.com + import Ember from 'ember'; const { @@ -18,15 +29,15 @@ export default Ember.Component.extend({ actions: { add() { - if (isEmpty(this.newUser.firstname)) { + if (isEmpty(this.get('newUser.firstname'))) { set(this, 'firstnameError', true); return $("#newUserFirstname").focus(); } - if (isEmpty(this.newUser.lastname)) { + if (isEmpty(this.get('newUser.lastname'))) { set(this, 'lastnameError', true); return $("#newUserLastname").focus(); } - if (isEmpty(this.newUser.email) || is.not.email(this.newUser.email)) { + if (isEmpty(this.get('newUser.email')) || is.not.email(this.get('newUser.email'))) { set(this, 'emailError', true); return $("#newUserEmail").focus(); } diff --git a/app/app/pods/setup/controller.js b/app/app/pods/setup/controller.js index ea508ba6..6bfffb01 100644 --- a/app/app/pods/setup/controller.js +++ b/app/app/pods/setup/controller.js @@ -13,14 +13,6 @@ import Ember from 'ember'; import NotifierMixin from "../../mixins/notifier"; import Encoding from "../../utils/encoding"; -const { - isEmpty, - computed, - isPresent, - get, - set -} = Ember; - export default Ember.Controller.extend(NotifierMixin, { ajax: Ember.inject.service(), diff --git a/app/app/templates/components/documize-setup.hbs b/app/app/templates/components/documize-setup.hbs index 21aeb3cb..ab0df0f7 100644 --- a/app/app/templates/components/documize-setup.hbs +++ b/app/app/templates/components/documize-setup.hbs @@ -9,27 +9,27 @@
What's your tribe called?
- {{focus-input id="siteTitle" type="text" value=model.title}} + {{focus-input id="siteTitle" type="text" value=model.title class=(if hasEmptyTitleError 'error')}}
What do people call you?
- {{input id="adminFirstname" type="text" value=model.firstname class=(unless model.firstName 'error')}} + {{input id="adminFirstname" type="text" value=model.firstname class=(if hasEmptyFirstnameError 'error')}}
How the government refers to you.
- {{input id="adminLastname" type="text" value=model.lastname}} + {{input id="adminLastname" type="text" value=model.lastname class=(if hasEmptyLastnameError 'error')}}
No spam. Ever!
- {{input id="adminEmail" type="email" value=model.email}} + {{input id="adminEmail" type="email" value=model.email class=(if hasEmptyEmailError 'error')}}
Something you can remember without writing it down.
- {{input id="adminPassword" type="text" value=model.password}} + {{input id="adminPassword" type="text" value=model.password class=(if hasEmptyPasswordError 'error')}}
Go Setup