";
echo "| ".$text['label-structure']." | ";
echo "";
- echo " \n";
+ //structure table
+ echo " \n";
+ //headings
+ echo " \n";
echo " \n";
- echo " | ".$text['label-function']." | \n";
+ echo " " . ($text['label-order'] ?? 'Order') . " | \n";
echo " ".$text['label-action']." | \n";
- echo " ".$text['label-order']." | \n";
- if (!empty($phrase_details)) {
- echo " \n";
- echo " ".$text['label-delete']."\n";
- echo " \n";
- echo " | \n";
- }
+ echo " ".($text['label-recording'] ?? 'Recording')." | \n";
+/*
+// echo " ".$text['label-order']." | \n";
+// if (!empty($phrase_details)) {
+// echo " \n";
+// echo " ".$text['label-delete']."\n";
+// echo " \n";
+// echo " | \n";
+// }
+//*/
echo " \n";
- if (!empty($phrase_details)) {
- foreach($phrase_details as $x => $field) {
- //clean up output for display
- if ($field['phrase_detail_function'] == 'play-file' && substr($field['phrase_detail_data'], 0, 21) == '${lua streamfile.lua ') {
- $phrase_detail_function = $text['label-play'];
- $phrase_detail_data = str_replace('${lua streamfile.lua ', '', $field['phrase_detail_data']);
- $phrase_detail_data = str_replace('}', '', $phrase_detail_data);
- }
- else if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 6) == 'sleep(') {
- $phrase_detail_function = $text['label-pause'];
- $phrase_detail_data = str_replace('sleep(', '', $field['phrase_detail_data']);
- $phrase_detail_data = str_replace(')', '', $phrase_detail_data);
- $phrase_detail_data = ($phrase_detail_data / 1000).'s'; // seconds
- }
- else if ($field['phrase_detail_function'] == 'play-file') {
- $phrase_detail_function = $text['label-play'];
- $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/', '', $field['phrase_detail_data']);
- }
- else {
- $phrase_detail_function = $field['phrase_detail_function'];
- $phrase_detail_data = $field['phrase_detail_data'];
- }
- echo "\n";
- echo " | ".escape($phrase_detail_function)." | \n";
- echo " ".escape($phrase_detail_data)." | \n";
- echo " ".$field['phrase_detail_order']." | \n";
- echo " ";
- if (is_uuid($field['phrase_detail_uuid'])) {
- echo " \n";
- echo " \n";
- }
- echo " | \n";
- echo " \n";
- }
- }
- unset($phrase_details, $field);
- echo "\n";
+ echo " \n";
+ echo "\n";
+/*
+// if (!empty($phrase_details)) {
+// foreach($phrase_details as $x => $field) {
+// //clean up output for display
+// if ($field['phrase_detail_function'] == 'play-file' && substr($field['phrase_detail_data'], 0, 21) == '${lua streamfile.lua ') {
+// $phrase_detail_function = $text['label-play'];
+// $phrase_detail_data = str_replace('${lua streamfile.lua ', '', $field['phrase_detail_data']);
+// $phrase_detail_data = str_replace('}', '', $phrase_detail_data);
+// }
+// else if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 6) == 'sleep(') {
+// $phrase_detail_function = $text['label-pause'];
+// $phrase_detail_data = str_replace('sleep(', '', $field['phrase_detail_data']);
+// $phrase_detail_data = str_replace(')', '', $phrase_detail_data);
+// $phrase_detail_data = ($phrase_detail_data / 1000).'s'; // seconds
+// }
+// else if ($field['phrase_detail_function'] == 'play-file') {
+// $phrase_detail_function = $text['label-play'];
+// $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/', '', $field['phrase_detail_data']);
+// }
+// else {
+// $phrase_detail_function = $field['phrase_detail_function'];
+// $phrase_detail_data = $field['phrase_detail_data'];
+// }
+// echo "\n";
+// echo " | ".escape($phrase_detail_function)." | \n";
+// echo " ".escape($phrase_detail_data)." | \n";
+// echo " ".$field['phrase_detail_order']." | \n";
+// echo " ";
+// if (is_uuid($field['phrase_detail_uuid'])) {
+// echo " \n";
+// echo " \n";
+// }
+// echo " | \n";
+// echo " \n";
+// }
+// }
+// unset($phrase_details, $field);
+//*/
+ echo "\n";
+ echo " | ";
echo " \n";
echo " | \n";
- echo " \n";
- echo " \n";
- echo " | \n";
- echo " \n";
- echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]);
- echo " | \n";
-
+/*
+// echo " \n";
+// echo " \n";
+// echo " | \n";
+// */
echo " \n";
+ echo "";
+ echo "";
+ echo "";
+ echo "| | ";
+ echo "";
+ echo button::create(['type'=>'button','icon'=>$_SESSION['theme']['button_icon_add'], 'onclick' => 'add_row()']);
+ echo button::create(['type'=>'button','icon'=>'fa-solid fa-minus', 'onclick' => 'remove_row()']);
+ echo " | ";
+ echo " | ";
+ echo " ";
+ echo "\n";
echo " \n";
echo " ".$text['description-structure']."\n";
diff --git a/app/phrases/resources/javascript/phrase_edit.js b/app/phrases/resources/javascript/phrase_edit.js
new file mode 100644
index 0000000000..f1d92fcfab
--- /dev/null
+++ b/app/phrases/resources/javascript/phrase_edit.js
@@ -0,0 +1,103 @@
+document.addEventListener("DOMContentLoaded", function () {
+ // Initialize the select options
+ const select = document.getElementById('phrase_detail_data');
+ const grp_rec = document.createElement('optgroup');
+ const grp_snd = document.createElement('optgroup');
+
+ // Add a blank entry
+ select.appendChild(new Option('', ''));
+
+ // Add recordings
+ grp_rec.label = 'Recordings';
+ for (let i = 0; i < window.phrase_recordings.length; i++) {
+ grp_rec.appendChild(new Option(' ' + window.phrase_recordings[i].recording_name, window.phrase_recordings[i].recording_uuid));
+ }
+ select.appendChild(grp_rec);
+
+ // Add sounds
+ grp_snd.label = 'Sounds';
+ for (let i = 0; i < window.phrase_sounds.length; i++) {
+ grp_snd.appendChild(new Option(' ' + window.phrase_sounds[i], i));
+ }
+ select.appendChild(grp_snd);
+
+ // Initialize draggable rows
+ add_draggable_rows();
+});
+
+// Add draggable functionality to rows
+function add_draggable_rows() {
+ const tableBody = document.getElementById('structure');
+ let draggedRow = null;
+
+ tableBody.querySelectorAll('tr').forEach((row) => {
+ // Make rows draggable
+ row.setAttribute('draggable', 'true');
+
+ // When dragging starts
+ row.addEventListener('dragstart', (e) => {
+ draggedRow = row;
+ e.dataTransfer.effectAllowed = 'move';
+ e.dataTransfer.setData('text/plain', row.rowIndex);
+
+ // Highlight the dragged row
+ row.style.backgroundColor = '#d1e7fd'; // Light blue color
+ row.style.opacity = '0.8'; // Slightly transparent for visual feedback
+ });
+
+ // When dragging ends
+ row.addEventListener('dragend', () => {
+ draggedRow = null;
+
+ // Clear the background color
+ row.style.backgroundColor = '';
+ row.style.opacity = '1'; // Reset opacity
+ });
+
+ // Allow drop (prevent default behavior)
+ row.addEventListener('dragover', (e) => {
+ e.preventDefault();
+ });
+
+ // Handle drop
+ row.addEventListener('drop', (e) => {
+ e.preventDefault();
+
+ if (draggedRow && draggedRow !== row) {
+ // Insert the dragged row before the row it is dropped onto
+ tableBody.insertBefore(draggedRow, row.nextSibling || row);
+ }
+ });
+
+ // Optional: Highlight drop target
+ row.addEventListener('dragenter', () => {
+ row.style.backgroundColor = '#f0f0f0'; // Light gray for drop target
+ });
+
+ row.addEventListener('dragleave', () => {
+ row.style.backgroundColor = ''; // Clear drop target highlight
+ });
+ });
+}
+
+
+// Add a new row to the table
+function add_row() {
+ const tbody = document.getElementById('structure');
+ const newRow = document.getElementById('recordings_row').cloneNode(true);
+ newRow.id = `row_${tbody.childElementCount}`;
+ newRow.name = `recordings[${tbody.childElementCount}]`;
+
+ tbody.appendChild(newRow);
+
+ // Reinitialize draggable functionality
+ add_draggable_rows();
+}
+
+// Remove the last row in the table
+function remove_row() {
+ const tbody = document.getElementById('structure');
+ if (tbody && tbody.rows.length > 1) {
+ tbody.lastElementChild.remove();
+ }
+}
|