mirror of
				https://github.com/HendrikRauh/dmx-interface.git
				synced 2025-11-04 00:41:02 +00:00 
			
		
		
		
	added script for loading the config
This commit is contained in:
		
							parent
							
								
									552cf376a0
								
							
						
					
					
						commit
						115442f91e
					
				
					 2 changed files with 36 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
        <title>Konfiguration</title>
 | 
			
		||||
        <link rel="stylesheet" href="/style.css" />
 | 
			
		||||
        <script type="module" src="/input-visibility.js" defer></script>
 | 
			
		||||
        <script type="module" src="/load-data.js" defer></script>
 | 
			
		||||
        <script type="module" src="/submit.js" defer></script>
 | 
			
		||||
    </head>
 | 
			
		||||
    <body>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										35
									
								
								data/load-data.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								data/load-data.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
const form = document.querySelector("form");
 | 
			
		||||
 | 
			
		||||
async function loadData() {
 | 
			
		||||
    try {
 | 
			
		||||
        const req = await fetch("/config", {
 | 
			
		||||
            method: "GET",
 | 
			
		||||
        });
 | 
			
		||||
        if (!req.ok) {
 | 
			
		||||
            throw new Error(`Response status: ${req.status}`);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const json = await req.json();
 | 
			
		||||
        console.log(json);
 | 
			
		||||
        return json;
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        console.log(error);
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function writeDataToInput(data) {
 | 
			
		||||
    console.log("write data", typeof data);
 | 
			
		||||
    for (const [key, value] of Object.entries(data)) {
 | 
			
		||||
        const element = document.querySelector(`[name=${key}]`);
 | 
			
		||||
        console.log(element);
 | 
			
		||||
        element.value = value;
 | 
			
		||||
    }
 | 
			
		||||
    // send "change" event
 | 
			
		||||
    form.dispatchEvent(new Event("change", { bubbles: true }));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const data = await loadData();
 | 
			
		||||
if (data !== null) {
 | 
			
		||||
    writeDataToInput(data);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue