From b0e08833590f3b405dc6e721cccc0fc42ecc84ba Mon Sep 17 00:00:00 2001
From: DCoded <dicoded@email.com>
Date: Sun, 16 Jan 2022 00:02:20 -0500
Subject: [PATCH] Added dialogs to options group and facilities

---
 devTools/types/FC/facilities.d.ts |  7 +++++++
 src/004-base/facilityFramework.js |  4 ++++
 src/facilities/club/club.js       |  2 +-
 src/gui/options/optionsGroup.js   | 27 +++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/devTools/types/FC/facilities.d.ts b/devTools/types/FC/facilities.d.ts
index c33c4f173ec..74976994de2 100644
--- a/devTools/types/FC/facilities.d.ts
+++ b/devTools/types/FC/facilities.d.ts
@@ -64,6 +64,13 @@ declare namespace FC {
 				note?: string;
 				/** Any prerequisites that must be met for the option to be displayed. */
 				prereqs?: Array<() => boolean>
+				/** Any dialog to display upon setting the value. */
+				dialog?: {
+					/** The content displayed in the dialog. */
+					content: string|HTMLElement|DocumentFragment;
+					/** The name of the dialog to display. */
+					name: string;
+				};
 			}>
 			/** Any additional nodes to attach. */
 			nodes?: Array<string|HTMLElement|DocumentFragment>
diff --git a/src/004-base/facilityFramework.js b/src/004-base/facilityFramework.js
index f500d2c1400..b9c10720b13 100644
--- a/src/004-base/facilityFramework.js
+++ b/src/004-base/facilityFramework.js
@@ -229,6 +229,10 @@ App.Facilities.Facility = class Facility {
 							_.isEqual(V[rule.property], o.value)) {
 								App.UI.DOM.appendNewElement("div", div, o.text);
 							}
+
+							if (o.dialog) {
+								options.addDialog(o.dialog.content, o.dialog.name);
+							}
 						}
 					});
 
diff --git a/src/facilities/club/club.js b/src/facilities/club/club.js
index 1687f646ada..70e31a416e4 100644
--- a/src/facilities/club/club.js
+++ b/src/facilities/club/club.js
@@ -354,7 +354,7 @@ App.Facilities.Club.club = class Club extends App.Facilities.Facility {
 		App.UI.DOM.appendNewElement("div", div, App.UI.DOM.passageLink(`Manage club advertisements`, "Club Advertisement", () => {
 			V.nextLink = passage();
 			V.nextButton = "Back";
-		}));
+		}), ["indent"]);
 
 		return div;
 	}
diff --git a/src/gui/options/optionsGroup.js b/src/gui/options/optionsGroup.js
index c49892ec214..647169b5a86 100644
--- a/src/gui/options/optionsGroup.js
+++ b/src/gui/options/optionsGroup.js
@@ -487,6 +487,7 @@ App.UI.OptionsGroup = (function() {
 			this.rows = [];
 			this.doubleColumn = false;
 			this.refresh = App.UI.reload;
+			this.dialog = null;
 		}
 
 		/**
@@ -558,6 +559,19 @@ App.UI.OptionsGroup = (function() {
 			return this._addRow(new CustomRow(element));
 		}
 
+		/**
+		 * Opens the given element as a dialog upon selecting the option
+		 *
+		 * @param {HTMLElement|string|DocumentFragment} element
+		 * @param {string} name
+		 * @returns {this}
+		 */
+		addDialog(element, name) {
+			this.dialog = {element, name};
+
+			return this;
+		}
+
 		/**
 		 * @returns {HTMLDivElement}
 		 */
@@ -568,6 +582,19 @@ App.UI.OptionsGroup = (function() {
 				container.classList.add("double");
 			}
 
+			if (this.dialog) {
+				container.onclick = () => {
+					if (Dialog.isOpen()) {
+						Dialog.close();
+					}
+					Dialog.setup(this.dialog.name);
+					const frag = new DocumentFragment();
+					frag.append(this.dialog.element);
+					$(Dialog.body()).empty().append(frag);
+					Dialog.open();
+				}
+			}
+
 			for (const row of this.rows) {
 				row.render(container, this.refresh);
 			}
-- 
GitLab