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