Compare commits
3 Commits
d0e2e10222
...
3e278c27fa
Author | SHA1 | Date | |
---|---|---|---|
3e278c27fa | |||
9e7e84a4fc | |||
bcf95f41b8 |
@ -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;
|
||||||
|
@ -98,8 +98,8 @@ class AjaxController extends AbstractController
|
|||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
$speaker = new Speaker();
|
$speaker = new Speaker();
|
||||||
$speaker->setName($data->speakerName);
|
$speaker->setName($data->speakerName)
|
||||||
$speaker->setUser($user);
|
->setUser($user);
|
||||||
|
|
||||||
$emi->persist($speaker);
|
$emi->persist($speaker);
|
||||||
$emi->flush();
|
$emi->flush();
|
||||||
@ -139,8 +139,8 @@ class AjaxController extends AbstractController
|
|||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
$series = new Series();
|
$series = new Series();
|
||||||
$series->setName($data->seriesName);
|
$series->setName($data->seriesName)
|
||||||
$series->setUser($user);
|
->setUser($user);
|
||||||
|
|
||||||
$emi->persist($series);
|
$emi->persist($series);
|
||||||
$emi->flush();
|
$emi->flush();
|
||||||
@ -267,22 +267,28 @@ class AjaxController extends AbstractController
|
|||||||
public function saveNote(Request $req, EntityManagerInterface $emi): Response
|
public function saveNote(Request $req, EntityManagerInterface $emi): Response
|
||||||
{
|
{
|
||||||
$data = json_decode($req->getContent());
|
$data = json_decode($req->getContent());
|
||||||
$note = $emi->getRepository(Note::class)->find($data->id);
|
$newNote = false;
|
||||||
|
if (isset($data->id) && $data->id) {
|
||||||
|
/** @var Note|array $note */
|
||||||
|
$note = $emi->getRepository(Note::class)->findBy(['id' => $data->id, 'user' => $this->getUser()]);
|
||||||
|
|
||||||
if (!$note) {
|
if (is_array($note) && count($note) > 0) {
|
||||||
|
/** @var Note $note */
|
||||||
|
$note = $note[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$note = new Note();
|
$note = new Note();
|
||||||
$uuid = Uuid::fromString($data->id);
|
$newNote = true;
|
||||||
$note->setId($uuid);
|
$note->setUser($this->getUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
$refs = json_decode(json_encode($data->refs), true);
|
$refs = json_decode(json_encode($data->refs), true);
|
||||||
|
|
||||||
$series = $emi->getRepository(Series::class)->find($data->series);
|
$series = $emi->getRepository(Series::class)->find($data->series);
|
||||||
$speaker = $emi->getRepository(Speaker::class)->find($data->speaker);
|
$speaker = $emi->getRepository(Speaker::class)->find($data->speaker);
|
||||||
$user = $this->getUser();
|
|
||||||
|
|
||||||
$note->setUser($user)
|
/** @var Note $note */
|
||||||
->setTitle($data->title)
|
$note->setTitle($data->title)
|
||||||
->setDate(new DateTime($data->date))
|
->setDate(new DateTime($data->date))
|
||||||
->setSeries($series)
|
->setSeries($series)
|
||||||
->setSpeaker($speaker)
|
->setSpeaker($speaker)
|
||||||
@ -296,7 +302,8 @@ class AjaxController extends AbstractController
|
|||||||
$res = new Response();
|
$res = new Response();
|
||||||
$res->setContent(json_encode([
|
$res->setContent(json_encode([
|
||||||
'msg' => 'saved',
|
'msg' => 'saved',
|
||||||
'id' => $note->getId()
|
'id' => $note->getId(),
|
||||||
|
'new' => $newNote,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
|
@ -26,11 +26,9 @@ class DefaultController extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||||
$last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user);
|
$last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user);
|
||||||
$uuid = Uuid::v4();
|
|
||||||
|
|
||||||
return $this->render('default/home.html.twig', [
|
return $this->render('default/home.html.twig', [
|
||||||
'last4Notes' => $last4Notes,
|
'last4Notes' => $last4Notes,
|
||||||
'id' => $uuid,
|
|
||||||
'isAdmin' => $this->isGranted('ROLE_ADMIN'),
|
'isAdmin' => $this->isGranted('ROLE_ADMIN'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id='fields-container'>
|
<div id='fields-container'>
|
||||||
<input type="hidden" id="noteId" value="{{ id }}" />
|
<input type="hidden" id="noteId" value="" />
|
||||||
<input type="text" id="noteTitle" placeholder="Title..." />
|
<input type="text" id="noteTitle" placeholder="Title..." />
|
||||||
<input type='text' id='noteDate' onchange='textDirty=true;saved=false;' />
|
<input type='text' id='noteDate' onchange='textDirty=true;saved=false;' />
|
||||||
<input type='text' id='newSpeaker' placeholder='Name...' onkeyup='saveSpeaker(event)' style='display:none;' />
|
<input type='text' id='newSpeaker' placeholder='Name...' onkeyup='saveSpeaker(event)' style='display:none;' />
|
||||||
|
Loading…
Reference in New Issue
Block a user