add execute input box

This commit is contained in:
Tim Fry 2024-12-02 19:06:53 -04:00
parent b14e8f20c8
commit b1330ec105
2 changed files with 62 additions and 3 deletions

View File

@ -342,9 +342,20 @@ if (count($_POST) > 0) {
//javascript constants for use in the selection option group
echo "<script>\n";
echo "window.permission_execute = " . (permission_exists('phrase_execute') ? 'true' : 'false') . ";\n";
echo "window.phrase_label_sounds = '" . ($text['label-sounds'] ?? 'Sounds') . "';\n";
echo "window.phrase_label_recordings = '" . ($text['label-recordings'] ?? 'Recordings') . "';\n";
echo "window.phrase_commands = " . json_encode([$text['label-play'] ?? 'Play', $text['label-pause'] ?? 'Pause', $text['label-execute'] ?? 'Execute'], true) . ";\n";
//only include permissive actions
$phrase_commands = [];
if (permission_exists('phrase_play')) {
$phrase_commands[] = $text['label-play'] ?? 'Play';
$phrase_commands[] = $text['label-pause'] ?? 'Pause';
}
if (permission_exists('phrase_execute')) {
$phrase_commands[] = $text['label-execute'] ?? 'Execute';
}
echo "window.phrase_commands = " . json_encode($phrase_commands, true) . ";\n";
//existing details
if (!empty($phrase_details)) {

View File

@ -31,6 +31,44 @@ document.addEventListener("DOMContentLoaded", function () {
add_draggable_rows();
});
//
// Switch to a text input box when 'Execute' is selected instead of dropdown
//
function add_switch_to_text_input(select_action) {
if (window.permission_execute) {
const row = select_action.parentNode.parentNode;
const row_index = document.getElementById('structure').rows.length;
//get the select boxes
const select_list = row.querySelectorAll('td select'); //action and recording select dropdown boxes
const select_data = select_list[1];
// Create a new text input to replace the select when execute is chosen
const textInput = document.createElement('input');
textInput.type = 'text';
textInput.className = 'formfld';
textInput.id = 'phrase_detail_data_input[' + row_index + ']';
textInput.name = 'phrase_detail_data_input[' + row_index + ']';
//match style
textInput.style.width = select_data.style.width;
textInput.style.height = select_data.style.height;
//set to hide
textInput.style.display = 'none';
select_data.parentNode.appendChild(textInput);
select_action.addEventListener('change', function () {
if (select_action.value === 'execute') {
//show text box
select_data.style.display = 'none';
textInput.style.display = 'block';
} else {
//hide text box
select_data.style.display = 'block';
textInput.style.display = 'none';
}
});
}
}
//
// Inserts all existing records before the empty one
//
@ -47,7 +85,8 @@ function add_existing() {
const select_list = newRow.querySelectorAll('td select'); //action and recording select dropdown boxes
//play, pause, execute select box
const select_action = select_list[0];
select_by_text(select_action, 'Play');
add_switch_to_text_input(select_action);
select_by_value(select_action, 'play-file');
//recording select box
const select_recording = select_list[1];
@ -181,10 +220,19 @@ function add_row() {
//reset id
newRow.id = 'row_' + index;
//reset 'name' attribute
newRow.setAttribute('name', 'recording_' + index);
//get the select boxes
const select_list = newRow.querySelectorAll('td select'); //action and recording select dropdown boxes
//play, pause, execute select box
const select_action = select_list[0];
//recording select box
const select_recording = select_list[1];
//add switchable select box to text input box
add_switch_to_text_input(select_action);
//add the row to the table body
tbody.appendChild(newRow);