|
|
@ -148,42 +148,68 @@ class SettingsComponent extends Component { |
|
|
|
|
|
|
|
|
|
|
|
bindValue(e) { |
|
|
|
bindValue(e) { |
|
|
|
let next = Object.assign({}, this.state); |
|
|
|
let next = Object.assign({}, this.state); |
|
|
|
|
|
|
|
let error = false; |
|
|
|
|
|
|
|
|
|
|
|
next.errors.json = ''; |
|
|
|
next.errors.json = ''; |
|
|
|
try { |
|
|
|
try { |
|
|
|
this.validate(e.target); |
|
|
|
this.validate(e.target); |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
next.errors.json = err.message; |
|
|
|
next.errors.json = err.message; |
|
|
|
|
|
|
|
error = true; |
|
|
|
} |
|
|
|
} |
|
|
|
next.settings[e.target.name] = e.target.value; |
|
|
|
next.settings[e.target.name] = e.target.value; |
|
|
|
|
|
|
|
|
|
|
|
this.setState(next); |
|
|
|
this.setState(this.state); |
|
|
|
|
|
|
|
if (!error) { |
|
|
|
this.context.store.dispatch(settingActions.save(next.settings)); |
|
|
|
this.context.store.dispatch(settingActions.save(next.settings)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bindSource(e) { |
|
|
|
migrateToForm() { |
|
|
|
let from = this.state.settings.source; |
|
|
|
|
|
|
|
let to = e.target.value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let next = Object.assign({}, this.state); |
|
|
|
|
|
|
|
if (from === 'form' && to === 'json') { |
|
|
|
|
|
|
|
next.settings.json = |
|
|
|
|
|
|
|
settingsValues.jsonFromForm(this.state.settings.form); |
|
|
|
|
|
|
|
} else if (from === 'json' && to === 'form') { |
|
|
|
|
|
|
|
let b = window.confirm(DO_YOU_WANT_TO_CONTINUE); |
|
|
|
let b = window.confirm(DO_YOU_WANT_TO_CONTINUE); |
|
|
|
if (!b) { |
|
|
|
if (!b) { |
|
|
|
this.setState(this.state); |
|
|
|
this.setState(this.state); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
next.settings.form = |
|
|
|
try { |
|
|
|
settingsValues.formFromJson( |
|
|
|
validator.validate(JSON.parse(this.state.settings.json)); |
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
this.setState(this.state); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let form = settingsValues.formFromJson( |
|
|
|
this.state.settings.json, KeymapsForm.AllowdOps); |
|
|
|
this.state.settings.json, KeymapsForm.AllowdOps); |
|
|
|
|
|
|
|
let next = Object.assign({}, this.state); |
|
|
|
|
|
|
|
next.settings.form = form; |
|
|
|
|
|
|
|
next.settings.source = 'form'; |
|
|
|
|
|
|
|
next.errors.json = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setState(next); |
|
|
|
|
|
|
|
this.context.store.dispatch(settingActions.save(next.settings)); |
|
|
|
} |
|
|
|
} |
|
|
|
next.settings.source = to; |
|
|
|
|
|
|
|
|
|
|
|
migrateToJson() { |
|
|
|
|
|
|
|
let json = settingsValues.jsonFromForm(this.state.settings.form); |
|
|
|
|
|
|
|
let next = Object.assign({}, this.state); |
|
|
|
|
|
|
|
next.settings.json = json; |
|
|
|
|
|
|
|
next.settings.source = 'json'; |
|
|
|
|
|
|
|
next.errors.json = ''; |
|
|
|
|
|
|
|
|
|
|
|
this.setState(next); |
|
|
|
this.setState(next); |
|
|
|
this.context.store.dispatch(settingActions.save(next.settings)); |
|
|
|
this.context.store.dispatch(settingActions.save(next.settings)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindSource(e) { |
|
|
|
|
|
|
|
let from = this.state.settings.source; |
|
|
|
|
|
|
|
let to = e.target.value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (from === 'form' && to === 'json') { |
|
|
|
|
|
|
|
this.migrateToJson(); |
|
|
|
|
|
|
|
} else if (from === 'json' && to === 'form') { |
|
|
|
|
|
|
|
this.migrateToForm(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default SettingsComponent; |
|
|
|
export default SettingsComponent; |
|
|
|