diff --git a/devTools/types/FC/facilities.d.ts b/devTools/types/FC/facilities.d.ts index fc65a86be8faa449baf9afba0bac4b3cf6037b37..b0a63a0d2e7640153dcb4b5ddaf2f3493c520f66 100644 --- a/devTools/types/FC/facilities.d.ts +++ b/devTools/types/FC/facilities.d.ts @@ -70,6 +70,8 @@ declare namespace FC { content: string|HTMLElement|DocumentFragment; /** The name of the dialog to display. */ name?: string; + /** Any prerequisites that must be met for the dialog to be displayed. */ + prereqs?: Array<() => boolean> }; }> /** Any additional nodes to attach. */ diff --git a/src/gui/options/optionsGroup.js b/src/gui/options/optionsGroup.js index 6274b50693e097b2c41160e0a3301b9d0ae403b4..c8ab55f4d2a0eac0ebc4064103b3a8bfcc90b539 100644 --- a/src/gui/options/optionsGroup.js +++ b/src/gui/options/optionsGroup.js @@ -564,10 +564,11 @@ App.UI.OptionsGroup = (function() { * * @param {HTMLElement|string|DocumentFragment} content * @param {string} name + * @param {Array.<() => boolean>} [prereqs] * @returns {this} */ - addDialog(content, name) { - this.dialog = {content, name}; + addDialog(content, name, prereqs = []) { + this.dialog = {content, name, prereqs}; return this; } @@ -583,18 +584,22 @@ App.UI.OptionsGroup = (function() { } if (this.dialog) { - container.onclick = () => { - if (Dialog.isOpen()) { - Dialog.close(); - } - if (this.dialog.name) { - Dialog.setup(this.dialog.name); - } - const frag = new DocumentFragment(); - frag.append(this.dialog.content); - $(Dialog.body()).empty().append(frag); - Dialog.open(); - }; + if (this.dialog.content && + (!this.dialog.prereqs || + this.dialog.prereqs.every(prereq => prereq() === true))) { + container.onclick = () => { + if (Dialog.isOpen()) { + Dialog.close(); + } + if (this.dialog.name) { + Dialog.setup(this.dialog.name); + } + const frag = new DocumentFragment(); + frag.append(this.dialog.content); + $(Dialog.body()).empty().append(frag); + Dialog.open(); + }; + } } for (const row of this.rows) {