class aiCategoryManager extends zui.Component
{
static NAME = "aiCategoryManager";
init() {
this.render();
}
afterInit() {
this.$element.on("click", ".btn-add", (e) => {
const $target = $(e.currentTarget).closest(".category-item");
const $newItem = this.createCustomItem();
$target.after($newItem);
});
this.$element.on("click", ".btn-delete", (e) => {
const $item = $(e.currentTarget).closest(".category-item");
if ($item.find(".btn-delete").is(":disabled")) return;
$item.remove();
});
}
createCategoryItem(key, value, isBuiltIn, isUsed) {
const $item = $(`
`);
return $item;
}
createCustomItem() {
const timestamp = Date.now();
return $(`
`);
}
render() {
const options = this.options;
const $element = this.$element;
$element.empty();
Object.entries(options.builtInList).forEach(([key, value]) => {
const $item = this.createCategoryItem(key, value, true, false);
$element.append($item);
});
Object.entries(options.customList).forEach(([key, value]) => {
const isUsed = options.usedCustomList.includes(key);
const $item = this.createCategoryItem(key, value, false, isUsed);
$element.append($item);
});
}
}
aiCategoryManager.defineFn();
/* Extend aiCategoryManager to zui object. */
$.extend(zui, {aiCategoryManager});