increase saveTimeout

add check for note text to see if something has changed
add recording link text field
fix error for check
covert reference buttons to match style of other buttons
This commit is contained in:
Ryan Prather 2024-05-26 22:30:03 -04:00
parent 77e2777c7a
commit 72bf4273f3

View File

@ -4,7 +4,7 @@ var references = {};
var tabs = []; var tabs = [];
let saved = false; let saved = false;
let textDirty = false; let textDirty = false;
let saveTimeout = 10000; let saveTimeout = 15000;
var to = null; var to = null;
let controller; let controller;
var BOOKS = {}; var BOOKS = {};
@ -158,6 +158,7 @@ function saveNote(event) {
} }
let saveCheck = document.querySelector('#save-check'); let saveCheck = document.querySelector('#save-check');
var noteText = document.querySelector('#notes').value;
startSave(); startSave();
@ -169,6 +170,7 @@ function saveNote(event) {
series: document.querySelector('#series').value, series: document.querySelector('#series').value,
passage: document.querySelector('#passage').value, passage: document.querySelector('#passage').value,
note: document.querySelector('#notes').value, note: document.querySelector('#notes').value,
recording: document.querySelector('#recording').value,
refs: references refs: references
}; };
$.ajax({ $.ajax({
@ -182,20 +184,23 @@ function saveNote(event) {
.done(function (data) { .done(function (data) {
if (data.msg == 'saved' && !saved) { if (data.msg == 'saved' && !saved) {
saveCheck.classList.remove('saving'); saveCheck.classList.remove('saving');
saveCheck.classList.remove('error');
showSave(); showSave();
saved = true; if (noteText == document.querySelector('#notes').value) {
textDirty = false; saved = true;
document.querySelector('#note-header-left h2').classList.remove('dirty'); textDirty = false;
document.querySelector('#note-header-left h2').classList.remove('dirty');
}
if (data.new) { if (data.new) {
document.querySelector('#noteId').value = data.id; document.querySelector('#noteId').value = data.id;
} }
} }
}) })
.fail(function (data) { .fail(function (xhr, status, error) {
saveCheck.classList.remove('saving'); saveCheck.classList.remove('saving');
saveCheck.classList.add('error'); saveCheck.classList.add('error');
console.error(data); console.error(error);
}) })
.always(function (xhr, status) { .always(function (xhr, status) {
if (status == 'timeout') { if (status == 'timeout') {
@ -271,6 +276,9 @@ function discardNote() {
document.querySelector('#template').value = 0; document.querySelector('#template').value = 0;
document.querySelector('#passage').value = ''; document.querySelector('#passage').value = '';
document.querySelector('#notes').value = ''; document.querySelector('#notes').value = '';
document.querySelector('#recording').value = '';
document.querySelector('#noteDate').value = '';
document.querySelector('#noteId').value = '';
fetch('/index.php/discard-note', { fetch('/index.php/discard-note', {
method: 'POST', method: 'POST',
@ -368,6 +376,8 @@ function saveSeries(event) {
} }
function openRef(closeSidebar = true) { function openRef(closeSidebar = true) {
document.querySelector('#openRefBtn').classList.add('active');
refQuery = document.querySelector('#refQuery'); refQuery = document.querySelector('#refQuery');
refQuery.style.display = 'block'; refQuery.style.display = 'block';
@ -389,6 +399,7 @@ function closeRef() {
document.querySelector('#verse-range').innerText = ''; document.querySelector('#verse-range').innerText = '';
document.querySelector('#refQuery').style.display = 'none'; document.querySelector('#refQuery').style.display = 'none';
document.querySelector('#openRefBtn').classList.remove('active');
} }
function queryRef(type = null, book = null, input = null) { function queryRef(type = null, book = null, input = null) {
@ -438,10 +449,11 @@ function queryRef(type = null, book = null, input = null) {
function makeButton(title) { function makeButton(title) {
var btn = document.createElement('button'); var btn = document.createElement('button');
btn.innerText = title; btn.innerText = title;
btn.class = 'button';
btn.addEventListener('click', function () { btn.addEventListener('click', function () {
removeActiveRef(); removeActiveRef();
document.querySelector('#ref').innerHTML = md.render(references[title]); document.querySelector('#ref').innerHTML = md.render(references[title]);
this.classList.add('activeRef'); this.classList.add('active');
findRefLinks(); findRefLinks();
}); });
@ -456,16 +468,16 @@ function makeButton(title) {
}); });
removeActiveRef(); removeActiveRef();
btn.classList.add('activeRef'); btn.classList.add('active');
return btn; return btn;
} }
function removeActiveRef() { function removeActiveRef() {
tabs = document.querySelectorAll('.activeRef'); tabs = document.querySelectorAll('.active');
for (var t in tabs) { for (var t in tabs) {
if (isFinite(parseInt(t))) { if (isFinite(parseInt(t))) {
tabs[t].classList.remove('activeRef'); tabs[t].classList.remove('active');
} }
} }
} }
@ -573,6 +585,30 @@ function retrieveBooks() {
newBook.text = BOOKS.cd[x]; newBook.text = BOOKS.cd[x];
bookList.appendChild(newBook); bookList.appendChild(newBook);
} }
} else if (selectedType == 'note') {
var none = document.createElement("option");
none.value = '';
none.text = '-- Select --';
bookList.appendChild(none);
fetch('/index.php/retrieve-reference', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'type': 'note'
})
})
.then(response => response.json())
.then(results => {
for (var x in results) {
var newBook = document.createElement("option");
newBook.value = results[x].id;
newBook.text = results[x].title;
bookList.appendChild(newBook);
}
});
} else { } else {
var min = BOOKS[selectedType][0]; var min = BOOKS[selectedType][0];
var max = BOOKS[selectedType][1]; var max = BOOKS[selectedType][1];
@ -623,6 +659,10 @@ function filterVerse() {
} }
function retrieveReference(el) { function retrieveReference(el) {
if (el.value == 'new') {
document.querySelector('#refName').style.display = 'inline-block';
return;
}
fetch('/index.php/get-reference', { fetch('/index.php/get-reference', {
method: "POST", method: "POST",
header: { header: {