mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Refactor setup route to use a component
This commit is contained in:
parent
bb89ad90f2
commit
6beaaa3122
4 changed files with 113 additions and 76 deletions
62
app/app/components/documize-setup.js
Normal file
62
app/app/components/documize-setup.js
Normal file
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,11 +1,11 @@
|
|||
// 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
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// 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, {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,46 +9,7 @@
|
|||
<img src="/assets/img/setup/cogs.png" width="157" height="187" alt="Setup new database" class="no-select no-outline" />
|
||||
</div>
|
||||
</div>
|
||||
{{documize-setup model=model save=(action 'save')}}
|
||||
|
||||
<div class="col-lg-9 col-md-9 col-sm-9">
|
||||
<div class="input-form">
|
||||
<form>
|
||||
<div class="heading">
|
||||
<div class="title">Let's setup Documize</div>
|
||||
<div class="tip">Database name is <em>{{model.dbname}}</em></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="input-control">
|
||||
<label>Team</label>
|
||||
<div class="tip">What's your tribe called?</div>
|
||||
{{focus-input id="siteTitle" type="text" value=model.title}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Firstname</label>
|
||||
<div class="tip">What do people call you?</div>
|
||||
{{input id="adminFirstname" type="text" value=model.firstname}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Lastname</label>
|
||||
<div class="tip">How the government refers to you.</div>
|
||||
{{input id="adminLastname" type="text" value=model.lastname}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Email</label>
|
||||
<div class="tip">No spam. Ever!</div>
|
||||
{{input id="adminEmail" type="email" value=model.email}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Password</label>
|
||||
<div class="tip">Something you can remember without writing it down.</div>
|
||||
{{input id="adminPassword" type="text" value=model.password}}
|
||||
</div>
|
||||
<div class="regular-button button-green" {{ action 'save' }}>Go Setup</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
38
app/app/templates/components/documize-setup.hbs
Normal file
38
app/app/templates/components/documize-setup.hbs
Normal file
|
@ -0,0 +1,38 @@
|
|||
<div class="col-lg-9 col-md-9 col-sm-9">
|
||||
<div class="input-form">
|
||||
<form>
|
||||
<div class="heading">
|
||||
<div class="title">Let's setup Documize</div>
|
||||
<div class="tip">Database name is <em>{{model.dbname}}</em></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="input-control">
|
||||
<label>Team</label>
|
||||
<div class="tip">What's your tribe called?</div>
|
||||
{{focus-input id="siteTitle" type="text" value=model.title}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Firstname</label>
|
||||
<div class="tip">What do people call you?</div>
|
||||
{{input id="adminFirstname" type="text" value=model.firstname class=(unless model.firstName 'error')}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Lastname</label>
|
||||
<div class="tip">How the government refers to you.</div>
|
||||
{{input id="adminLastname" type="text" value=model.lastname}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Email</label>
|
||||
<div class="tip">No spam. Ever!</div>
|
||||
{{input id="adminEmail" type="email" value=model.email}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Password</label>
|
||||
<div class="tip">Something you can remember without writing it down.</div>
|
||||
{{input id="adminPassword" type="text" value=model.password}}
|
||||
</div>
|
||||
<div class="regular-button button-green" {{ action 'save' }}>Go Setup</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue