add setQuestions endpoint and access it from js
This commit is contained in:
parent
25eeae34ba
commit
04be0b641e
@ -34,3 +34,11 @@ def get_questions():
|
|||||||
data[-1].append({"text": locale.TEXT})
|
data[-1].append({"text": locale.TEXT})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@routes_api_admin.route("/setQuestions", methods=["GET", "POST"])
|
||||||
|
def set_questions():
|
||||||
|
if not flask.request.json:
|
||||||
|
return {"error": 1, "msg": "no json set"}
|
||||||
|
lang = flask.request.json["lang"]
|
||||||
|
questions = flask.request.json["questions"]
|
||||||
|
return {"error": 0}
|
||||||
|
@ -6,24 +6,49 @@
|
|||||||
{%endfor%}
|
{%endfor%}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<section id="questionsTag">
|
<form id="questionsTag">
|
||||||
|
</form>
|
||||||
|
|
||||||
</section>
|
<button onclick="saveForm()"> Save changes </button>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.questionTypeTag{
|
.questionTypeTag{
|
||||||
border: thin solid red;
|
border: thin solid red;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
.questionTypeTag input{
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="/static/js/api.js"></script>
|
<script src="/static/js/api.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function save(){
|
let lang = null;
|
||||||
console.log("Saving")
|
|
||||||
|
function saveForm(){
|
||||||
|
var formData = new FormData(questionsTag);
|
||||||
|
let questionsJson = [];
|
||||||
|
|
||||||
|
for(let questionTypeTag of questionsTag.children){
|
||||||
|
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){
|
async function changeLang(newLang){
|
||||||
|
lang = null;
|
||||||
|
|
||||||
console.log("Changing language to "+newLang);
|
console.log("Changing language to "+newLang);
|
||||||
resp = await makeAPIRequest("admin/getQuestions", {"lang": newLang});
|
resp = await makeAPIRequest("admin/getQuestions", {"lang": newLang});
|
||||||
|
|
||||||
@ -31,21 +56,25 @@
|
|||||||
|
|
||||||
for(let questionType of resp){
|
for(let questionType of resp){
|
||||||
|
|
||||||
let questionTypeTag = document.createElement("section")
|
let questionTypeTag = document.createElement("fieldset")
|
||||||
questionTypeTag.className = 'questionTypeTag';
|
questionTypeTag.className = 'questionTypeTag';
|
||||||
questionsTag.appendChild(questionTypeTag);
|
questionsTag.appendChild(questionTypeTag);
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
for(let question of questionType){
|
for(let question of questionType){
|
||||||
let questionTag = document.createElement("h1");
|
let questionTag = document.createElement("input");
|
||||||
questionTypeTag.appendChild(questionTag);
|
questionTypeTag.appendChild(questionTag);
|
||||||
|
|
||||||
questionTag.innerHTML = question.text;
|
questionTag.value = question.text;
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lang = newLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
function langChangedEvent(){
|
function langChangedEvent(){
|
||||||
save();
|
|
||||||
changeLang(langs.value)
|
changeLang(langs.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user