`;
for (i = 0; i < this.value.length; i++) {
html += `${this.value[i].name}`;
}
html += `
`;
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
break;
case "editableOptionShort":
html += `
${this.hint ? "" + this.hint + "" : ""}
`;
for (i = 0; i < this.value.length; i++) {
html += `${this.value[i].name}`;
}
html += `
`;
this.manager.addDynamicListener(".editable-option-menu a", "click", this.editableOptionClick, this);
break;
case "text":
html += `
${this.hint ? "" + this.hint + "" : ""}
`;
break;
default:
break;
}
return html;
}
/**
* Handler for populate option changes.
* Populates the relevant argument with the specified value.
*
* @param {event} e
*/
populateOptionChange(e) {
e.preventDefault();
e.stopPropagation();
const el = e.target;
const op = el.parentNode.parentNode;
const target = op.querySelectorAll(".arg")[this.target];
target.value = el.childNodes[el.selectedIndex].getAttribute("populate-value");
const evt = new Event("change");
target.dispatchEvent(evt);
this.manager.recipe.ingChange();
}
/**
* Handler for populate multi option changes.
* Populates the relevant arguments with the specified values.
*
* @param {event} e
*/
populateMultiOptionChange(e) {
e.preventDefault();
e.stopPropagation();
const el = e.target;
const op = el.parentNode.parentNode;
const args = op.querySelectorAll(".arg");
const targets = this.target.map(i => args[i]);
const vals = JSON.parse(el.childNodes[el.selectedIndex].getAttribute("populate-value"));
const evt = new Event("change");
for (let i = 0; i < targets.length; i++) {
targets[i].value = vals[i];
}
// Fire change event after all targets have been assigned
this.manager.recipe.ingChange();
// Send change event for each target once all have been assigned, to update the label placement.
for (const target of targets) {
target.dispatchEvent(evt);
}
}
/**
* Handler for editable option clicks.
* Populates the input box with the selected value.
*
* @param {event} e
*/
editableOptionClick(e) {
e.preventDefault();
e.stopPropagation();
const link = e.target,
input = link.parentNode.parentNode.parentNode.querySelector("input");
input.value = link.getAttribute("value");
const evt = new Event("change");
input.dispatchEvent(evt);
this.manager.recipe.ingChange();
}
}
export default HTMLIngredient;