mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 13:43:44 +08:00
c7475ee03b
* DEV: Import ember/object rather than Ember.Object globally * fixed broken object proxy import * prettier on js * added @ember/object/proxy to loader * added unstaged file * Fixed objet proxy reference is loader * Linting!
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
import EmberObject from "@ember/object";
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
import ValidState from "wizard/mixins/valid-state";
|
|
import { ajax } from "wizard/lib/ajax";
|
|
|
|
export default EmberObject.extend(ValidState, {
|
|
id: null,
|
|
|
|
@computed("index")
|
|
displayIndex: index => index + 1,
|
|
|
|
@computed("fields.[]")
|
|
fieldsById(fields) {
|
|
const lookup = {};
|
|
fields.forEach(field => (lookup[field.get("id")] = field));
|
|
return lookup;
|
|
},
|
|
|
|
validate() {
|
|
let allValid = true;
|
|
const result = { warnings: [] };
|
|
|
|
this.fields.forEach(field => {
|
|
allValid = allValid && field.check();
|
|
const warning = field.get("warning");
|
|
if (warning) {
|
|
result.warnings.push(warning);
|
|
}
|
|
});
|
|
|
|
this.setValid(allValid);
|
|
|
|
return result;
|
|
},
|
|
|
|
fieldError(id, description) {
|
|
const field = this.fields.findBy("id", id);
|
|
if (field) {
|
|
field.setValid(false, description);
|
|
}
|
|
},
|
|
|
|
save() {
|
|
const fields = {};
|
|
this.fields.forEach(f => (fields[f.id] = f.value));
|
|
|
|
return ajax({
|
|
url: `/wizard/steps/${this.id}`,
|
|
type: "PUT",
|
|
data: { fields }
|
|
}).catch(response => {
|
|
response.responseJSON.errors.forEach(err =>
|
|
this.fieldError(err.field, err.description)
|
|
);
|
|
throw new Error(response);
|
|
});
|
|
}
|
|
});
|