discourse-placeholder-theme.../javascripts/discourse/controllers/discourse-placeholder-build...

48 lines
1.1 KiB
JavaScript
Raw Normal View History

import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import EmberObject, { action } from "@ember/object";
import { isBlank } from "@ember/utils";
export default Controller.extend(ModalFunctionality, {
form: null,
onShow() {
this.set(
"form",
EmberObject.create({
key: null,
description: null,
values: [],
})
);
},
onClose() {},
@action
insertPlaceholder() {
if (isBlank(this.form.key)) {
bootbox.alert(I18n.t(themePrefix("builder.errors.no_key")));
return;
}
let output = `[wrap=placeholder key="${this.form.key}"`;
if (this.form.description) {
output = `${output} description="${this.form.description}"`;
}
if (this.form.values.length) {
if (this.form.values.length === 1) {
output = `${output} default="${this.form.values.firstObject}"`;
} else {
output = `${output} defaults="${this.form.values.join(",")}"`;
}
}
this.model.toolbarEvent.addText(`${output}][/wrap]`);
this.send("closeModal");
},
});