import React, { Component } from 'react'; import { Form } from 'react-bootstrap'; import ReactDOM from 'react-dom'; export default class SettingsInput extends Component { constructor(props) { super(props) this.state = { type: this.props.type, name: this.props.name, displayName: (this.props.name) ? this.formatName(this.props.name) : '', value: (this.props.value) ? this.props.value : '', classes: this.props.classes, id: this.props.id, label: (this.props.label) ? this.props.label : false, readonly: true, description: (this.props.description) ? this.props.description : false, options: this.props.options ? this.props.options : [], hideDescription: this.props.hideDescription ? true : false, min: this.props.min ? this.props.min : null, max: this.props.max ? this.props.max : null, url: this.props.url, inline: this.props.inline ? 'd-inline-block' : 'd-block', btnType: this.props.btnType, earlyReturn: this.props.earlyReturn ? true : false, autoComplete: String(this.props.autoComplete ? true : Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 7)), } } componentDidMount() { this.setState({ readonly: this.isReadOnly() }); } formatName(name) { name = name.split('_').join(' '); return name.charAt(0).toUpperCase() + name.slice(1); } handleInput = (evt) => { var val = evt.target.value; if(this.state.type === 'checkbox') { val = evt.target.checked; } this.props.handler( this.state.name, val ); this.setState({ value: val }); } isReadOnly = () => { if(window.config.editable[this.state.name] == false) { return true; } return false; } generateNumberInput(disabled) { return } generateSelectInput(disabled) { return ( {this.state.options.map((option,i) => { return })} ); } generateCheckboxInput(disabled) { return } generateTextInput(disabled) { return } generatePasswordInput(disabled) { return } generateButtonGetInput() { var url = this.state.url; return ( ); } generateInput = () => { var disabled = (this.state.readonly) ? true : false; var input = null; if(this.state.type === 'number') { input = this.generateNumberInput(disabled); } if(this.state.type === 'select') { input = this.generateSelectInput(disabled); } if(this.state.type === 'checkbox') { input = this.generateCheckboxInput(disabled); } if(this.state.type === 'text') { input = this.generateTextInput(disabled); } if(this.state.type === 'password') { input = this.generatePasswordInput(disabled); } if(this.state.type === 'btn-get') { input = this.generateButtonGetInput(); } if(this.state.earlyReturn) { return input; } return ( {this.state.label && {this.formatName(this.state.name)} } {input} {this.state.description && !this.state.hideDescription &&

} {this.state.readonly && This setting is defined as an env variable and is not editable. }
); } render() { var input = this.generateInput(); return input; } } if (document.getElementById('SettingsInput')) { ReactDOM.render(, document.getElementById('SettingsInput')); }