From 21813ad5b57b8e2d3896637251f4fae73310e8ea Mon Sep 17 00:00:00 2001
From: Lucio Zambon <lucio.zambon@elettra.eu>
Date: Tue, 16 Jul 2024 03:26:12 +0000
Subject: [PATCH] Update talk.js

---
 speech/talk.js | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/speech/talk.js b/speech/talk.js
index e429bb2..2aac3e3 100644
--- a/speech/talk.js
+++ b/speech/talk.js
@@ -51,6 +51,7 @@
 		}
 	}
 	let keepAlive = false;
+	const ancestor = [];
 	const names = [];
 	let aliveTimer = -1;
 	function startRec() {
@@ -150,7 +151,7 @@
 		speechStat = '';
 		let txt = transcript.toLowerCase();
 		if (txt.length>0) {
-			const tok = txt.split(' ')[0];
+			let tok = txt.split(' ')[0];
 			if (locale[lang].open.indexOf(tok)>-1) {
 				mode = 'open';
 				$('#search').hide();
@@ -170,7 +171,7 @@
 							window.openData.push(rlocale[i]);
 						}
 					}
-					$('#openTable').html('<tr><td>'+txt+'</td><td><input id="oname" class="oname"></input></td><td><button class="btn btn-primary" onClick="findPanel($(\"#oname\").val)">'+locale[lang].searchSubmit+'</button></td></tr>');
+					$('#openTable').html('<tr><td>'+txt+'</td><td><input id="oname" class="oname"></input></td><td><button class="btn btn-primary" onClick="mode=null">CANCEL</button></td></tr>');
 					$(function() {$(".oname").autocomplete({source: launcher, select: function(event, ui) {findPanel(ui.item.value, txt); return false;}});});
 					window.openData.push(txt);								
 					showLog('window.openData1');
@@ -217,7 +218,7 @@
 				txt = txt.replace(tok+' ', '').split(' ').join('_').split('.').join('_').split('-').join('_').toUpperCase();
 				const token = document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: '';
 				const snd = './talk.php?search='+txt+token+"&lang="+lang+"&speech="+tok;
-				$('#openTable').html('<tr><td colspan="5">' + locale[lang].searchCorrect + '</td></tr><tr><td>'+txt+'</td><td><input id="sname" class="sname"></input></td><td><button class="btn btn-primary" onClick="findComponent($(\"#sname\").val)">'+locale[lang].searchSubmit+'</button></td></tr>');
+				$('#openTable').html('<tr><td colspan="5">' + locale[lang].searchCorrect + '</td></tr><tr><td>'+txt+'</td><td><input id="sname" class="sname" size="10"></input></td><td><button class="btn btn-primary" onClick="mode=null">CANCEL</button></td></tr>');
 				$(function() {$(".sname").autocomplete({source: names, select: function(event, ui) {findComponent(ui.item.value, txt); return false;}});});
 				showLog(snd);
 				fetch(snd).then((response) => {return response.text();}).then((rlocale) => {
@@ -227,6 +228,28 @@
 				// mode = '';
 				// $('#search').hide(); $('#open').hide();
 			}
+			if (locale[lang].ujive.indexOf(tok)>-1) {
+				const token = document.location.search.indexOf('token=')>-1? '&token='+document.location.search.split('token=')[1].split('&')[0]: (document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: '');
+				const snd = './talk.php?search=ujive'+token+"&lang="+lang;
+				showLog('ujive');
+				showLog(snd);
+				fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);});
+				mode = 'ujive';
+				ancestor.length = 0;
+				txt = txt.replace(tok, '').replace(' ', '');
+			}
+			if (mode=='ujive') {
+				showLog('ujive: '+tok);
+				if (!isNaN(tok)) {ancestor.push(tok); tok = 'n'+ancestor.join('_');}
+				if (locale[lang].back.indexOf(tok)>-1) ancestor.pop();
+				if (locale[lang].up.indexOf(tok)>-1) tok = 'up';
+				if (locale[lang].down.indexOf(tok)>-1) tok = 'down';
+				const token = document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: '';
+				const snd = './talk.php?ctree='+tok+token;
+				fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);});
+				mode = '';
+				$('#search').hide(); $('#open').hide();
+			}
 			if (locale[lang].list.indexOf(tok)>-1) {
 				mode = 'list';
 				txt = txt.replace(tok, '').replace(' ', '');
@@ -252,6 +275,7 @@
 		fetch(snd).then((response) => {return response.text();}).then((rlocale) => {showLog(rlocale); /*alert(rlocale);*/});
 	}
 	function findComponent(txt, speech) {
+		if (locale[lang].open.indexOf(txt)>-1) return;
 		showLog(txt);
 		showLog(speech);
 		const token = document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: '';
-- 
GitLab