Add time copy button, improve session editing

This commit is contained in:
Lukáš Kucharczyk 2023-09-18 20:21:05 +02:00
parent 8ba5344a4d
commit 077d8d1e3c
4 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,8 @@
* Add helper buttons next to datime fields * Add helper buttons next to datime fields
* Change recent session view to current year instead of last 30 days * Change recent session view to current year instead of last 30 days
* Fix bug when filtering only manual sessions (https://git.kucharczyk.xyz/lukas/timetracker/issues/51) * Fix bug when filtering only manual sessions (https://git.kucharczyk.xyz/lukas/timetracker/issues/51)
* Add copy button on Add session page to copy times between fields
* Use the same form when editing a session as when adding a session
## 1.0.3 / 2023-02-20 17:16+01:00 ## 1.0.3 / 2023-02-20 17:16+01:00

View File

@ -8,6 +8,9 @@ for (let button of document.querySelectorAll("[data-target]")) {
event.preventDefault(); event.preventDefault();
if (type == "now") { if (type == "now") {
targetElement.value = toISOUTCString(new Date); targetElement.value = toISOUTCString(new Date);
} else if (type == "copy") {
const oppositeName = targetElement.name == "timestamp_start" ? "timestamp_end" : "timestamp_start";
document.querySelector(`[name='${oppositeName}']`).value = targetElement.value;
} else if (type == "toggle") { } else if (type == "toggle") {
if (targetElement.type == "datetime-local") targetElement.type = "text"; if (targetElement.type == "datetime-local") targetElement.type = "text";
else targetElement.type = "datetime-local"; else targetElement.type = "datetime-local";

View File

@ -20,6 +20,7 @@
<div class="basic-button-container"> <div class="basic-button-container">
<button class="basic-button" data-target="{{field.name}}" data-type="now">Set to now</button> <button class="basic-button" data-target="{{field.name}}" data-type="now">Set to now</button>
<button class="basic-button" data-target="{{field.name}}" data-type="toggle">Toggle text</button> <button class="basic-button" data-target="{{field.name}}" data-type="toggle">Toggle text</button>
<button class="basic-button" data-target="{{field.name}}" data-type="copy">Copy</button>
</div> </div>
</td> </td>
{% endif %} {% endif %}

View File

@ -64,7 +64,7 @@ def edit_session(request, session_id=None):
return redirect("list_sessions") return redirect("list_sessions")
context["title"] = "Edit Session" context["title"] = "Edit Session"
context["form"] = form context["form"] = form
return render(request, "add.html", context) return render(request, "add_session.html", context)
def edit_purchase(request, purchase_id=None): def edit_purchase(request, purchase_id=None):