2022-03-16 12:33:34 +01:00
|
|
|
import Component from "@ember/component";
|
|
|
|
import { dasherize } from "@ember/string";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2023-10-09 19:03:51 +02:00
|
|
|
import { cook } from "discourse/lib/text";
|
2022-03-16 12:33:34 +01:00
|
|
|
|
|
|
|
export default Component.extend({
|
2022-06-15 08:59:09 +02:00
|
|
|
classNameBindings: [
|
|
|
|
":wizard-field",
|
|
|
|
"typeClasses",
|
|
|
|
"field.invalid",
|
|
|
|
"field.id",
|
|
|
|
],
|
2022-03-16 12:33:34 +01:00
|
|
|
|
2022-07-26 16:18:09 +02:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2023-10-09 19:03:51 +02:00
|
|
|
cook(this.field.translatedDescription).then((cookedDescription) => {
|
2022-07-26 16:18:09 +02:00
|
|
|
this.set("cookedDescription", cookedDescription);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-03-16 12:33:34 +01:00
|
|
|
@discourseComputed("field.type", "field.id")
|
|
|
|
typeClasses: (type, id) =>
|
|
|
|
`${dasherize(type)}-field ${dasherize(type)}-${dasherize(id)}`,
|
|
|
|
|
|
|
|
@discourseComputed("field.id")
|
|
|
|
fieldClass: (id) => `field-${dasherize(id)} wizard-focusable`,
|
|
|
|
|
|
|
|
@discourseComputed("field.type", "field.id")
|
|
|
|
inputComponentName(type, id) {
|
|
|
|
if (["text_only"].includes(type)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-26 16:18:09 +02:00
|
|
|
return dasherize(type === "component" ? id : `custom-wizard-field-${type}`);
|
2022-03-16 12:33:34 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed("field.type")
|
|
|
|
textType(fieldType) {
|
|
|
|
return ["text", "textarea"].includes(fieldType);
|
|
|
|
},
|
|
|
|
});
|