mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
169 lines
5.2 KiB
Plaintext
169 lines
5.2 KiB
Plaintext
<%
|
||
const isBlankForm = !('prefilled' in locals);
|
||
prefilled = locals.prefilled || {};
|
||
%>
|
||
|
||
<fieldset>
|
||
<legend>Your WebID</legend>
|
||
<p>
|
||
A <em>WebID</em> is a unique identifier for you
|
||
in the form of a URL.
|
||
<br>
|
||
You WebID lets you log in to Solid apps
|
||
and access non-public data in Pods.
|
||
</p>
|
||
<ol>
|
||
<li class="radio">
|
||
<label>
|
||
<input type="radio" id="createWebIdOn" name="createWebId" value="on"<%
|
||
if (isBlankForm || prefilled.createWebId) { %> checked<% } %>>
|
||
Create a new WebID for my Pod.
|
||
</label>
|
||
<p id="createWebIdForm">
|
||
Please also create a Pod below, since your WebID will be stored there.
|
||
</p>
|
||
</li>
|
||
<li class="radio">
|
||
<label>
|
||
<input type="radio" id="createWebIdOff" name="createWebId" value=""<%
|
||
if (!isBlankForm && !prefilled.createWebId) { %> checked<% } %>>
|
||
Use my existing WebID to access my Pod.
|
||
</label>
|
||
<ol id="existingWebIdForm">
|
||
<li>
|
||
<label for="webId">Existing WebID:</label>
|
||
<input id="webId" type="text" name="webId" value="<%= prefilled.webId || '' %>">
|
||
</li>
|
||
<li class="checkbox">
|
||
<label>
|
||
<input type="checkbox" id="register" name="register"<%
|
||
if (isBlankForm || prefilled.register) { %> checked<% } %>>
|
||
Use my new account to log in with this WebID.
|
||
</label>
|
||
</li>
|
||
</ol>
|
||
</li>
|
||
</ol>
|
||
</fieldset>
|
||
|
||
<fieldset>
|
||
<legend>Your Pod</legend>
|
||
<p>
|
||
A Pod is a storage place for your data.
|
||
</p>
|
||
<ol>
|
||
<li class="checkbox">
|
||
<label>
|
||
<input type="checkbox" id="createPod" name="createPod"<%
|
||
if (isBlankForm || prefilled.createPod) { %> checked<% } %>>
|
||
Create a new Pod with my WebID as owner<% if (locals.allowRootPod) { %> in the root<% } %>.
|
||
</label>
|
||
<ol id="createPodForm">
|
||
<% if (locals.allowRootPod) { %>
|
||
<input type="hidden" id="rootPod" name="rootPod" value="true">
|
||
<% } else { %>
|
||
<li id="podNameForm">
|
||
<label for="podName">Pod name:</label>
|
||
<input id="podName" type="text" name="podName" value="<%= prefilled.podName || '' %>">
|
||
</li>
|
||
<% } %>
|
||
</ol>
|
||
</li>
|
||
</ol>
|
||
</fieldset>
|
||
|
||
<fieldset>
|
||
<legend>Your account</legend>
|
||
<div>
|
||
<p>
|
||
Choose the credentials you want to use to log in to this server in the future.
|
||
</p>
|
||
<ol>
|
||
<li>
|
||
<label for="email">Email:</label>
|
||
<input id="email" type="text" name="email" value="<%= prefilled.email || '' %>" >
|
||
</li>
|
||
</ol>
|
||
<ol id="passwordForm">
|
||
<li>
|
||
<label for="password">Password:</label>
|
||
<input id="password" type="password" name="password">
|
||
</li>
|
||
<li>
|
||
<label for="confirmPassword">Confirm password:</label>
|
||
<input id="confirmPassword" type="password" name="confirmPassword">
|
||
</li>
|
||
</ol>
|
||
</div>
|
||
</fieldset>
|
||
|
||
<!-- Assist the user with filling out the form by hiding irrelevant fields -->
|
||
<script>
|
||
const elements = {};
|
||
|
||
// Wires up the DOM element with the specified ID
|
||
function registerElement(id) {
|
||
const element = document.getElementById(id) || document.createElement('input');
|
||
elements[id] = element;
|
||
element.addEventListener('change', synchronizeInputFields);
|
||
}
|
||
|
||
// Wire up all elements
|
||
[
|
||
'mainForm',
|
||
'createWebIdOn', 'createWebIdOff', 'createWebIdForm', 'existingWebIdForm', 'webId',
|
||
'createPod', 'createPodForm', 'podNameForm', 'podName',
|
||
'register', 'passwordForm',
|
||
].forEach(registerElement);
|
||
|
||
// Conditions under which elements should be visible
|
||
const visibilityConditions = {
|
||
createWebIdForm: () => elements.createWebIdOn.checked,
|
||
existingWebIdForm: () => elements.createWebIdOff.checked,
|
||
createPodForm: () => elements.createPod.checked,
|
||
};
|
||
|
||
// Ensures that the only relevant input fields are visible and enabled
|
||
function synchronizeInputFields({ srcElement } = {}) {
|
||
// The user needs a Pod if they want to create a WebID
|
||
if (elements.createWebIdOn.checked)
|
||
elements.createPod.checked = true;
|
||
|
||
// Hide irrelevant fields
|
||
for (const [id, condition] of Object.entries(visibilityConditions))
|
||
setVisibility(id, condition());
|
||
|
||
// Lock pod creation if a WebID is requested
|
||
elements.createPod.disabled = elements.createWebIdOn.checked;
|
||
|
||
// If child elements have just been activated, focus on them
|
||
if (srcElement?.checked) {
|
||
switch(document.activeElement) {
|
||
case elements.createWebIdOff:
|
||
const { webId } = elements;
|
||
webId.value = webId.value.startsWith('http') ? webId.value : 'https://';
|
||
webId.focus();
|
||
break;
|
||
case elements.createPod:
|
||
elements.podName.focus();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// Prepare the form when the DOM is ready
|
||
addEventListener('DOMContentLoaded', (event) => {
|
||
synchronizeInputFields();
|
||
elements.mainForm.classList.add('loaded');
|
||
});
|
||
|
||
// Enable all elements on form submission (otherwise their value is not submitted)
|
||
elements.mainForm.addEventListener('submit', () => {
|
||
for (const child of getDescendants(elements.mainForm)) {
|
||
if (child.name)
|
||
child.disabled = false;
|
||
}
|
||
});
|
||
elements.mainForm.addEventListener('formdata', synchronizeInputFields);
|
||
</script>
|