@@ -19,6 +19,7 @@ limitations under the License.
1919var React = require ( 'react' ) ;
2020
2121var ComponentBroker = require ( "../../../../src/ComponentBroker" ) ;
22+ var MatrixClientPeg = require ( "../../../../src/MatrixClientPeg" ) ;
2223
2324var ProgressBar = ComponentBroker . get ( "molecules/ProgressBar" ) ;
2425var Loader = require ( "react-loader" ) ;
@@ -28,15 +29,44 @@ var LoginController = require("../../../../src/controllers/templates/Login");
2829var ServerConfig = ComponentBroker . get ( "molecules/ServerConfig" ) ;
2930
3031module . exports = React . createClass ( {
32+ DEFAULT_HS_URL : 'https://matrix.org' ,
33+ DEFAULT_IS_URL : 'https://matrix.org' ,
34+
3135 displayName : 'Login' ,
3236 mixins : [ LoginController ] ,
3337
38+ getInitialState : function ( ) {
39+ return {
40+ serverConfigVisible : false
41+ } ;
42+ } ,
43+
44+ componentWillMount : function ( ) {
45+ this . onHSChosen ( ) ;
46+ this . customHsUrl = this . DEFAULT_HS_URL ;
47+ this . customIsUrl = this . DEFAULT_IS_URL ;
48+ } ,
49+
3450 getHsUrl : function ( ) {
35- return this . refs . serverConfig . getHsUrl ( ) ;
51+ if ( this . state . serverConfigVisible ) {
52+ return this . customHsUrl ;
53+ } else {
54+ return this . DEFAULT_HS_URL ;
55+ }
3656 } ,
3757
3858 getIsUrl : function ( ) {
39- return this . refs . serverConfig . getIsUrl ( ) ;
59+ if ( this . state . serverConfigVisible ) {
60+ return this . customIsUrl ;
61+ } else {
62+ return this . DEFAULT_IS_URL ;
63+ }
64+ } ,
65+
66+ onServerConfigVisibleChange : function ( ev ) {
67+ this . setState ( {
68+ serverConfigVisible : ev . target . checked
69+ } , this . onHsUrlChanged ) ;
4070 } ,
4171
4272 /**
@@ -49,15 +79,46 @@ module.exports = React.createClass({
4979 } ;
5080 } ,
5181
82+ onHsUrlChanged : function ( ) {
83+ this . customHsUrl = this . refs . serverConfig . getHsUrl ( ) ;
84+ this . customIsUrl = this . refs . serverConfig . getIsUrl ( ) ;
85+ MatrixClientPeg . replaceUsingUrls (
86+ this . getHsUrl ( ) ,
87+ this . getIsUrl ( )
88+ ) ;
89+ this . setState ( {
90+ hs_url : this . getHsUrl ( ) ,
91+ is_url : this . getIsUrl ( )
92+ } ) ;
93+ // XXX: HSes do not have to offer password auth, so we
94+ // need to update and maybe show a different component
95+ // when a new HS is entered.
96+ /*if (this.updateHsTimeout) {
97+ clearTimeout(this.updateHsTimeout);
98+ }
99+ var self = this;
100+ this.updateHsTimeout = setTimeout(function() {
101+ self.onHSChosen();
102+ }, 500);*/
103+ } ,
104+
52105 componentForStep : function ( step ) {
53106 switch ( step ) {
54107 case 'choose_hs' :
108+ var serverConfigStyle = { } ;
109+ if ( ! this . state . serverConfigVisible ) {
110+ serverConfigStyle . display = 'none' ;
111+ }
55112 return (
56113 < div >
57- < form onSubmit = { this . onHSChosen } >
58- < ServerConfig ref = "serverConfig" />
59- < input type = "submit" value = "Continue" />
60- </ form >
114+ < input type = "checkbox" value = { this . state . serverConfigVisible } onChange = { this . onServerConfigVisibleChange } />
115+ Use custom server options (advanced)
116+ < div style = { serverConfigStyle } >
117+ < ServerConfig ref = "serverConfig"
118+ defaultHsUrl = { this . customHsUrl } defaultIsUrl = { this . customIsUrl }
119+ onHsUrlChanged = { this . onHsUrlChanged }
120+ />
121+ </ div >
61122 </ div >
62123 ) ;
63124 // XXX: clearly these should be separate organisms
@@ -67,6 +128,7 @@ module.exports = React.createClass({
67128 < form onSubmit = { this . onUserPassEntered } >
68129 < input ref = "user" type = "text" placeholder = "username" /> < br />
69130 < input ref = "pass" type = "password" placeholder = "password" /> < br />
131+ { this . componentForStep ( 'choose_hs' ) }
70132 < input type = "submit" value = "Log in" />
71133 </ form >
72134 </ div >
@@ -94,7 +156,6 @@ module.exports = React.createClass({
94156 render : function ( ) {
95157 return (
96158 < div className = "mx_Login" >
97- < ProgressBar value = { this . state . currentStep } max = { this . state . totalSteps } />
98159 { this . loginContent ( ) }
99160 </ div >
100161 ) ;
0 commit comments