Edit poljubne in ustvari novo. #11
This commit is contained in:
@@ -22,6 +22,19 @@ const editTitleInput = document.getElementById('edit-title');
|
||||
const editLyricsInput = document.getElementById('edit-lyrics');
|
||||
const saveEditBtn = document.getElementById('save-edit-btn');
|
||||
const cancelEditBtn = document.getElementById('cancel-edit-btn');
|
||||
const editSongNumberDisplay = document.getElementById('edit-song-number-display');
|
||||
|
||||
// Prompt Modal elementi
|
||||
const promptModal = document.getElementById('prompt-modal');
|
||||
const promptInput = document.getElementById('prompt-input');
|
||||
const promptEditBtn = document.getElementById('prompt-edit-btn');
|
||||
const promptCancelBtn = document.getElementById('prompt-cancel-btn');
|
||||
const promptNewBtn = document.getElementById('prompt-new-btn');
|
||||
|
||||
// Info Modal elementi
|
||||
const infoModal = document.getElementById('info-modal');
|
||||
const infoMessage = document.getElementById('info-message');
|
||||
const infoOkBtn = document.getElementById('info-ok-btn');
|
||||
|
||||
let capsMode = false;
|
||||
let wakeLock = null;
|
||||
@@ -225,20 +238,38 @@ async function toggleCaps() {
|
||||
}
|
||||
|
||||
// Odpri urejevalnik
|
||||
async function openEditor() {
|
||||
async function openEditor(songId = null) {
|
||||
try {
|
||||
const response = await fetch('/api/get_song_details');
|
||||
if (songId === 'new') {
|
||||
editTitleInput.value = '';
|
||||
editLyricsInput.value = '';
|
||||
editModal.dataset.songId = 'new';
|
||||
editSongNumberDisplay.textContent = '';
|
||||
editModal.style.display = 'block';
|
||||
menuDropdown.classList.remove('show');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = songId ? `/api/get_song_details?id=${songId}` : '/api/get_song_details';
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status === 'ok') {
|
||||
editTitleInput.value = data.song.title;
|
||||
editLyricsInput.value = data.song.lyrics;
|
||||
editModal.dataset.songId = data.song.id;
|
||||
editSongNumberDisplay.textContent = data.song.id;
|
||||
editModal.style.display = 'block';
|
||||
menuDropdown.classList.remove('show');
|
||||
} else {
|
||||
alert(data.message || 'Za urejanje najprej naložite besedilo.');
|
||||
menuDropdown.classList.remove('show');
|
||||
if (!songId) {
|
||||
// Če ni naložene pesmi, pokaži prompt
|
||||
promptModal.style.display = 'block';
|
||||
promptInput.value = '';
|
||||
menuDropdown.classList.remove('show');
|
||||
} else {
|
||||
alert(data.message || 'Napaka pri pridobivanju podatkov.');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Napaka pri pridobivanju podatkov:', error);
|
||||
@@ -246,6 +277,11 @@ async function openEditor() {
|
||||
}
|
||||
}
|
||||
|
||||
function showInfo(message) {
|
||||
infoMessage.textContent = message;
|
||||
infoModal.style.display = 'block';
|
||||
}
|
||||
|
||||
// Zapri urejevalnik
|
||||
function closeEditor() {
|
||||
editModal.style.display = 'none';
|
||||
@@ -276,6 +312,9 @@ async function saveSongEdit() {
|
||||
|
||||
if (data.status === 'ok') {
|
||||
closeEditor();
|
||||
if (data.new_id) {
|
||||
showInfo(`Nova pesem je bila shranjena pod številko: ${data.new_id}`);
|
||||
}
|
||||
await updateState(true);
|
||||
} else {
|
||||
alert('Napaka pri shranjevanju: ' + data.message);
|
||||
@@ -376,6 +415,39 @@ if (saveEditBtn) {
|
||||
});
|
||||
}
|
||||
|
||||
// Prompt Modal dogodki
|
||||
if (promptEditBtn) {
|
||||
promptEditBtn.addEventListener('click', () => {
|
||||
const id = promptInput.value.trim();
|
||||
if (id) {
|
||||
promptModal.style.display = 'none';
|
||||
openEditor(id);
|
||||
} else {
|
||||
alert('Vnesite številko pesmi.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (promptCancelBtn) {
|
||||
promptCancelBtn.addEventListener('click', () => {
|
||||
promptModal.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
if (promptNewBtn) {
|
||||
promptNewBtn.addEventListener('click', () => {
|
||||
promptModal.style.display = 'none';
|
||||
openEditor('new');
|
||||
});
|
||||
}
|
||||
|
||||
// Info Modal dogodki
|
||||
if (infoOkBtn) {
|
||||
infoOkBtn.addEventListener('click', () => {
|
||||
infoModal.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
// Hamburger menu toggle
|
||||
if (menuToggle) {
|
||||
menuToggle.addEventListener('click', (e) => {
|
||||
@@ -430,6 +502,14 @@ document.addEventListener('keydown', (e) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Če smo v promptu za številko, ne procesiraj bližnjic za numerično tipkovnico
|
||||
if (promptModal && promptModal.style.display === 'block') {
|
||||
if (e.key === 'Escape') {
|
||||
promptModal.style.display = 'none';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// na telefonu ni potrebe; na velikih ekranih pa naj dela
|
||||
if (window.innerWidth < 901) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user