Skip to content

Commit 58d3da6

Browse files
committed
Add a severity level tooltip
1 parent 05cf629 commit 58d3da6

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

api/admin.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,18 @@ def get_form(self, request, obj=None, change=False, **kwargs):
310310
return form
311311

312312
url, title = self._crisis_categorisation_link_data(obj)
313-
field.label = mark_safe(f'<a href="{url}" title="{title}">IFRC Severity level</a>')
313+
field.label = mark_safe(
314+
f'<a href="{url}" title="{title}">IFRC Severity level</a>'
315+
' <span class="help-icon cc-help-icon ifrc-severity-help-icon" '
316+
'title="Click for more information" '
317+
'aria-label="IFRC Severity level help">ⓘ</span>'
318+
' <div class="help-tooltip cc-help-tooltip ifrc-severity-help-tooltip" role="tooltip">'
319+
"Link to the crisis categorisation page belonging to this event.<br>"
320+
"If this is a multi-country event, you may want to select the country yourself from the "
321+
'<a target="_blank" href="/admin/api/crisiscategorisationbycountry/">list</a> or'
322+
' add a new record <a target="_blank" href="/admin/api/crisiscategorisationbycountry/add/">here</a>.<br>'
323+
"</div>"
324+
)
314325
return form
315326

316327
severity_level_link.short_description = "Crisis Categorisation"
@@ -494,6 +505,9 @@ def changelist_view(self, request, extra_context=None):
494505

495506
return response
496507

508+
class Media:
509+
js = ("js/event_severity_help.js",)
510+
497511

498512
class GdacsAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdmin):
499513
country_in = "countries__pk__in"

go-static/css/after.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ p.deletelink-box {
233233
top: -0.3rem;
234234
}
235235

236+
.ifrc-severity-help-icon {
237+
background: transparent;
238+
color: #0b6aa2;
239+
}
240+
236241
/* Tooltip bubble */
237242
.precrisis-help-tooltip,
238243
.cc-help-tooltip {
@@ -254,6 +259,12 @@ p.deletelink-box {
254259
margin-top: 0;
255260
}
256261

262+
.ifrc-severity-help-tooltip {
263+
top: calc(100% + 2px);
264+
bottom: auto;
265+
font-weight: normal;
266+
}
267+
257268
.precrisis-help-tooltip img,
258269
.cc-help-tooltip img {
259270
display: block;
@@ -274,6 +285,13 @@ p.deletelink-box {
274285
border-top: 5px solid #ccc;
275286
}
276287

288+
.ifrc-severity-help-tooltip::before {
289+
top: -5px;
290+
bottom: auto;
291+
border-top: none;
292+
border-bottom: 5px solid #ccc;
293+
}
294+
277295
.precrisis-help-tooltip.visible,
278296
.cc-help-tooltip.visible {
279297
display: block;
@@ -292,4 +310,13 @@ p.deletelink-box {
292310
.cc-help-tooltip::before {
293311
border-top-color: #1a1a1a;
294312
}
313+
314+
.ifrc-severity-help-icon {
315+
background: transparent;
316+
color: #4ea3d8;
317+
}
318+
319+
.ifrc-severity-help-tooltip::before {
320+
border-bottom-color: #1a1a1a;
321+
}
295322
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(function() {
2+
function initSeverityHelpTooltip() {
3+
const label = document.querySelector('label[for="id_ifrc_severity_level"]');
4+
if (!label) {
5+
return;
6+
}
7+
8+
const helpIcon = label.querySelector('.ifrc-severity-help-icon');
9+
const tooltip = label.querySelector('.ifrc-severity-help-tooltip');
10+
if (!helpIcon || !tooltip) {
11+
return;
12+
}
13+
14+
label.style.position = 'relative';
15+
16+
helpIcon.addEventListener('click', function(e) {
17+
e.preventDefault();
18+
e.stopPropagation();
19+
20+
const shouldShow = !tooltip.classList.contains('visible');
21+
document.querySelectorAll('.cc-help-tooltip.visible').forEach(function(openTooltip) {
22+
openTooltip.classList.remove('visible');
23+
});
24+
tooltip.classList.toggle('visible', shouldShow);
25+
});
26+
27+
document.addEventListener('click', function(e) {
28+
if (!label.contains(e.target)) {
29+
tooltip.classList.remove('visible');
30+
}
31+
});
32+
}
33+
34+
if (document.readyState === 'loading') {
35+
document.addEventListener('DOMContentLoaded', initSeverityHelpTooltip);
36+
} else {
37+
initSeverityHelpTooltip();
38+
}
39+
})();

0 commit comments

Comments
 (0)