github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/server/camlistored/ui/mobile_setup.js (about)

     1  /*
     2  Copyright 2014 The Camlistore Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  goog.provide('cam.MobileSetupView');
    17  
    18  goog.require('goog.Uri');
    19  
    20  cam.MobileSetupView = React.createClass({
    21  	displayName: 'MobileSetupView',
    22  
    23  	propTypes: {
    24  		baseURL: React.PropTypes.object.isRequired,
    25  		defaultUsername: React.PropTypes.string.isRequired,
    26  	},
    27  
    28  	getInitialState: function() {
    29  		var serverURL = this.props.baseURL.clone().setPath('').setQuery('');
    30  		return {
    31  			autoUpload: false,
    32  			// TODO(wathiede): autopopulate this, not sure how.
    33  			certFingerprint: '',
    34  			maxCacheSize: 256,
    35  			server: serverURL.toString()
    36  		};
    37  	},
    38  
    39  	getQRURL_: function() {
    40  		// TODO(wathiede): I'm not sure what the Android and iPhone requirements are for registering a URL handler are.  If they can't be the same for both platforms, then we'll need this to be conditional based on a checkbox in the form.
    41  		var settingsURL = goog.Uri.parse('camli://settings/');
    42  		if (this.state.username != '') {
    43  			settingsURL.setParameterValue('username', this.state.username);
    44  		}
    45  		if (this.state.server != '') {
    46  			settingsURL.setParameterValue('server', this.state.server);
    47  		}
    48  		if (this.state.autoUpload) {
    49  			settingsURL.setParameterValue('autoUpload', 1);
    50  		}
    51  		settingsURL.setParameterValue('maxCacheSize', this.state.maxCacheSize);
    52  		if (this.state.certFingerprint != '') {
    53  			settingsURL.setParameterValue('certFingerprint', this.state.certFingerprint);
    54  		}
    55  
    56  		var qrURL = this.props.baseURL.clone();
    57  		qrURL.setPath(qrURL.getPath() + '/qr/').setParameterValue('url', settingsURL.toString());
    58  		return qrURL.toString();
    59  	},
    60  
    61  	handleServerChange_: function(e) {
    62  		this.setState({server: e.target.value});
    63  	},
    64  
    65  	handleUsernameChange_: function(e) {
    66  		this.setState({username: e.target.value});
    67  	},
    68  
    69  	handleAutoUploadChange_: function(e) {
    70  		this.setState({autoUpload: e.target.checked});
    71  	},
    72  
    73  	handleMaxCacheSizeChange_: function(e) {
    74  		this.setState({maxCacheSize: e.target.value});
    75  	},
    76  
    77  	handleCertFingerprintChange_: function(e) {
    78  		this.setState({certFingerprint: e.target.value});
    79  	},
    80  
    81  	render: function() {
    82  		return (
    83  			React.DOM.div({},
    84  				React.DOM.img({src:this.getQRURL_()}),
    85  				React.DOM.form({ref:'form', onSubmit:this.handleChange_},
    86  					React.DOM.label({}, 'Camlistore Server:',
    87  						React.DOM.input({
    88  							defaultValue: this.state.server,
    89  							onChange: this.handleServerChange_,
    90  							placeholder: 'e.g. https://foo.example.com or example.com:3179',
    91  							type: 'text'
    92  						})),
    93  					React.DOM.label({}, 'Username:',
    94  						React.DOM.input({
    95  							defaultValue: this.props.defaultUsername,
    96  							onChange: this.handleUsernameChange_,
    97  							placeholder: '<unset>',
    98  							type: 'text'
    99  						})),
   100  					React.DOM.label({className: 'mobile-setup-auto-upload'},
   101  						React.DOM.input({
   102  							onChange: this.handleAutoUploadChange_,
   103  							type: 'checkbox'
   104  						}),
   105  						'Auto-Upload',
   106  						React.DOM.span({className: 'mobile-setup-helptext'}, 'Upload SD card files as created')),
   107  					// TODO(wathiede): add suboptions to auto-upload?
   108  					React.DOM.label({className: 'mobile-setup-max-cache-size'},
   109  						'Maximum cache size',
   110  						React.DOM.input({
   111  							defaultValue: this.state.maxCacheSize,
   112  							onChange: this.handleMaxCacheSizeChange_,
   113  							type: 'text'
   114  						}),
   115  						'MB'),
   116  					React.DOM.label({}, 'Self-signed cert fingerprint:',
   117  						React.DOM.input({
   118  							onChange: this.handleCertFingerprintChange_,
   119  							placeholder: '<unset; optional 20 hex SHA-256 prefix>',
   120  							type: 'text'
   121  						}))
   122  			)));
   123  	},
   124  
   125  	handleChange_: function() {
   126  		var u = this.getQRURL_();
   127  		console.log(u);
   128  	},
   129  });