discourse-placeholder-theme.../javascripts/discourse/components/modal/discourse-placeholder-build...

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-12-05 17:15:32 -05:00
import Component from "@ember/component";
import EmberObject, { action } from "@ember/object";
2024-03-27 13:55:28 -04:00
import { service } from "@ember/service";
2023-12-05 17:15:32 -05:00
import { isBlank } from "@ember/utils";
import I18n from "I18n";
export default class DiscoursePlaceholderBuilder extends Component {
@service dialog;
form = EmberObject.create({
key: null,
description: null,
values: [],
});
@action
updateKey(event) {
this.form.set("key", event.target.value);
}
@action
updateDescription(event) {
this.form.set("description", event.target.value);
}
@action
insertPlaceholder() {
if (isBlank(this.form.key)) {
this.dialog.alert(I18n.t(themePrefix("builder.errors.no_key")));
return;
}
let output = `[wrap=placeholder key="${this.form.key}"`;
if (this.form.description) {
output += ` description="${this.form.description}"`;
}
if (this.form.values.length) {
if (this.form.values.length === 1) {
output += ` default="${this.form.values.firstObject}"`;
} else {
output += ` defaults="${this.form.values.join(",")}"`;
}
}
output += "][/wrap]";
this.model.toolbarEvent.addText(output);
this.closeModal();
}
}