28f7e7c96a09b51e6cc91a364fa18ae64e1c22c0
Christian Fraß [add] client

Christian Fraß authored 3 years ago

1) async function api_query
2) (
3) 	action_name,
4) 	input
5) )
6) {
7) 	const client = lib_comm.client_http_construct
8) 	(
9) 		{
10) 			"protocol": "http",
11) 			"host": "localhost",
12) 			"port": 7777,
13) 			"path": "/foo/bar",
14) 		}
15) 	);
16) 	const message = JSON.stringify
17) 	(
18) 		{
19) 			"action": action_name,
20) 			"input": input,
21) 		}
22) 	);
23) 	const answer = await lib_comm.client_http_send(client, message);
24) 	if (! (answer.code === 200))
25) 	{
26) 		return Promise.reject("server side error");
27) 	}
28) 	else
29) 	{
30) 		const output = JSON.parse(answer.text);
31) 		return Promise.resolve(output);
32) 	}
33) }
34) 
35) 
36) /**
37)  */
38) function main
39) (
40) )
41) {
Christian Fraß [mod] client:translate

Christian Fraß authored 3 years ago

42) 	// tabify
43) 	{
44) 		for (let dom_tab of document.querySelectorAll(".tab"))
Christian Fraß [add] client

Christian Fraß authored 3 years ago

45) 		{
Christian Fraß [mod] client:translate

Christian Fraß authored 3 years ago

46) 			for (let dom_tab_select of dom_tab.querySelectorAll(".tab-select li"))
Christian Fraß [add] client

Christian Fraß authored 3 years ago

47) 			{
Christian Fraß [mod] client:translate

Christian Fraß authored 3 years ago

48) 				dom_tab_select.addEventListener
49) 				(
50) 					"click",
51) 					(event) =>
52) 					{
53) 						const tab_name = dom_tab_select.getAttribute("rel");
54) 						dom_tab.setAttribute("rel", tab_name);
55) 					}
56) 				);
Christian Fraß [add] client

Christian Fraß authored 3 years ago

57) 			}
58) 		}
Christian Fraß [mod] client:translate

Christian Fraß authored 3 years ago

59) 	}
60) 	// show
61) 	{
62) 		document.querySelector(".tab-content[rel=\"show\"] button").addEventListener
63) 		(
64) 			"click",
65) 			async function ()
66) 			{
67) 				const concept_id = document.querySelector(".tab-content[rel=\"show\"] inupt").value;
68) 				const result = await api_query
69) 				(
70) 					"show",
71) 					{
72) 						"concept_id": concept_id,
73) 					}
74) 				);
75) 				let dom_result = document.querySelector("#show_result")
76) 				dom_result.textContent = JSON.stringify(result, undefined, "  ");
77) 			}
78) 		);
79) 	}
80) 	// translate
81) 	{
82) 		document.querySelector(".tab-content[rel=\"translate\"] button").addEventListener
83) 		(
84) 			"click",
85) 			async function ()
86) 			{
87) 				const language_from = document.querySelector(".tab-content[rel=\"translate\"] select[name=language_from]").value;
88) 				const language_to = document.querySelector(".tab-content[rel=\"translate\"] select[name=language_to]").value;
89) 				const token = document.querySelector(".tab-content[rel=\"translate\"] input[name=token]").value;
90) 				const result = await api_query
91) 				(
92) 					"translate",
93) 					{
94) 						"language_from": language_from,
95) 						"language_to": language_to,
96) 						"token": token,
97) 					}
98) 				);
99) 				const dom_ul = document.querySelector("#translate_result");
100) 				dom_ul.textContent = "";
101) 				for (const entry of result)
102) 				{
103) 					let dom_li = document.createElement("li");
104) 					dom_li.textContent = (`[${entry.language_from}] ${entry.value_from} ~ [${entry.language_to}] ${entry.value_to}`);
105) 					dom_ul.appendChild(dom_li);
106) 				}
107) 			}
108) 		);
109) 	}