fix: various updates

Add jquery-ui
fix uuid validation for other versions
expand queryRef method to include parameters
converted mouseover to click events for embedded links
added additional parameters to openNote and retrieveNote
This commit is contained in:
Ryan Prather 2024-05-15 22:39:56 -04:00
parent 7506b1156c
commit 090fd864b4

View File

@ -49,11 +49,9 @@ function setHeight() {
notePreview = document.querySelector('#notePreview');
notePreview.style.height = (window.innerHeight - 50) + 'px';
date = document.querySelector('#noteDate');
dt = new Date();
date.value = dt.getFullYear() + '-' +
((dt.getMonth() < 9) ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)) + '-' +
(dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate());
if ($('#noteDate')) {
$('#noteDate').datepicker();
}
setTimeout(saveNote, saveTimeout);
}
@ -138,7 +136,7 @@ function validateNote() {
const id = document.querySelector('#noteId');
const psg = document.querySelector('#passage');
if (!isUuidV4Valid(id.value)) { return false; }
if (!isUuidValid(id.value)) { return false; }
if (!title.value.length) { return false; }
if (!date.value) { return false; }
if (!parseInt(speaker.value)) { return false; }
@ -149,8 +147,8 @@ function validateNote() {
return true;
}
function isUuidV4Valid(uuid) {
const regex = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[8|9|a|b][a-f0-9]{3}-[a-f0-9]{12}$/i;
function isUuidValid(uuid) {
const regex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[8|9|a|b][a-f0-9]{3}-[a-f0-9]{12}$/i;
return regex.test(uuid);
}
@ -303,19 +301,25 @@ function closeRef() {
refQuery.style.display = 'none';
}
function queryRef() {
var input = document.querySelector('#refQuery #search');
var type = document.querySelector('#referenceType');
var book = document.querySelector('#referenceBook');
function queryRef(type = null, book = null, input = null) {
if (!input) {
var input = document.querySelector('#refQuery #search').value;
}
if (!type) {
var type = document.querySelector('#referenceType').value;
}
if (!book) {
var book = document.querySelector('#referenceBook').value;
}
fetch('/index.php/retrieve-reference', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'type': type.value,
'book': book.value,
'reference': input.value,
'type': type,
'book': book,
'reference': input,
})
})
.then(response => response.json())
@ -566,9 +570,9 @@ function findLinks() {
var links = document.querySelector('#notePreview').querySelectorAll('a');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener('mouseover', function (e) {
links[i].addEventListener('click', function (e) {
e.preventDefault();
if (!this.href.contains('notes\.rkprather\.com')) {
if (!this.href.includes('get-passage')) {
return;
}
var passage = this.href.split('/');
@ -597,7 +601,7 @@ function findLinks() {
showPassage(
e,
"<button onclick='closePopup()'>Close</button>&nbsp;&nbsp;" +
"<button onclick=\"getRef('" + book + "', '" + cv + "')\">Open Ref</button><br/>" +
"<button onclick=\"queryRef('bible', '" + book + "', '" + cv + "')\">Open Ref</button><br/>" +
result);
});
});
@ -608,9 +612,9 @@ function findRefLinks() {
var links = document.querySelector('#ref').querySelectorAll('a');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener('mouseover', function (e) {
links[i].addEventListener('click', function (e) {
e.preventDefault();
if (!this.href.contains('get-passage')) {
if (!this.href.includes('get-passage')) {
return;
}
var passage = this.href.split('/');
@ -639,7 +643,7 @@ function findRefLinks() {
showPassage(
e,
"<button onclick='closePopup()'>Close</button>&nbsp;&nbsp;" +
"<button onclick=\"getRef('" + book + "', '" + cv + "')\">Open Ref</button><br/>" +
"<button onclick=\"queryRef('bible', '" + book + "', '" + cv + "')\">Open Ref</button><br/>" +
result);
});
});
@ -667,7 +671,7 @@ function closePopup() {
popup.style.display = 'none';
}
function openNote() {
function openNote(openSidebar = true) {
const noteList = document.querySelector('#note-list');
const refs = document.querySelector('#ref');
@ -679,10 +683,12 @@ function openNote() {
refs.style.display = 'none';
}
document.querySelector('.toggle').click();
if (openSidebar) {
document.querySelector('.toggle').click();
}
}
function retrieveNote(id) {
function retrieveNote(id, runOpen = true) {
fetch('/index.php/get-note', {
method: 'POST',
header: {
@ -694,23 +700,26 @@ function retrieveNote(id) {
})
.then(response => response.json())
.then(result => {
var dt = new Date(result.date);
var dt = new Date(result.date.date);
document.querySelector('#notes').value = result.text;
document.querySelector('#passage').value = result.passage;
document.querySelector('#series').value = result.series.id;
document.querySelector('#speaker').value = result.speaker.id;
document.querySelector('#noteTitle').value = result.title;
document.querySelector('#noteDate').value = dt.getFullYear() + '-' +
(dt.getMonth() < 9 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)) + '-' +
(dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate());
document.querySelector('#noteDate').value = '';
document.querySelector('#noteDate').value =
(dt.getMonth() < 9 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1)) + '/' +
(dt.getDate() < 10 ? '0' + dt.getDate() : dt.getDate()) + '/' +
dt.getFullYear();
document.querySelector('#noteId').value = result.id;
if (result.references) {
references = result.references;
if (result.refs) {
references = result.refs;
}
const list = document.querySelector('#ref-list');
list.innerHTML = '';
var newList = null;
for (var x in references) {
var newList = document.createElement('li');
@ -720,7 +729,9 @@ function retrieveNote(id) {
list.appendChild(newList);
}
openNote();
if (runOpen) {
openNote(false);
}
});
}