Keep hosting plan help next to its fields
This commit is contained in:
1 parent
1199810257
commit
7e51716122
5 files changed
+145
-23
No files matched your search
@@ -0,0 +1,50 @@
|
|||||||
|
let activeHelp;
|
||||||
|
let pinned = false;
|
||||||
|
|
||||||
|
function closeHelp() {
|
||||||
|
if (activeHelp) activeHelp.open = false;
|
||||||
|
activeHelp = undefined;
|
||||||
|
pinned = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showHelp(help) {
|
||||||
|
if (activeHelp === help) return;
|
||||||
|
closeHelp();
|
||||||
|
help.open = true;
|
||||||
|
activeHelp = help;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const help of document.querySelectorAll("[data-field-help]")) {
|
||||||
|
const summary = help.querySelector("summary");
|
||||||
|
help.addEventListener("pointerenter", (event) => {
|
||||||
|
if (event.pointerType === "mouse" && !pinned) showHelp(help);
|
||||||
|
});
|
||||||
|
help.addEventListener("pointerleave", () => {
|
||||||
|
if (activeHelp === help && !pinned && !summary.matches(":focus-visible")) {
|
||||||
|
closeHelp();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
summary.addEventListener("focus", () => {
|
||||||
|
if (summary.matches(":focus-visible")) showHelp(help);
|
||||||
|
});
|
||||||
|
summary.addEventListener("blur", () => {
|
||||||
|
if (activeHelp === help) closeHelp();
|
||||||
|
});
|
||||||
|
summary.addEventListener("click", (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (activeHelp === help && pinned) {
|
||||||
|
closeHelp();
|
||||||
|
} else {
|
||||||
|
showHelp(help);
|
||||||
|
pinned = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("pointerdown", (event) => {
|
||||||
|
if (activeHelp && !activeHelp.contains(event.target)) closeHelp();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (event) => {
|
||||||
|
if (event.key === "Escape" && activeHelp) closeHelp();
|
||||||
|
});
|
||||||
@@ -728,14 +728,54 @@ dd {
|
|||||||
accent-color: var(--accent);
|
accent-color: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-help {
|
.plan-field-heading {
|
||||||
padding: 0.65rem 0.75rem;
|
position: relative;
|
||||||
border: 1px solid var(--line);
|
display: flex;
|
||||||
border-radius: var(--radius);
|
align-items: center;
|
||||||
|
gap: 0.35rem;
|
||||||
|
margin-bottom: 0.35rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-help dt {
|
.plan-field-heading label {
|
||||||
margin-block-start: 0.55rem;
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-help summary {
|
||||||
|
display: grid;
|
||||||
|
width: 1.5rem;
|
||||||
|
height: 1.5rem;
|
||||||
|
place-items: center;
|
||||||
|
border: 1px solid var(--control-line);
|
||||||
|
border-radius: 50%;
|
||||||
|
color: var(--accent);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: 700;
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-help summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-help summary:hover, .field-help[open] summary {
|
||||||
|
background: var(--control-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-help p {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
inset-block-start: 100%;
|
||||||
|
inset-inline-start: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: min(100%, 25rem);
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.6rem 0.75rem;
|
||||||
|
border: 1px solid var(--control-line);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
background: var(--surface);
|
||||||
|
box-shadow: 0 4px 12px var(--surface-shadow);
|
||||||
|
font-size: 0.88rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.reseller-editor fieldset {
|
.reseller-editor fieldset {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% extends "hosting/base.html" %}
|
{% extends "hosting/base.html" %}
|
||||||
|
{% load static %}
|
||||||
{% block title %}{{ page_title }} · Coulobre Panel{% endblock %}
|
{% block title %}{{ page_title }} · Coulobre Panel{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<a class="back-link" href="{% url 'panel:hosting_plans' %}">← Hosting plans</a>
|
<a class="back-link" href="{% url 'panel:hosting_plans' %}">← Hosting plans</a>
|
||||||
@@ -6,26 +7,28 @@
|
|||||||
<section class="surface editor-surface">
|
<section class="surface editor-surface">
|
||||||
<form method="post" class="editor">
|
<form method="post" class="editor">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_div }}
|
{{ form.non_field_errors }}
|
||||||
<details class="field-help">
|
{% for field in form.visible_fields %}
|
||||||
<summary>Examples and explanations</summary>
|
<div class="plan-field">
|
||||||
<dl>
|
<div class="plan-field-heading">
|
||||||
<dt>Scheduled tasks per hosting account</dt>
|
{{ field.label_tag }}
|
||||||
<dd>For example, allow up to 10 scripts that run on a schedule, such as a CMS task that runs every 15 minutes.</dd>
|
{% if field.help_text %}
|
||||||
<dt>Website, database and mailbox limits</dt>
|
<details class="field-help" data-field-help>
|
||||||
<dd>The primary site counts toward the website limit. A blank database or mailbox limit allows any number. Zero blocks new requests.</dd>
|
<summary aria-label="Help for {{ field.label }}">?</summary>
|
||||||
<dt>Mailbox and website storage</dt>
|
<p id="{{ field.auto_id }}_helptext">{{ field.help_text }}</p>
|
||||||
<dd>Storage is measured in MiB. Enter 1024 for 1 GiB. The mailbox limit applies to new mailbox requests. The website limit is the default when applying a site quota.</dd>
|
</details>
|
||||||
<dt>Catch-all email</dt>
|
{% endif %}
|
||||||
<dd>Send messages for unknown addresses at a mail domain to a designated mailbox.</dd>
|
</div>
|
||||||
<dt>External mail forwarding</dt>
|
{{ field.errors }}
|
||||||
<dd>Let an alias send a copy of incoming mail to another domain.</dd>
|
{{ field }}
|
||||||
</dl>
|
</div>
|
||||||
</details>
|
{% endfor %}
|
||||||
|
{% for field in form.hidden_fields %}{{ field }}{% endfor %}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="button primary" type="submit">{{ submit_label }}</button>
|
<button class="button primary" type="submit">{{ submit_label }}</button>
|
||||||
<a class="button secondary" href="{% url 'panel:hosting_plans' %}">Cancel</a>
|
<a class="button secondary" href="{% url 'panel:hosting_plans' %}">Cancel</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
<script src="{% static 'hosting/field-help.js' %}" defer></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -25,6 +25,19 @@ class HostingPlanTests(TestCase):
|
|||||||
name="Example hosting", primary_domain="example.org"
|
name="Example hosting", primary_domain="example.org"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_scheduled_task_help_is_associated_with_the_field(self):
|
||||||
|
self.client.force_login(self.operator)
|
||||||
|
response = self.client.get(reverse("panel:hosting_plan_create"))
|
||||||
|
self.assertContains(
|
||||||
|
response, 'aria-describedby="id_website_job_limit_helptext"'
|
||||||
|
)
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
'aria-label="Help for Scheduled tasks per hosting account"',
|
||||||
|
)
|
||||||
|
self.assertContains(response, "including paused tasks")
|
||||||
|
self.assertNotContains(response, "Examples and explanations")
|
||||||
|
|
||||||
def test_operator_can_create_assign_and_edit_a_plan(self):
|
def test_operator_can_create_assign_and_edit_a_plan(self):
|
||||||
self.client.force_login(self.operator)
|
self.client.force_login(self.operator)
|
||||||
list_url = reverse("panel:hosting_plans")
|
list_url = reverse("panel:hosting_plans")
|
||||||
|
|||||||
@@ -2233,8 +2233,24 @@ class HostingPlanEditor:
|
|||||||
jobs.label = "Scheduled tasks per hosting account"
|
jobs.label = "Scheduled tasks per hosting account"
|
||||||
jobs.help_text = (
|
jobs.help_text = (
|
||||||
"Counts saved tasks across all websites, including paused tasks. "
|
"Counts saved tasks across all websites, including paused tasks. "
|
||||||
"Enter 0 to disable scheduling."
|
"Enter 0 to disable scheduling. With a limit of 10, a CMS "
|
||||||
|
"task that runs every 15 minutes uses one of the 10 slots."
|
||||||
)
|
)
|
||||||
|
for field in ("mailbox_quota_mib", "website_storage_limit_mib"):
|
||||||
|
form.fields[field].help_text += " Enter 1024 for 1 GiB."
|
||||||
|
php_help = {
|
||||||
|
"php_memory_limit_mib": "Memory a PHP script can use.",
|
||||||
|
"php_upload_limit_mib": "Maximum size of an uploaded file.",
|
||||||
|
"php_request_timeout_seconds": (
|
||||||
|
"How long PHP-FPM lets a request run before stopping it."
|
||||||
|
),
|
||||||
|
"php_max_children": (
|
||||||
|
"How many PHP requests a website can process at once."
|
||||||
|
),
|
||||||
|
}
|
||||||
|
for name, description in php_help.items():
|
||||||
|
field = form.fields[name]
|
||||||
|
field.help_text = f"{description} {field.help_text}"
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user