From 103306f00ca54538ab7ed77aa7990c69ef2e0c63 Mon Sep 17 00:00:00 2001
From: "Panagiotis \"Ivory\" Vasilopoulos" <git@n0toose.net>
Date: Mon, 29 Apr 2024 19:48:21 +0200
Subject: [PATCH] UI: Disable internal wiki options when enabling external wiki

Using "data-target", it is possible to set a value to a target element
that can enable it or disable it. Using "data-context" lets us perform
the opposite action on a different target.

Before, only the #external_wiki_box target was used, which was enabled
or disabled depending on whether the user has chosen to use the internal
wiki or the external wiki. If the user chooses to use the internal wiki,
they will disable the box that lets them enter a link pointing to an
external wiki, and vice versa. Although it is not possible to use, say,
boolean operations, we can introduce a target that is
called #globally_writeable_checkbox that gets enabled when
the #external_wiki_box box is disabled, and vice versa.

This makes the box's behavior more consistent with the behavior in the
"Issues" section. To keep things consistent with that section, a new
property was assigned to the "globally_writeable_checkbox" that makes
the box go a bit further in (`tw-pl-4`).
---
 templates/repo/settings/units/wiki.tmpl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/templates/repo/settings/units/wiki.tmpl b/templates/repo/settings/units/wiki.tmpl
index dc83483b04..23df294bd3 100644
--- a/templates/repo/settings/units/wiki.tmpl
+++ b/templates/repo/settings/units/wiki.tmpl
@@ -16,13 +16,13 @@
 	<div class="field{{if not $isWikiEnabled}} disabled{{end}}" id="wiki_box">
 		<div class="field">
 			<div class="ui radio checkbox{{if $isWikiGlobalDisabled}} disabled{{end}}"{{if $isWikiGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
-				<input class="enable-system-radio" name="enable_external_wiki" type="radio" value="false" data-target="#external_wiki_box" {{if not (.Repository.UnitEnabled $.Context $.UnitTypeExternalWiki)}}checked{{end}}>
+				<input class="enable-system-radio" name="enable_external_wiki" type="radio" value="false" data-context="#globally_writeable_checkbox" data-target="#external_wiki_box" {{if not (.Repository.UnitEnabled $.Context $.UnitTypeExternalWiki)}}checked{{end}}>
 				<label>{{ctx.Locale.Tr "repo.settings.use_internal_wiki"}}</label>
 			</div>
 		</div>
 		{{if (not .Repository.IsPrivate)}}
-			<div class="field {{if (.Repository.UnitEnabled $.Context $.UnitTypeExternalWiki)}}disabled{{end}}">
-				<div class="field">
+			<div class="field {{if (.Repository.UnitEnabled $.Context $.UnitTypeExternalWiki)}}disabled{{end}}" id="globally_writeable_checkbox">
+				<div class="field tw-pl-4">
 					<div class="ui checkbox">
 						<input name="globally_writeable_wiki" type="checkbox" {{if .Permission.IsGloballyWriteable $.UnitTypeWiki}}checked{{end}}>
 						<label>{{ctx.Locale.Tr "repo.settings.wiki_globally_editable"}}</label>
@@ -32,7 +32,7 @@
 		{{end}}
 		<div class="field">
 			<div class="ui radio checkbox{{if $isExternalWikiGlobalDisabled}} disabled{{end}}"{{if $isExternalWikiGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
-				<input class="enable-system-radio" name="enable_external_wiki" type="radio" value="true" data-target="#external_wiki_box" {{if .Repository.UnitEnabled $.Context $.UnitTypeExternalWiki}}checked{{end}}>
+				<input class="enable-system-radio" name="enable_external_wiki" type="radio" value="true" data-context="#globally_writeable_checkbox" data-target="#external_wiki_box" {{if .Repository.UnitEnabled $.Context $.UnitTypeExternalWiki}}checked{{end}}>
 				<label>{{ctx.Locale.Tr "repo.settings.use_external_wiki"}}</label>
 			</div>
 		</div>