mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Safe ID getting, question xhttp get refactor
This commit is contained in:
parent
7d4dbe4eb6
commit
c750261b12
1 changed files with 18 additions and 4 deletions
|
@ -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'))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue