2022-09-02 08:53:33 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2022-09-15 10:30:58 +00:00
|
|
|
import ActionInvoker from '../lib/action-invoker';
|
2022-09-15 11:05:51 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2022-09-02 08:53:33 +00:00
|
|
|
|
|
|
|
|
export default class FormIndexSettingComponent extends Component {
|
2022-09-19 12:36:40 +00:00
|
|
|
@service toaster;
|
2022-09-15 11:05:51 +00:00
|
|
|
|
2022-09-02 08:53:33 +00:00
|
|
|
@tracked value;
|
2022-09-12 11:59:26 +00:00
|
|
|
@tracked error;
|
2022-09-02 08:53:33 +00:00
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super(...arguments);
|
|
|
|
|
|
2022-09-15 10:30:58 +00:00
|
|
|
this.invoker = new ActionInvoker();
|
|
|
|
|
|
2022-09-02 08:53:33 +00:00
|
|
|
this.setInitialValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
2022-09-10 08:34:03 +00:00
|
|
|
save(newValue) {
|
2022-09-12 11:59:26 +00:00
|
|
|
this.error = null;
|
|
|
|
|
|
|
|
|
|
try {
|
2022-09-15 11:05:51 +00:00
|
|
|
return this.args.index
|
2022-10-14 08:59:34 +00:00
|
|
|
.updateSetting(JSON.parse(newValue), this.args.setting.name)
|
2022-09-19 12:36:40 +00:00
|
|
|
.then(this.toaster.taskToast);
|
2022-09-12 11:59:26 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
this.error = error.error || error;
|
|
|
|
|
}
|
2022-09-02 08:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
async setInitialValue() {
|
2022-10-14 08:59:34 +00:00
|
|
|
this.value = await this.args.index.getSetting(this.args.setting.name);
|
2022-09-12 11:59:26 +00:00
|
|
|
this.error = null;
|
2022-09-02 08:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@action
|
2022-09-15 11:05:51 +00:00
|
|
|
reset() {
|
2022-09-12 11:59:26 +00:00
|
|
|
this.error = null;
|
2022-09-15 11:05:51 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return this.args.index
|
2022-10-14 08:59:34 +00:00
|
|
|
.resetSetting(this.args.setting.name)
|
2022-09-19 12:36:40 +00:00
|
|
|
.then(this.toaster.taskToast);
|
2022-09-15 11:05:51 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
this.error = error.error || error;
|
|
|
|
|
}
|
2022-09-02 08:53:33 +00:00
|
|
|
}
|
2022-10-15 06:55:37 +00:00
|
|
|
|
|
|
|
|
@action
|
|
|
|
|
onDidChangeValidation(error) {
|
|
|
|
|
this.error = error;
|
|
|
|
|
}
|
2022-09-02 08:53:33 +00:00
|
|
|
}
|