From ede7a45ae58082e586f9efa57cf6d8eb3a43393f Mon Sep 17 00:00:00 2001 From: Cazals Mathias Date: Mon, 20 Mar 2023 16:02:52 +0100 Subject: [PATCH] update questions file in for admin --- truthinquiry/static/css/admin_ui.css | 8 ++ truthinquiry/static/js/admin.js | 43 +++++++- truthinquiry/templates/admin/questions.html | 105 +++++++------------- 3 files changed, 84 insertions(+), 72 deletions(-) diff --git a/truthinquiry/static/css/admin_ui.css b/truthinquiry/static/css/admin_ui.css index 6c07f09..b38fcc6 100644 --- a/truthinquiry/static/css/admin_ui.css +++ b/truthinquiry/static/css/admin_ui.css @@ -16,3 +16,11 @@ width: 100%; } + .questionType{ + border: thin solid red; + margin-top: 20px; + } + .question input{ + width: 100%; + margin: 10px; + } diff --git a/truthinquiry/static/js/admin.js b/truthinquiry/static/js/admin.js index fb1b34c..1923bd7 100644 --- a/truthinquiry/static/js/admin.js +++ b/truthinquiry/static/js/admin.js @@ -50,4 +50,45 @@ function saveFormTraits(){ data.push(trait); } makeAPIRequest("admin/setTraits", {"traits": data, "lang": "FR"}, {"content": "json"}) -} \ No newline at end of file +} + + + +//functions for questions.html + + + + +function addEntry(button){ + let questionTypeContent = button.parentNode.querySelector(".questionTypeContent"); + let newQuestion = questionTypeContent.querySelector(".question").cloneNode(true); + newQuestion.id = ""; + newQuestion.querySelector("input").value = ""; + questionTypeContent.appendChild(newQuestion); +} + +function deleteEntry(buttonNode){ + let placeNode = buttonNode.parentNode; + placeNode.parentNode.removeChild(placeNode); +} + +function saveFormQuestions(){ + let data = []; + + for(let questionTypeNode of allQuestions.querySelectorAll(".questionType")){ + let questionsJson = []; + let questionTypeJson = {"questions": questionsJson}; + data.push(questionTypeJson); + + for(let questionNode of questionTypeNode.querySelectorAll("input")){ + questionsJson.push({"text": questionNode.value}) + } + } + + makeAPIRequest("admin/setQuestions", {"questions": data, "lang": "FR"}, {"content": "json"}) +} + +function changeLang(){ + +} + diff --git a/truthinquiry/templates/admin/questions.html b/truthinquiry/templates/admin/questions.html index 0e85c4e..022392c 100644 --- a/truthinquiry/templates/admin/questions.html +++ b/truthinquiry/templates/admin/questions.html @@ -1,78 +1,41 @@ - go Back
+ + + + Admin Page + + + + + + > + + go Back
- + -
- {%for questionType in questions%} -
-
- {%for question in questionType["questions"]%} -
- - -
+
+ {%for questionType in questions%} +
+
+ {%for question in questionType["questions"]%} +
+ + +
+ {%endfor%} +
+ +
{%endfor%}
- -
- {%endfor%} -
-
+
- - - - - - + + +