diff --git a/app/app/components/documize-setup.js b/app/app/components/documize-setup.js new file mode 100644 index 00000000..22302b69 --- /dev/null +++ b/app/app/components/documize-setup.js @@ -0,0 +1,62 @@ +import Ember from 'ember'; + +const { + isEmpty, + isEqual, + isPresent, + computed, + set + +} = Ember; + +export default Ember.Component.extend({ + titleEmpty: computed.empty('model.title'), + firstnameEmpty: computed.empty('model.firstname'), + 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'), + + actions: { + save() { + if (isEmpty(this.model.title)) { + set(this, 'titleError', true); + return $("#siteTitle").focus(); + } + + if (isEmpty(this.model.firstname)) { + set(this, 'adminFirstnameError', true); + return $("#adminFirstname").focus(); + } + + if (isEmpty(this.model.lastname)) { + set(this, 'adminLastnameError', true); + return $("#adminLastname").focus(); + } + + if (isEmpty(this.model.email) || !is.email(this.model.email)) { + set(this, 'adminEmailError', true); + return $("#adminEmail").focus(); + } + + if (isEmpty(this.model.password)) { + set(this, 'adminPasswordError', true); + return $("#adminPassword").focus(); + } + + this.model.allowAnonymousAccess = Ember.$("#allowAnonymousAccess").prop('checked'); + + this.get('save')().then(() => { + set(this, 'titleError', false); + set(this, 'adminFirstnameError', false); + set(this, 'adminLastnameError', false); + set(this, 'adminEmailError', false); + set(this, 'adminPasswordError', false); + }); + } + } +}); diff --git a/app/app/pods/setup/controller.js b/app/app/pods/setup/controller.js index 611277ab..ea508ba6 100644 --- a/app/app/pods/setup/controller.js +++ b/app/app/pods/setup/controller.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . 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 // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -13,45 +13,21 @@ 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(), actions: { save() { - if (is.empty(this.model.title)) { - $("#siteTitle").addClass("error").focus(); - return; - } - - if (is.empty(this.model.firstname)) { - $("#adminFirstname").addClass("error").focus(); - return; - } - - if (is.empty(this.model.lastname)) { - $("#adminLastname").addClass("error").focus(); - return; - } - - if (is.empty(this.model.email)) { - $("#adminEmail").addClass("error").focus(); - return; - } - - if (!is.email(this.model.email)) { - $("#adminEmail").addClass("error").focus(); - return; - } - - if (is.empty(this.model.password)) { - $("#adminPassword").addClass("error").focus(); - return; - } - - this.model.allowAnonymousAccess = Ember.$("#allowAnonymousAccess").prop('checked'); - - this.get('ajax').request("/setup", { + return this.get('ajax').request("/setup", { method: 'POST', data: this.model, dataType: "text", @@ -64,4 +40,4 @@ export default Ember.Controller.extend(NotifierMixin, { }); } } -}); \ No newline at end of file +}); diff --git a/app/app/pods/setup/template.hbs b/app/app/pods/setup/template.hbs index 25715da1..a49de2fa 100644 --- a/app/app/pods/setup/template.hbs +++ b/app/app/pods/setup/template.hbs @@ -9,46 +9,7 @@ Setup new database + {{documize-setup model=model save=(action 'save')}} -
-
-
-
-
Let's setup Documize
-
Database name is {{model.dbname}}
-
-
-
- -
What's your tribe called?
- {{focus-input id="siteTitle" type="text" value=model.title}} -
-
- -
What do people call you?
- {{input id="adminFirstname" type="text" value=model.firstname}} -
-
- -
How the government refers to you.
- {{input id="adminLastname" type="text" value=model.lastname}} -
-
- -
No spam. Ever!
- {{input id="adminEmail" type="email" value=model.email}} -
-
- -
Something you can remember without writing it down.
- {{input id="adminPassword" type="text" value=model.password}} -
-
Go Setup
-
-
-
-
- - diff --git a/app/app/templates/components/documize-setup.hbs b/app/app/templates/components/documize-setup.hbs new file mode 100644 index 00000000..21aeb3cb --- /dev/null +++ b/app/app/templates/components/documize-setup.hbs @@ -0,0 +1,38 @@ +
+
+
+
+
Let's setup Documize
+
Database name is {{model.dbname}}
+
+
+
+ +
What's your tribe called?
+ {{focus-input id="siteTitle" type="text" value=model.title}} +
+
+ +
What do people call you?
+ {{input id="adminFirstname" type="text" value=model.firstname class=(unless model.firstName 'error')}} +
+
+ +
How the government refers to you.
+ {{input id="adminLastname" type="text" value=model.lastname}} +
+
+ +
No spam. Ever!
+ {{input id="adminEmail" type="email" value=model.email}} +
+
+ +
Something you can remember without writing it down.
+ {{input id="adminPassword" type="text" value=model.password}} +
+
Go Setup
+
+
+
+