}
}
- handleChange(value) {
+ handleChange = value => {
clearTimeout(this.timeout);
this.props.changeValue(this.props.setting.definition.key, value);
if (this.props.setting.definition.type === TYPE_PASSWORD) {
this.handleSave();
}
- }
+ };
- handleReset() {
+ handleReset = () => {
const componentKey = this.props.component ? this.props.component.key : null;
const { definition } = this.props.setting;
return this.props
.catch(() => {
/* do nothing */
});
- }
+ };
- handleCancel() {
+ handleCancel = () => {
const componentKey = this.props.component ? this.props.component.key : null;
this.props.cancelChange(this.props.setting.definition.key, componentKey);
this.props.passValidation(this.props.setting.definition.key);
- }
+ };
- handleSave() {
- this.safeSetState({ success: false });
- const componentKey = this.props.component ? this.props.component.key : null;
- this.props
- .saveValue(this.props.setting.definition.key, componentKey)
- .then(() => {
- this.safeSetState({ success: true });
- this.timeout = setTimeout(() => this.safeSetState({ success: false }), 3000);
- })
- .catch(() => {
- /* do nothing */
- });
- }
+ handleSave = () => {
+ if (this.props.changedValue != null) {
+ this.safeSetState({ success: false });
+ const componentKey = this.props.component ? this.props.component.key : null;
+ this.props
+ .saveValue(this.props.setting.definition.key, componentKey)
+ .then(() => {
+ this.safeSetState({ success: true });
+ this.timeout = setTimeout(() => this.safeSetState({ success: false }), 3000);
+ })
+ .catch(() => {
+ /* do nothing */
+ });
+ }
+ };
render() {
const { setting, changedValue, loading } = this.props;
)}
</div>
- <Input setting={setting} value={effectiveValue} onChange={this.handleChange.bind(this)} />
+ <Input
+ setting={setting}
+ value={effectiveValue}
+ onCancel={this.handleCancel}
+ onChange={this.handleChange}
+ onSave={this.handleSave}
+ />
{!hasValueChanged && (
<DefinitionDefaults
setting={setting}
isDefault={isDefault}
- onReset={() => this.handleReset()}
+ onReset={this.handleReset}
/>
)}
{hasValueChanged && (
- <DefinitionChanges
- onSave={this.handleSave.bind(this)}
- onCancel={this.handleCancel.bind(this)}
- />
+ <DefinitionChanges onSave={this.handleSave} onCancel={this.handleCancel} />
)}
</div>
</div>
...defaultInputPropTypes,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
type: PropTypes.string.isRequired,
- className: PropTypes.string.isRequired
+ className: PropTypes.string.isRequired,
+ onCancel: PropTypes.func,
+ onSave: PropTypes.func
};
- handleInputChange(e) {
- this.props.onChange(e.target.value);
- }
+ handleInputChange = event => {
+ this.props.onChange(event.currentTarget.value);
+ };
+
+ handleKeyDown = event => {
+ if (event.keyCode === 13) {
+ if (this.props.onSave) {
+ this.props.onSave();
+ }
+ } else if (event.keyCode === 27) {
+ if (this.props.onCancel) {
+ this.props.onCancel();
+ }
+ }
+ };
render() {
return (
className={this.props.className + ' text-top'}
type={this.props.type}
value={this.props.value || ''}
- onChange={e => this.handleInputChange(e)}
+ onChange={this.handleInputChange}
+ onKeyDown={this.handleKeyDown}
/>
);
}