fix setTimeouts
This commit is contained in:
parent
bcf95f41b8
commit
9e7e84a4fc
@ -5,6 +5,7 @@ var tabs = [];
|
|||||||
let saved = false;
|
let saved = false;
|
||||||
let textDirty = false;
|
let textDirty = false;
|
||||||
let saveTimeout = 10000;
|
let saveTimeout = 10000;
|
||||||
|
var to = null;
|
||||||
|
|
||||||
document.addEventListener('keyup', function (event) {
|
document.addEventListener('keyup', function (event) {
|
||||||
if (event.key == "F3") {
|
if (event.key == "F3") {
|
||||||
@ -60,7 +61,9 @@ function setHeight() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setTimeout(saveNote, saveTimeout);
|
if (!to) {
|
||||||
|
to = setTimeout(saveNote, saveTimeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
@ -133,7 +136,8 @@ function saveNote(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!textDirty || !validateNote()) {
|
if (!textDirty || !validateNote()) {
|
||||||
setTimeout(saveNote, saveTimeout);
|
clearTimeout(to);
|
||||||
|
to = setTimeout(saveNote, saveTimeout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,10 +165,14 @@ function saveNote(event) {
|
|||||||
saved = true;
|
saved = true;
|
||||||
textDirty = false;
|
textDirty = false;
|
||||||
document.querySelector('#note-header-left h2').classList.remove('dirty');
|
document.querySelector('#note-header-left h2').classList.remove('dirty');
|
||||||
|
|
||||||
|
if (data.new) {
|
||||||
|
document.querySelector('#noteId').value = data.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => console.log(error))
|
.catch(error => console.log(error))
|
||||||
.finally(() => setTimeout(saveNote, saveTimeout));
|
.finally(() => function () { clearTimeout(to); to = setTimeout(saveNote, saveTimeout); });
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateNote() {
|
function validateNote() {
|
||||||
@ -173,10 +181,8 @@ function validateNote() {
|
|||||||
const speaker = document.querySelector('#speaker');
|
const speaker = document.querySelector('#speaker');
|
||||||
const series = document.querySelector('#series');
|
const series = document.querySelector('#series');
|
||||||
const title = document.querySelector('#noteTitle');
|
const title = document.querySelector('#noteTitle');
|
||||||
const id = document.querySelector('#noteId');
|
|
||||||
const psg = document.querySelector('#passage');
|
const psg = document.querySelector('#passage');
|
||||||
|
|
||||||
if (!isUuidValid(id.value)) { return false; }
|
|
||||||
if (!title.value.length) { return false; }
|
if (!title.value.length) { return false; }
|
||||||
if (!date.value) { return false; }
|
if (!date.value) { return false; }
|
||||||
if (!parseInt(speaker.value)) { return false; }
|
if (!parseInt(speaker.value)) { return false; }
|
||||||
@ -380,6 +386,7 @@ function queryRef(type = null, book = null, input = null) {
|
|||||||
document.querySelector('#referenceType').value = '';
|
document.querySelector('#referenceType').value = '';
|
||||||
document.querySelector('#referenceBook').value = '';
|
document.querySelector('#referenceBook').value = '';
|
||||||
document.querySelector('#referenceBook').style.display = 'none';
|
document.querySelector('#referenceBook').style.display = 'none';
|
||||||
|
document.querySelector('#refQuery #search').value = '';
|
||||||
closeRef();
|
closeRef();
|
||||||
|
|
||||||
saved = false;
|
saved = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user