Refactor dialog buttons

This commit is contained in:
isaisstillalive 2020-07-07 08:33:51 +09:00
parent 76fb637606
commit b1fce1b115
2 changed files with 6 additions and 11 deletions

View File

@ -365,23 +365,18 @@ export class DialogWithForm extends Dialog {
* @param {Application} param0.app * @param {Application} param0.app
* @param {string} param0.title * @param {string} param0.title
* @param {string} param0.desc * @param {string} param0.desc
* @param {string=} param0.confirmButton * @param {array=} param0.buttons
* @param {string=} param0.confirmButtonId
* @param {string=} param0.extraButton * @param {string=} param0.extraButton
* @param {Array<FormElement>} param0.formElements * @param {Array<FormElement>} param0.formElements
*/ */
constructor({ app, title, desc, formElements, confirmButton = "ok:good", extraButton = null }) { constructor({ app, title, desc, formElements, buttons = ["cancel", "ok:good"], confirmButtonId = "ok" }) {
let html = ""; let html = "";
html += desc + "<br>"; html += desc + "<br>";
for (let i = 0; i < formElements.length; ++i) { for (let i = 0; i < formElements.length; ++i) {
html += formElements[i].getHtml(); html += formElements[i].getHtml();
} }
let buttons = null;
if (extraButton) {
buttons = [extraButton, "cancel", confirmButton];
} else {
buttons = ["cancel", confirmButton];
}
super({ super({
app, app,
title: title, title: title,
@ -390,10 +385,10 @@ export class DialogWithForm extends Dialog {
type: "info", type: "info",
closeButton: true, closeButton: true,
}); });
this.confirmButtonId = confirmButton.split(":")[0]; this.confirmButtonId = confirmButtonId;
this.formElements = formElements; this.formElements = formElements;
this.enterHandler = "ok"; this.enterHandler = confirmButtonId;
} }
internalButtonHandler(id, ...payload) { internalButtonHandler(id, ...payload) {

View File

@ -303,7 +303,7 @@ export class HUDWaypoints extends BaseHUDPart {
title: T.dialogs.editMarker.title, title: T.dialogs.editMarker.title,
desc: T.dialogs.editMarker.desc, desc: T.dialogs.editMarker.desc,
formElements: [markerNameInput], formElements: [markerNameInput],
extraButton: "delete:bad", buttons: ["delete:bad", "cancel", "ok:good"],
}); });
this.root.hud.parts.dialogs.internalShowDialog(dialog); this.root.hud.parts.dialogs.internalShowDialog(dialog);