Connect npc view to backend
This commit is contained in:
parent
55018c90bb
commit
ccac9c302c
@ -25,6 +25,7 @@ def npc(npc_id):
|
||||
npc_answers.append(answer_list)
|
||||
|
||||
npc_dict = {
|
||||
"id": npc_obj.NPC_ID,
|
||||
"name": npc_obj.LOCALE.TEXTS[0].TEXT,
|
||||
"img": npc_obj.NPC_ID,
|
||||
"answers": npc_answers,
|
||||
|
@ -122,3 +122,27 @@ def set_places():
|
||||
db.session.commit()
|
||||
|
||||
return {"error": 0}
|
||||
|
||||
@routes_api_admin.route("/setNpc", methods=["GET", "POST"])
|
||||
def set_npc():
|
||||
input_lang = flask.request.json["lang"]
|
||||
input_npc = flask.request.json["npc"]
|
||||
|
||||
if input_npc["id"] == None:
|
||||
npc_obj = Npc(None, None)
|
||||
db.session.add(npc_obj)
|
||||
else:
|
||||
npc_obj = db.session.get(Npc, input_npc["id"])
|
||||
|
||||
npc_obj.LOCALE.get_text(input_lang, True).TEXT = input_npc["name"]
|
||||
|
||||
for answer_type, input_answer_type in zip(npc_obj.ANSWERS, input_npc["allAnswers"]):
|
||||
for text in answer_type.LOCALE.get_texts(input_lang):
|
||||
db.session.delete(text)
|
||||
for input_answer in input_answer_type["answers"]:
|
||||
answer_type.LOCALE.TEXTS.append(Text(None, None, input_lang, input_answer["text"]))
|
||||
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return {"error": 0}
|
@ -92,3 +92,27 @@ function changeLang(){
|
||||
|
||||
}
|
||||
|
||||
//functions for npc.html
|
||||
|
||||
function saveFormNpc(){
|
||||
let data = {}
|
||||
|
||||
data["id"] = npc.querySelector("#npc_id").value;
|
||||
data["name"] = npc.querySelector("#npc_name").value;
|
||||
|
||||
let allAnswersJson = [];
|
||||
data["allAnswers"] = allAnswersJson;
|
||||
|
||||
for(let answerTypeNode of npc.querySelectorAll(".answerType")){
|
||||
let answersJson = [];
|
||||
let answerTypeJson = {"answers": answersJson};
|
||||
allAnswersJson.push(answerTypeJson);
|
||||
|
||||
for(let answerNode of answerTypeNode.querySelectorAll("input")){
|
||||
answersJson.push({"text": answerNode.value})
|
||||
}
|
||||
}
|
||||
|
||||
makeAPIRequest("admin/setNpc", {"npc": data, "lang": "FR"}, {"content": "json"})
|
||||
}
|
||||
|
||||
|
@ -4,26 +4,32 @@
|
||||
<title>NPC</title>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/css/admin_ui.css">
|
||||
<script src="/static/js/api.js"></script>
|
||||
<script src="/static/js/admin.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/admin"> go Back </a> <br>
|
||||
|
||||
<section>
|
||||
<span>Npc name: </span>
|
||||
<input value="{{ npc.get('name') or ''}}">
|
||||
<img href="{{npc.get('img')}}">
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<p>Answers:</p>
|
||||
{%for answer_type in npc.get("answers") or []%}
|
||||
<section id="npc">
|
||||
<section>
|
||||
{%for answer in answer_type%}
|
||||
<input value="{{answer}}">
|
||||
<span>Npc name: </span>
|
||||
<input id="npc_id" value="{{ npc.get('id') or ''}}" hidden>
|
||||
<input id="npc_name" value="{{ npc.get('name') or ''}}">
|
||||
<img href="{{npc.get('img')}}">
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<p>Answers:</p>
|
||||
{%for answer_type in npc.get("answers") or []%}
|
||||
<section class="answerType">
|
||||
{%for answer in answer_type%}
|
||||
<input value="{{answer}}">
|
||||
{%endfor%}
|
||||
</section>
|
||||
{%endfor%}
|
||||
</section>
|
||||
{%endfor%}
|
||||
</section>
|
||||
|
||||
<button onclick="saveFormNpc()">Save changes</button>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user