Fix custom server or registration & do some of new login UI

This commit is contained in:
David Baker 2015-07-16 17:51:21 +01:00
parent 8feeb93215
commit cfbef0177e
3 changed files with 67 additions and 12 deletions

View File

@ -28,15 +28,44 @@ var LoginController = require("../../../../src/controllers/templates/Login");
var ServerConfig = ComponentBroker.get("molecules/ServerConfig"); var ServerConfig = ComponentBroker.get("molecules/ServerConfig");
module.exports = React.createClass({ module.exports = React.createClass({
DEFAULT_HS_URL: 'https://matrix.org',
DEFAULT_IS_URL: 'https://matrix.org',
displayName: 'Login', displayName: 'Login',
mixins: [LoginController], mixins: [LoginController],
getInitialState: function() {
return {
serverConfigVisible: false
};
},
componentWillMount: function() {
this.onHSChosen();
this.customHsUrl = this.DEFAULT_HS_URL;
this.customIsUrl = this.DEFAULT_IS_URL;
},
getHsUrl: function() { getHsUrl: function() {
return this.refs.serverConfig.getHsUrl(); if (this.state.serverConfigVisible) {
return this.refs.serverConfig.getHsUrl();
} else {
return this.DEFAULT_HS_URL;
}
}, },
getIsUrl: function() { getIsUrl: function() {
return this.refs.serverConfig.getIsUrl(); if (this.state.serverConfigVisible) {
return this.refs.serverConfig.getIsUrl();
} else {
return this.DEFAULT_IS_URL;
}
},
onServerConfigVisibleChange: function(ev) {
this.setState({
serverConfigVisible: ev.target.checked
});
}, },
/** /**
@ -49,15 +78,35 @@ module.exports = React.createClass({
}; };
}, },
onHsUrlChanged: function() {
this.customHsUrl = this.getHsUrl();
this.customIsUrl = this.getIsUrl();
if (this.updateHsTimeout) {
clearTimeout(this.updateHsTimeout);
}
/*var self = this;
this.updateHsTimeout = setTimeout(function() {
self.onHSChosen();
}, 500);*/
},
componentForStep: function(step) { componentForStep: function(step) {
switch (step) { switch (step) {
case 'choose_hs': case 'choose_hs':
var serverConfigStyle = {};
if (!this.state.serverConfigVisible) {
serverConfigStyle.display = 'none';
}
return ( return (
<div> <div>
<form onSubmit={this.onHSChosen}> <input type="checkbox" value={this.state.serverConfigVisible} onChange={this.onServerConfigVisibleChange} />
<ServerConfig ref="serverConfig" /> Use custom server options (advanced)
<input type="submit" value="Continue" /> <div style={serverConfigStyle}>
</form> <ServerConfig ref="serverConfig"
defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
onHsUrlChanged={this.onHsUrlChanged}
/>
</div>
</div> </div>
); );
// XXX: clearly these should be separate organisms // XXX: clearly these should be separate organisms
@ -67,6 +116,7 @@ module.exports = React.createClass({
<form onSubmit={this.onUserPassEntered}> <form onSubmit={this.onUserPassEntered}>
<input ref="user" type="text" placeholder="username" /><br /> <input ref="user" type="text" placeholder="username" /><br />
<input ref="pass" type="password" placeholder="password" /><br /> <input ref="pass" type="password" placeholder="password" /><br />
{this.componentForStep('choose_hs')}
<input type="submit" value="Log in" /> <input type="submit" value="Log in" />
</form> </form>
</div> </div>
@ -94,7 +144,6 @@ module.exports = React.createClass({
render: function() { render: function() {
return ( return (
<div className="mx_Login"> <div className="mx_Login">
<ProgressBar value={this.state.currentStep} max={this.state.totalSteps} />
{this.loginContent()} {this.loginContent()}
</div> </div>
); );

View File

@ -39,6 +39,11 @@ module.exports = React.createClass({
}; };
}, },
componentWillMount: function() {
this.customHsUrl = this.DEFAULT_HS_URL;
this.customIsUrl = this.DEFAULT_IS_URL;
},
getRegFormVals: function() { getRegFormVals: function() {
return { return {
email: this.refs.email.getDOMNode().value, email: this.refs.email.getDOMNode().value,
@ -50,7 +55,7 @@ module.exports = React.createClass({
getHsUrl: function() { getHsUrl: function() {
if (this.state.serverConfigVisible) { if (this.state.serverConfigVisible) {
return this.refs.serverConfig.getHsUrl(); return this.customHsUrl;
} else { } else {
return this.DEFAULT_HS_URL; return this.DEFAULT_HS_URL;
} }
@ -58,7 +63,7 @@ module.exports = React.createClass({
getIsUrl: function() { getIsUrl: function() {
if (this.state.serverConfigVisible) { if (this.state.serverConfigVisible) {
return this.refs.serverConfig.getIsUrl(); return this.customIsUrl;
} else { } else {
return this.DEFAULT_IS_URL; return this.DEFAULT_IS_URL;
} }
@ -82,6 +87,8 @@ module.exports = React.createClass({
}, },
onServerUrlChanged: function(newUrl) { onServerUrlChanged: function(newUrl) {
this.customHsUrl = this.refs.serverConfig.getHsUrl();
this.customIsUrl = this.refs.serverConfig.getIsUrl();
this.forceUpdate(); this.forceUpdate();
}, },
@ -104,7 +111,7 @@ module.exports = React.createClass({
Use custom server options (advanced) Use custom server options (advanced)
<div style={serverConfigStyle}> <div style={serverConfigStyle}>
<ServerConfig ref="serverConfig" <ServerConfig ref="serverConfig"
defaultHsUrl={this.default_hs_url} defaultIsUrl={this.DEFAULT_IS_URL} defaultHsUrl={this.customHsUrl} defaultIsUrl={this.customIsUrl}
onHsUrlChanged={this.onServerUrlChanged} onIsUrlChanged={this.onServerUrlChanged} /> onHsUrlChanged={this.onServerUrlChanged} onIsUrlChanged={this.onServerUrlChanged} />
</div> </div>
<br /> <br />

View File

@ -38,8 +38,7 @@ module.exports = {
this.setState({ step: step, errorText: '', busy: false }); this.setState({ step: step, errorText: '', busy: false });
}, },
onHSChosen: function(ev) { onHSChosen: function() {
ev.preventDefault();
MatrixClientPeg.replaceUsingUrls( MatrixClientPeg.replaceUsingUrls(
this.getHsUrl(), this.getHsUrl(),
this.getIsUrl() this.getIsUrl()