Skip to content

Commit

Permalink
use hotkey to jump to add entry, enhance shortcut help
Browse files Browse the repository at this point in the history
the automated jump to "add entry text" textbox has bugged me for a
while, as it's weird behavior that's undesirable much of the time.
This instead changes that so the the user can tap "a" after opening
an incident to jump to that field.
  • Loading branch information
srabraham committed Feb 13, 2025
1 parent a86c99b commit 73dd264
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/ims/element/incident/incident_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
</div>
<div class="modal-body">
<code>n</code>: create new Incident <br/>
<code>h</code>: toggle showing system-generated history <br/>
<code>n</code>: create (n)ew Incident <br/>
<code>a</code>: jump to (a)dd new report text<br/>
<code>h</code>: toggle showing system-generated (h)istory <br/>
</div>
</div>
</div>
Expand Down Expand Up @@ -248,7 +249,7 @@
id="report_entry_add"
class="form-control no-print"
rows="3"
placeholder="Additional report text..."
placeholder="Press &quot;a&quot; to add report text"
autofocus=""
onchange="reportEntryEdited()"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/incident/incidents_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="modal-body">
<p class="mt-2 mb-0">Keyboard shortcuts</p>
<ul>
<li><code>n</code>: create new Incident <br/></li>
<li><code>n</code>: create (n)ew Incident <br/></li>
<li><code>/</code>: jump to search field <br/></li>
</ul>
<p class="mt-2 mb-0">In the search field</p>
Expand Down Expand Up @@ -150,7 +150,7 @@
id="search_input"
type="search"
class="form-control search-box"
placeholder="Search"
placeholder="Press &quot; ⁄ &quot; to search"
inputmode="latin"
autocomplete="off"
aria-controls="queue_table"
Expand Down
7 changes: 4 additions & 3 deletions src/ims/element/incident/report_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
</div>
<div class="modal-body">
<code>n</code>: create new Field Report <br/>
<code>h</code>: toggle showing system-generated history <br/>
<code>n</code>: create (n)ew Field Report <br/>
<code>a</code>: jump to (a)dd new report text<br/>
<code>h</code>: toggle showing system-generated (h)istory <br/>
</div>
</div>
</div>
Expand Down Expand Up @@ -144,7 +145,7 @@
id="report_entry_add"
class="form-control no-print input-sm"
rows="12"
placeholder="Additional report text..."
placeholder="Press &quot;a&quot; to add report text"
autofocus=""
onchange="reportEntryEdited()"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/incident/reports_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="modal-body">
<p class="mt-2 mb-0">Keyboard shortcuts</p>
<ul>
<li><code>n</code>: create new Field Report <br/></li>
<li><code>n</code>: create (n)ew Field Report <br/></li>
<li><code>/</code>: jump to search field <br/><br/></li>
</ul>
<p class="mt-2 mb-0">In the search field</p>
Expand Down Expand Up @@ -110,7 +110,7 @@
id="search_input"
type="search"
class="form-control search-box"
placeholder="Search"
placeholder="Press &quot; ⁄ &quot; to search"
inputmode="latin"
autocomplete="off"
aria-controls="field_reports_table"
Expand Down
3 changes: 2 additions & 1 deletion src/ims/element/page/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def add(name: str) -> None:

if name == "dataTables":
add("dataTablesBootstrap")
add("dataTablesResponsive")
# Responsive is currently unused. See incidents.js as well.
# add("dataTablesResponsive")

# All pages use Bootstrap
add("bootstrap")
Expand Down
7 changes: 7 additions & 0 deletions src/ims/element/static/field_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ function initFieldReportPage() {
if (e.key === "?") {
$("#helpModal").modal("toggle");
}
// a --> jump to add a new report entry
if (e.key === "a") {
e.preventDefault();
// Scroll to report_entry_add field
$("html, body").animate({scrollTop: $("#report_entry_add").offset().top}, 500);
$("#report_entry_add").focus();
}
// h --> toggle showing system entries
if (e.key.toLowerCase() === "h") {
document.getElementById("history_checkbox").click();
Expand Down
13 changes: 8 additions & 5 deletions src/ims/element/static/incident.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ function initIncidentPage() {
loadIncidentTypes(drawIncidentTypesToAdd);
loadAllFieldReports(renderFieldReportData);

// for a new incident
// for a new incident, jump to summary field
if (incident.number == null) {
$("#incident_summary").focus();
} else {
// Scroll to report_entry_add field
$("html, body").animate({scrollTop: $("#report_entry_add").offset().top}, 500);
$("#report_entry_add").focus();
}

// Warn the user if they're about to navigate away with unsaved text.
Expand Down Expand Up @@ -96,6 +92,13 @@ function initIncidentPage() {
if (e.key === "?") {
$("#helpModal").modal("toggle");
}
// a --> jump to add a new report entry
if (e.key === "a") {
e.preventDefault();
// Scroll to report_entry_add field
$("html, body").animate({scrollTop: $("#report_entry_add").offset().top}, 500);
$("#report_entry_add").focus();
}
// h --> toggle showing system entries
if (e.key.toLowerCase() === "h") {
document.getElementById("history_checkbox").click();
Expand Down

0 comments on commit 73dd264

Please sign in to comment.