Add ticket timer functionality and clear all
timers button
This commit is contained in:
+44
-2
@@ -20,6 +20,26 @@
|
|||||||
if (countDisplay) {
|
if (countDisplay) {
|
||||||
countDisplay.innerText = count;
|
countDisplay.innerText = count;
|
||||||
}
|
}
|
||||||
|
if (count == 0) {
|
||||||
|
countDisplay.classList.remove('badge-danger');
|
||||||
|
} else {
|
||||||
|
//check to see if more than one ticket
|
||||||
|
if (count > 1) {
|
||||||
|
countDisplay.classList.add('badge-danger');
|
||||||
|
}
|
||||||
|
//if count is one, check to see if its open in the current window by looking at the post variable ticket_id in url
|
||||||
|
if (count == 1) {
|
||||||
|
let urlParams = new URLSearchParams(window.location.search);
|
||||||
|
let ticketID = urlParams.get('ticket_id');
|
||||||
|
console.log(ticketID);
|
||||||
|
// If ticket number equals one in local storage, then add badge-danger class
|
||||||
|
if (localStorage.getItem("ticket-timer-running-") == ticketID) {
|
||||||
|
countDisplay.classList.add('badge-danger');
|
||||||
|
} else {
|
||||||
|
countDisplay.classList.remove('badge-danger');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getElapsedSeconds(ticketID) {
|
function getElapsedSeconds(ticketID) {
|
||||||
@@ -74,8 +94,6 @@
|
|||||||
requestAnimationFrame(() => updateRunningTickets());
|
requestAnimationFrame(() => updateRunningTickets());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function updateRunningTickets() {
|
function updateRunningTickets() {
|
||||||
var runningTickets = document.querySelectorAll('[id^="ticket-"]');
|
var runningTickets = document.querySelectorAll('[id^="ticket-"]');
|
||||||
runningTickets.forEach(ticket => {
|
runningTickets.forEach(ticket => {
|
||||||
@@ -91,9 +109,30 @@
|
|||||||
requestAnimationFrame(updateRunningTickets);
|
requestAnimationFrame(updateRunningTickets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearAllTimers() {
|
||||||
|
// Collect keys to be removed
|
||||||
|
let keysToRemove = [];
|
||||||
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
|
let key = localStorage.key(i);
|
||||||
|
if (key.startsWith("ticket-timer-running-") || key.endsWith("-startTime") || key.endsWith("-pausedTime")) {
|
||||||
|
keysToRemove.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove collected keys
|
||||||
|
keysToRemove.forEach(key => localStorage.removeItem(key));
|
||||||
|
|
||||||
|
// Update the display and redirect
|
||||||
|
updateTicketCountDisplay();
|
||||||
|
window.location.href = "/tickets.php";
|
||||||
|
}
|
||||||
|
|
||||||
// Initial update on script load
|
// Initial update on script load
|
||||||
updateTicketCountDisplay();
|
updateTicketCountDisplay();
|
||||||
|
|
||||||
|
// update every 10 seconds
|
||||||
|
setInterval(updateTicketCountDisplay, 10000);
|
||||||
|
|
||||||
// Add event listener to modal
|
// Add event listener to modal
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var modal = document.getElementById('openTicketsModal');
|
var modal = document.getElementById('openTicketsModal');
|
||||||
@@ -102,4 +141,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add event listener to clear all timers button
|
||||||
|
document.getElementById('clearAllTimers').addEventListener('click', clearAllTimers);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
function clearTimeStorage() {
|
function clearTimeStorage() {
|
||||||
localStorage.removeItem(getLocalStorageKey("startTime"));
|
localStorage.removeItem(getLocalStorageKey("startTime"));
|
||||||
localStorage.removeItem(getLocalStorageKey("pausedTime"));
|
localStorage.removeItem(getLocalStorageKey("pausedTime"));
|
||||||
|
localStorage.removeItem("ticket-timer-running-" + ticketID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTimer() {
|
function resetTimer() {
|
||||||
@@ -177,6 +178,11 @@
|
|||||||
setTimeout(forceResetTimer, 100); // 100ms delay should suffice, but you can adjust as needed.
|
setTimeout(forceResetTimer, 100); // 100ms delay should suffice, but you can adjust as needed.
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("ticket_close").addEventListener('click', function() {
|
||||||
|
// Wait for other synchronous actions (if any) to complete before resetting the timer.
|
||||||
|
setTimeout(clearTimeStorage, 100); // 100ms delay should suffice, but you can adjust as needed.
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
displayTime();
|
displayTime();
|
||||||
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
|
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
|
||||||
|
|||||||
+1
-1
@@ -823,7 +823,7 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
<?php }
|
<?php }
|
||||||
|
|
||||||
if ($ticket_status !== "Closed") { ?>
|
if ($ticket_status !== "Closed") { ?>
|
||||||
<a href="post.php?close_ticket=<?php echo $ticket_id; ?>" class="btn btn-secondary btn-block confirm-link">
|
<a href="post.php?close_ticket=<?php echo $ticket_id; ?>" class="btn btn-secondary btn-block confirm-link" id="ticket_close">
|
||||||
<i class="fas fa-fw fa-gavel mr-2"></i>Close Ticket
|
<i class="fas fa-fw fa-gavel mr-2"></i>Close Ticket
|
||||||
</a>
|
</a>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|||||||
+11
-8
@@ -36,13 +36,14 @@
|
|||||||
<i class="fas fa-fw fa-question"></i>
|
<i class="fas fa-fw fa-question"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<?php if ($config_module_enable_ticketing == 1) { ?>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="#" data-toggle="modal" data-target="#openTicketsModal">
|
<a class="nav-link" href="#" data-toggle="modal" data-target="#openTicketsModal">
|
||||||
<i class="fas fa-hourglass-half"></i>
|
<i class="fas fa-hourglass-half"></i>
|
||||||
<span class="badge badge-danger" id="runningTicketsCount">0</span>
|
<span class="badge" id="runningTicketsCount">0</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
|
||||||
<!-- New Notifications Dropdown -->
|
<!-- New Notifications Dropdown -->
|
||||||
@@ -160,5 +161,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<?php include_once "top_nav_tickets_modal.php"; ?>
|
<?php if ($config_module_enable_ticketing == 1) {
|
||||||
|
include_once "top_nav_tickets_modal.php";
|
||||||
|
} ?>
|
||||||
<!-- /.navbar -->
|
<!-- /.navbar -->
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-secondary" id="clearAllTimers">Clear All</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user