add new block dialog to scheduler

This commit is contained in:
Sundog Jones 2024-09-24 14:14:10 -04:00
parent 2a58c2d1d8
commit 13c8b14985
2 changed files with 7 additions and 5 deletions

View File

@ -854,7 +854,6 @@
const schedule_grid_click_handler = (e) => { const schedule_grid_click_handler = (e) => {
e.preventDefault(); e.preventDefault();
// TODO: open dialog for add block
const new_block_dialog = document.getElementById("new_block_dialog"); const new_block_dialog = document.getElementById("new_block_dialog");
const new_block_header = document.getElementById("new_block_dialog_header"); const new_block_header = document.getElementById("new_block_dialog_header");
const block_start_time = e.target.parentNode.firstElementChild.innerHTML; const block_start_time = e.target.parentNode.firstElementChild.innerHTML;
@ -870,6 +869,7 @@
event.preventDefault(); event.preventDefault();
const updateURL = "block.php"; const updateURL = "block.php";
let data = new FormData(document.getElementById("new_block_dialog_form")); let data = new FormData(document.getElementById("new_block_dialog_form"));
console.log("new block:");
console.dir(data); console.dir(data);
fetch(updateURL, { fetch(updateURL, {
method: "POST", method: "POST",
@ -878,8 +878,9 @@
.then((response) => { .then((response) => {
if (response.ok) { if (response.ok) {
response.json().then((json) => { response.json().then((json) => {
const day = new Date(Date.parse(document.querySelector("#current_day_indicator").getAttribute("data-day")));
new_block_dialog.close(); new_block_dialog.close();
load_schedule(); // TODO: need to pass day here to keep working on the same schedule! load_schedule(day);
}); });
} }
}); });

View File

@ -5,9 +5,9 @@
if (isset($_GET['date']) && $_GET['date'] !== "") { if (isset($_GET['date']) && $_GET['date'] !== "") {
// get info about single day's schedule // get info about single day's schedule
$query = $db->prepare("SELECT * FROM schedules s $query = $db->prepare("SELECT * FROM schedules s
LEFT JOIN schedules_blocks sb ON s.id = sb.schedule_id LEFT JOIN schedule_blocks sb ON s.id = sb.schedule_id
LEFT JOIN blocks b ON sb.block_id = b.id LEFT JOIN blocks b ON sb.block_id = b.id
WHERE s.date = :date"); WHERE s.day = :date");
$query->bindValue(":date", intval(strtotime($_GET['date']))); $query->bindValue(":date", intval(strtotime($_GET['date'])));
$result = $query->execute(); $result = $query->execute();
if ($result) { if ($result) {
@ -16,7 +16,8 @@
} }
} else if (isset($_POST['id']) && intval($_POST['id']) > 0) { } else if (isset($_POST['id']) && intval($_POST['id']) > 0) {
// update single schedule // update single schedule
} else if (isset($_POST['date']) && strtotime($_POST['date'])) {
} else if (isset($_POST['day']) && strtotime($_POST['day'])) {
// add new schedule // add new schedule
} else { } else {
echo("{}"); echo("{}");