95 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <a href="/admin"> go Back </a> <br>
 | |
| 
 | |
| <select id="langs" onchange="langChangedEvent()">
 | |
|     {%for lang in langs%}
 | |
|     <option value="{{lang}}">{{lang}}</option>
 | |
|     {%endfor%}
 | |
| </select>
 | |
| 
 | |
| 
 | |
| <form id="questionsTag" action="javascript:void(0);">
 | |
| </form>
 | |
| 
 | |
| <button onclick="saveForm()"> Save changes </button>
 | |
| 
 | |
| <style>
 | |
|     .questionTypeTag{
 | |
|         border: thin solid red;
 | |
|         margin-top: 20px;
 | |
|     }
 | |
|     .questionTypeTag input{
 | |
|         width: 100%;
 | |
|     }
 | |
| </style>
 | |
| 
 | |
| <script src="/static/js/api.js"></script>
 | |
| <script>
 | |
| 
 | |
| 
 | |
|     let lang = null;
 | |
| 
 | |
|     function saveForm(){
 | |
|         var formData = new FormData(questionsTag);
 | |
|         let questionsJson = [];
 | |
| 
 | |
|         for(let questionTypeTag of questionsTag.querySelectorAll("fieldset")){
 | |
|             let questionTypeJson = [];
 | |
|             questionsJson.push(questionTypeJson);
 | |
| 
 | |
|             for(let questionTag of questionTypeTag.children){
 | |
|                 questionTypeJson.push({"text": questionTag.value})
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         if(lang!==null){
 | |
|             makeAPIRequest("admin/setQuestions", {"questions": questionsJson, "lang": lang}, {"content": "json"})
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     let lastQueriedData = [];
 | |
| 
 | |
|     async function changeLang(newLang){
 | |
|         lang = null;
 | |
| 
 | |
|         console.log("Changing language to "+newLang);
 | |
|         resp = await makeAPIRequest("admin/getQuestions", {"lang": newLang});
 | |
| 
 | |
|         questionsTag.innerHTML = '';
 | |
| 
 | |
|         for(let questionType of resp){
 | |
|             
 | |
|             let questionTypeTag = document.createElement("fieldset")
 | |
|             questionTypeTag.className = 'questionTypeTag';
 | |
|             questionsTag.appendChild(questionTypeTag);
 | |
| 
 | |
| 
 | |
| 
 | |
|             function addNewInput(value=""){
 | |
|                 let questionTag = document.createElement("input");
 | |
|                 questionTypeTag.appendChild(questionTag);
 | |
| 
 | |
|                 questionTag.value = value;
 | |
|             }
 | |
|             
 | |
|             for(let question of questionType){
 | |
|                 addNewInput(question.text);
 | |
|             }
 | |
|             
 | |
|             let addNewTag = document.createElement("input")
 | |
|             addNewTag.type = 'button'
 | |
|             addNewTag.value = "Add new";
 | |
|             addNewTag.onclick = () => addNewInput();
 | |
|             questionsTag.appendChild(addNewTag);
 | |
|         }
 | |
| 
 | |
|         lang = newLang;
 | |
|     }
 | |
| 
 | |
|     function langChangedEvent(){
 | |
|         changeLang(langs.value)
 | |
|     }
 | |
| 
 | |
|     changeLang(langs.value);
 | |
| 
 | |
| </script>
 |