mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
Ticket timer (forum #3237): with Start the timer on opening a ticket on, a reply or note stops the timer instead of a new one starting by itself as the ticket comes back, it stays stopped on reloads and other changes on the ticket until play is pressed or the ticket is opened again from elsewhere, saying Stopped with your reply, choosing On Hold, Resolved or Closed for after the reply pauses it by status id, and a ticket opened with autostart off no longer keeps an empty time that stopped autostart later; 26.12.3 changelog
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* A ticket's timer, on its page (agent/ticket.php), kept in this browser's localStorage so it
|
||||
* runs on while you're elsewhere (the top bar's timers, js/ticket_timers.js, read the same keys).
|
||||
* With Start the timer on opening a ticket on, it starts by itself when you open the ticket.
|
||||
* Sending a reply or note puts the time on it and stops the timer: the page comes back with it
|
||||
* stopped, and stays so - reloading, or anything else done on the ticket - until you press play or
|
||||
* come to the ticket again from elsewhere, which starts a new one. Choosing On Hold, Resolved or
|
||||
* Closed for after the reply pauses it.
|
||||
*/
|
||||
(function() {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var timerInterval = null;
|
||||
@@ -59,7 +68,47 @@
|
||||
displayTime();
|
||||
}
|
||||
|
||||
// Sent a reply or note here - the timer stays stopped while the page comes back from this ticket
|
||||
function repliedKey() {
|
||||
return "ticket-timer-replied-" + ticketID;
|
||||
}
|
||||
|
||||
function forgetReplied() {
|
||||
try {
|
||||
sessionStorage.removeItem(repliedKey());
|
||||
} catch (e) {}
|
||||
let hint = document.querySelector("[data-timer-replied]");
|
||||
if (hint) hint.hidden = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Whether this page is the ticket coming back after your reply - from its own form, a reload,
|
||||
* or another change made on it. Arriving from anywhere else forgets the reply, so the timer
|
||||
* starts again as it does on opening a ticket.
|
||||
*/
|
||||
function cameBackAfterReply() {
|
||||
let at = 0;
|
||||
try {
|
||||
at = parseInt(sessionStorage.getItem(repliedKey()) || "0", 10);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
if (!at) {
|
||||
return false;
|
||||
}
|
||||
let fromHere = false;
|
||||
try {
|
||||
let from = new URL(document.referrer);
|
||||
fromHere = from.origin === window.location.origin && from.pathname === window.location.pathname && from.searchParams.get("ticket_id") === String(ticketID);
|
||||
} catch (e) {}
|
||||
if (!fromHere) {
|
||||
forgetReplied();
|
||||
}
|
||||
return fromHere;
|
||||
}
|
||||
|
||||
function startTimer() {
|
||||
forgetReplied();
|
||||
if (!localStorage.getItem(getLocalStorageKey("startTime"))) {
|
||||
localStorage.setItem(getLocalStorageKey("startTime"), Date.now().toString());
|
||||
}
|
||||
@@ -116,6 +165,8 @@
|
||||
|
||||
function handleInputFocus() {
|
||||
pauseTimer();
|
||||
let hint = document.querySelector("[data-timer-replied]");
|
||||
if (hint) hint.hidden = true;
|
||||
}
|
||||
|
||||
function updateTimeFromInput() {
|
||||
@@ -133,11 +184,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// On Hold, Resolved or Closed chosen for after the reply - the work is done, so it stops counting.
|
||||
// The select's values are status ids; data-timer-pause lists those that pause it.
|
||||
function checkStatusAndPauseTimer() {
|
||||
var statusEl = document.querySelector('select[name="status"]');
|
||||
if (statusEl) {
|
||||
var status = statusEl.value;
|
||||
if (status.includes("Pending") || status.includes("Close")) {
|
||||
if (statusEl && timerInterval) {
|
||||
var pausing = (statusEl.getAttribute("data-timer-pause") || "").split(",");
|
||||
if (pausing.indexOf(String(statusEl.value)) !== -1) {
|
||||
pauseTimer();
|
||||
}
|
||||
}
|
||||
@@ -201,6 +254,10 @@
|
||||
setTimeout(function() {
|
||||
if (!e.defaultPrevented) {
|
||||
forceResetTimer();
|
||||
// ... and it stays stopped when the page comes back, rather than starting again
|
||||
try {
|
||||
sessionStorage.setItem(repliedKey(), Date.now().toString());
|
||||
} catch (err) {}
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
@@ -217,18 +274,21 @@
|
||||
try {
|
||||
displayTime();
|
||||
|
||||
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
|
||||
if (typeof ticketAutoStart !== "undefined" && ticketAutoStart === 1) {
|
||||
// No time on it - a pausedTime of 0 left by an older version counts as none
|
||||
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !(parseInt(localStorage.getItem(getLocalStorageKey("pausedTime")) || "0", 10) > 0)) {
|
||||
let autoStart = typeof ticketAutoStart !== "undefined" && ticketAutoStart === 1;
|
||||
if (autoStart && cameBackAfterReply()) {
|
||||
// Stopped with the reply just sent - press play to time more
|
||||
let hint = document.querySelector("[data-timer-replied]");
|
||||
if (hint) hint.hidden = false;
|
||||
} else if (autoStart) {
|
||||
startTimer();
|
||||
} else {
|
||||
pauseTimer();
|
||||
}
|
||||
localStorage.removeItem(getLocalStorageKey("pausedTime"));
|
||||
} else if (localStorage.getItem(getLocalStorageKey("startTime"))) {
|
||||
startTimer();
|
||||
}
|
||||
|
||||
checkStatusAndPauseTimer();
|
||||
|
||||
} catch (error) {
|
||||
console.error("There was an issue initializing the timer:", error);
|
||||
}
|
||||
|
||||
@@ -1008,6 +1008,8 @@ if (isset($_GET['ticket_id'])) {
|
||||
<button type="button" class="btn btn-light border" id="startStopTimer" title="Start / pause the timer"><i class="fas fa-play"></i></button>
|
||||
<button type="button" class="btn btn-light border" id="resetTimer" title="Reset the timer"><i class="fas fa-redo-alt"></i></button>
|
||||
</div>
|
||||
<!-- Sending a reply stops the timer - said when the page comes back (agent/js/ticket_time_tracking.js) -->
|
||||
<div class="form-text mt-1" data-timer-replied title="Press play to time more" hidden><i class="fas fa-fw fa-stopwatch me-1"></i>Stopped with your reply</div>
|
||||
<!-- Add a block of time in one click - the timer stops at the new total (agent/js/ticket_reply_extras.js) -->
|
||||
<div class="d-flex flex-wrap gap-1 mt-1" data-time-add>
|
||||
<?php foreach ([15 => '+15m', 30 => '+30m', 60 => '+1h'] as $minutes => $label) { ?>
|
||||
@@ -1036,7 +1038,7 @@ if (isset($_GET['ticket_id'])) {
|
||||
<div class="row g-2 align-items-end">
|
||||
<div class="col-md-5">
|
||||
<label class="form-label small text-secondary mb-1" for="ticket_reply_status">Status after this</label>
|
||||
<select class="form-select select2" name="status" id="ticket_reply_status" required>
|
||||
<select class="form-select select2" name="status" id="ticket_reply_status" required data-timer-pause="<?= implode(',', [TICKET_STATUS_ON_HOLD, TICKET_STATUS_RESOLVED, TICKET_STATUS_CLOSED]) ?>">
|
||||
<!-- Resolved stays on offer here (reply and resolve in one go) unless open tasks block it -->
|
||||
<?php foreach ($ticket_status_options as $status_option) {
|
||||
$ticket_status_id_select = intval($status_option['ticket_status_id']);
|
||||
|
||||
Reference in New Issue
Block a user