add new block dialog to scheduler
This commit is contained in:
parent
0cd0d860c4
commit
ec02a912f4
34
layout.html
34
layout.html
@ -723,18 +723,43 @@
|
||||
}
|
||||
|
||||
const fetch_block_tags = async (block_id) => {
|
||||
const id = block_id || 0;
|
||||
const id = block_id || crypto.randomUUID();
|
||||
const api_url = "tags.php?block_id=" + id;
|
||||
fetch(api_url).then((response) => {
|
||||
if (response.ok) {
|
||||
response.json().then((tags) => {
|
||||
const container = document.querySelector("#new_block_program_tags");
|
||||
container.innerHTML = "";
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
const enabled_class = tags[i]['enabled'] === 'true' ? 'enabled' : 'disabled';
|
||||
for (var i = 0; i < tags.program.length; i++) {
|
||||
// tags for program itself
|
||||
const enabled_class = tags.program[i]['enabled'] === 'true' ? 'enabled' : 'disabled';
|
||||
const new_span = `<span class='tag ${enabled_class}' data-id='${tags[i]['id']}'>${tags[i]['tag']}</span>`;
|
||||
container.innerHTML += new_span;
|
||||
}
|
||||
const promo_container = document.querySelector("#new_block_promos_tag");
|
||||
promo_container.innerHTML = "";
|
||||
for (var i = 0; i < tags.promos.length; i++) {
|
||||
// tags for promos run during program
|
||||
const enabled_class = tags.promos[i]['enabled'] === 'true' ? 'enabled' : 'disabled';
|
||||
const new_span = `<span class='tag ${enabled_class}' data-id='${tags[i]['id']}'>${tags[i]['tag']}</span>`;
|
||||
promo_container.innerHTML += new_span;
|
||||
}
|
||||
const commercial_container = document.querySelector("#new_block_commercials_tag");
|
||||
commercial_container.innerHTML = "";
|
||||
for (var i = 0; i < tags.commercials.length; i++) {
|
||||
// tags for commercials run during program
|
||||
const enabled_class = tags.commercials[i]['enabled'] === 'true' ? 'enabled' : 'disabled';
|
||||
const new_span = `<span class='tag ${enabled_class}' data-id='${tags[i]['id']}'>${tags[i]['tag']}</span>`;
|
||||
commercial_container.innerHTML += new_span;
|
||||
}
|
||||
const bumper_container = document.querySelector("#new_block_bumpers_tag");
|
||||
bumper_container.innerHTML = "";
|
||||
for (var i = 0; i < tags.bumpers.length; i++) {
|
||||
// tags for bumpers run during program
|
||||
const enabled_class = tags.bumpers[i]['enabled'] === 'true' ? 'enabled' : 'disabled';
|
||||
const new_span = `<span class='tag ${enabled_class}' data-id='${tags[i]['id']}'>${tags[i]['tag']}</span>`;
|
||||
bumper_container.innerHTML += new_span;
|
||||
}
|
||||
block_tag_editor_handlers();
|
||||
});
|
||||
} else {
|
||||
@ -843,7 +868,6 @@
|
||||
|
||||
// add event handlers
|
||||
const block_cells = document.querySelectorAll(".schedule_grid_program_cell");
|
||||
console.dir(block_cells);
|
||||
block_cells.forEach((cell) => {
|
||||
cell.addEventListener("click", schedule_grid_click_handler);
|
||||
});
|
||||
@ -970,7 +994,7 @@
|
||||
}
|
||||
|
||||
const block_tag_editor_handlers = () => {
|
||||
const tags = document.querySelectorAll("#new_block_program_tags > .tag");
|
||||
const tags = document.querySelectorAll("#new_block_program_tags > .tag, #new_block_commercials_tags > .tag, #new_block_promos_tags > .tag, #new_block_bumpers_tags > .tag");
|
||||
tags.forEach((tag) => {
|
||||
tag.addEventListener("click", block_tag_editor_click_handler);
|
||||
});
|
||||
|
65
tags.php
Normal file → Executable file
65
tags.php
Normal file → Executable file
@ -37,6 +37,71 @@ if (isset($_POST['new_tag']) && $_POST['new_tag'] !== "") {
|
||||
echo('{"ok": false}');
|
||||
}
|
||||
exit();
|
||||
} else if (isset($_GET['block_id']) && trim($_GET['block_id']) !== '') {
|
||||
// get all tags and on/off status for a particular block
|
||||
$tagsQuery = "SELECT * FROM tags ORDER BY tag ASC";
|
||||
$tagsResult = $db->query($tagsQuery);
|
||||
|
||||
if ($tagsResult) {
|
||||
$tags = array();
|
||||
|
||||
while ($row = $tagsResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$tags[] = $row;
|
||||
}
|
||||
|
||||
$tagsForBlockQuery = $db->prepare("SELECT * FROM block_tags WHERE block_id = :block_id ORDER BY slot_type ASC, tag_id ASC");
|
||||
$tagsForBlockQuery->bindValue(":block_id", trim($_GET['block_id']));
|
||||
$tagsForBlockResult = $tagsForBlockQuery->execute();
|
||||
|
||||
if ($tagsForBlockResult) {
|
||||
$tagsForBlock = array();
|
||||
$tagsForBlock['program'] = $tags;
|
||||
$tagsForBlock['promos'] = $tags;
|
||||
$tagsForBlock['commercials'] = $tags;
|
||||
$tagsForBlock['bumpers'] = $tags;
|
||||
|
||||
$allTagsForBlock = array();
|
||||
while ($row = $tagsForBlockResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$allTagsForBlock[$row['slot_type']][] = $row['tag_id'];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < sizeof($allTagsForBlock['program']); $i++) {
|
||||
if (array_search($tagsForBlock['program'][$i], $allTagsForBlock['program']) !== false) {
|
||||
$tagsForBlock['program'][$i]['enabled'] = 'true';
|
||||
} else {
|
||||
$tagsForBlock['program'][$i]['enabled'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < sizeof($allTagsForBlock['promos']); $i++) {
|
||||
if (array_search($tagsForBlock['promos'][$i], $allTagsForBlock['promos']) !== false) {
|
||||
$tagsForBlock['promos'][$i]['enabled'] = 'true';
|
||||
} else {
|
||||
$tagsForBlock['promos'][$i]['enabled'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < sizeof($allTagsForBlock['commercials']); $i++) {
|
||||
if (array_search($tagsForBlock['commercials'][$i], $allTagsForBlock['commercials']) !== false) {
|
||||
$tagsForBlock['commercials'][$i]['enabled'] = 'true';
|
||||
} else {
|
||||
$tagsForBlock['commercials'][$i]['enabled'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < sizeof($allTagsForBlock['bumpers']); $i++) {
|
||||
if (array_search($tagsForBlock['bumpers'][$i], $allTagsForBlock['bumpers']) !== false) {
|
||||
$tagsForBlock['bumpers'][$i]['enabled'] = 'true';
|
||||
} else {
|
||||
$tagsForBlock['bumpers'][$i]['enabled'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo(json_encode($tagsForBlock));
|
||||
exit();
|
||||
}
|
||||
}
|
||||
} else if (isset($_GET['media_id']) && intval($_GET['media_id']) > -1) {
|
||||
// get all tags and on/off status for a particular media item
|
||||
$tagsQuery = "SELECT * FROM tags ORDER BY tag ASC";
|
||||
|
Loading…
Reference in New Issue
Block a user