Safe ID getting, question xhttp get refactor

This commit is contained in:
MrFry 2020-01-27 09:46:09 +01:00
parent 7d4dbe4eb6
commit c750261b12

View file

@ -62,7 +62,7 @@
// forcing pages for testing. unless you test, do not set these to true! // forcing pages for testing. unless you test, do not set these to true!
// only one of these should be true for testing // only one of these should be true for testing
const forceTestPage = true const forceTestPage = false
const forceResultPage = false const forceResultPage = false
const forceDefaultPage = false const forceDefaultPage = false
const logElementGetting = false const logElementGetting = false
@ -963,6 +963,7 @@
function ShowSaveQuizDialog (sendResult, sentData, newQuestions) { function ShowSaveQuizDialog (sendResult, sentData, newQuestions) {
// FIXME: normal string building with localisation :/ // FIXME: normal string building with localisation :/
var msg = '' var msg = ''
// TODO: '0 új kérdés'
if (sendResult) { if (sendResult) {
msg = 'Kérdések elküldve, katt az elküldött adatokért. ' + newQuestions + ' új kérdés' msg = 'Kérdések elküldve, katt az elküldött adatokért. ' + newQuestions + ' új kérdés'
} else { } else {
@ -1605,10 +1606,10 @@
} }
} }
function SafeGetElementById (id, todo) { function SafeGetElementById (id, next) {
let element = document.getElementById(id) let element = document.getElementById(id)
if (element) { if (element) {
todo(element) next(element)
} else { } else {
Log(`Unable to safe get element by id: ${id}`) Log(`Unable to safe get element by id: ${id}`)
} }
@ -1662,7 +1663,20 @@
url: url, url: url,
onload: function (response) { onload: function (response) {
try { try {
resolve(JSON.parse(response.responseText)) let res = JSON.parse(response.responseText)
// FIXME: check if res is a valid answer array
// res.json({
// result: r,
// success: true
// })
// ERROR:
// res.json({
// message: `Invalid question :(`,
// result: [],
// recievedData: JSON.stringify(req.query),
// success: false
// })
resolve(res.result)
} catch (e) { } catch (e) {
reject(new Error('json parse error')) reject(new Error('json parse error'))
} }