From 70d385133d078bcc8c6ad9bf3c6d1daf3312e37d Mon Sep 17 00:00:00 2001 From: erew123 <35898566+erew123@users.noreply.github.com> Date: Mon, 8 Jan 2024 01:13:36 +0000 Subject: [PATCH] JSON import pagination --- .../tts_chunk_player/tts_chunk_player.html | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/templates/tts_chunk_player/tts_chunk_player.html b/templates/tts_chunk_player/tts_chunk_player.html index 41082dc..a241377 100644 --- a/templates/tts_chunk_player/tts_chunk_player.html +++ b/templates/tts_chunk_player/tts_chunk_player.html @@ -1506,35 +1506,59 @@ } function importFromJSON() { - const input = document.createElement('input'); - input.type = 'file'; - input.accept = '.json'; + const input = document.createElement('input'); + input.type = 'file'; + input.accept = '.json'; - input.onchange = (e) => { - const file = e.target.files[0]; - if (file) { - const reader = new FileReader(); - reader.readAsText(file); - reader.onload = (e) => { - try { - const jsonData = JSON.parse(e.target.result); - console.log('JSON data imported:', jsonData); + input.onchange = async (e) => { + const file = e.target.files[0]; + if (file) { + const reader = new FileReader(); + reader.readAsText(file); + reader.onload = (e) => { + try { + const jsonData = JSON.parse(e.target.result); - // Update the ttsList with the imported data - ttsList = jsonData; + ttsList = jsonData; + currentPage = 1; // Reset to the first page + updateUIList(); + updatePaginationControls(); // Update pagination controls + } catch (error) { + console.error('Error parsing JSON:', error); + } + }; + } + }; - // Refresh the on-screen list - updateUIList(); // This function updates the UI with the contents of ttsList - } catch (error) { - console.error('Error parsing JSON:', error); - } - }; - } - }; + input.click(); +} - input.click(); +function updatePaginationControls() { + const lastPage = Math.ceil(ttsList.length / itemsPerPage); + const pageIndicator = document.getElementById('pageIndicator'); + if (pageIndicator) { + pageIndicator.textContent = `Page ${currentPage} of ${lastPage}`; } + const prevPageButton = document.getElementById('prevPage'); + if (prevPageButton) { + prevPageButton.disabled = (currentPage === 1); + } + + const nextPageButton = document.getElementById('nextPage'); + if (nextPageButton) { + nextPageButton.disabled = (currentPage === lastPage); + } + + // Similar updates for any additional pagination controls if you have them + // ... +} + + + + + + ////////////////////////////// //////// Other Things //////// //////////////////////////////