Commit 21d10429 by pupi1985

Recalc now returns JSON

parent 47d76b73
......@@ -56,28 +56,21 @@ function qa_recalc_update(elem, state, noteid)
{
if (state) {
var recalcCode = elem.form.elements.code_recalc ? elem.form.elements.code_recalc.value : elem.form.elements.code.value;
qa_ajax_post(
'recalc',
{state: state, code: recalcCode},
function(lines) {
if (lines[0] == '1') {
if (lines[2])
document.getElementById(noteid).innerHTML = lines[2];
if (elem.qa_recalc_stopped)
qa_recalc_cleanup(elem);
else
qa_recalc_update(elem, lines[1], noteid);
} else if (lines[0] == '0') {
document.getElementById(noteid).innerHTML = lines[1];
qa_recalc_cleanup(elem);
function (response) {
if (response.message) {
document.getElementById(noteid).innerHTML = response.message;
}
} else {
qa_ajax_error();
if (elem.qa_recalc_stopped) {
qa_recalc_cleanup(elem);
} else {
qa_recalc_update(elem, response.state, noteid);
}
}
}, 1
);
} else {
qa_recalc_cleanup(elem);
......
......@@ -26,7 +26,6 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
if (!qa_check_form_security_code('admin/recalc', qa_post_text('code'))) {
$state = '';
$message = qa_lang('misc/form_security_reload');
} else {
$recalc = new \Q2A\Recalc\RecalcMain(qa_post_text('state'));
$stoptime = time() + 3;
......@@ -37,13 +36,15 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$message = $recalc->getMessage();
$state = $recalc->getState();
}
} else {
$state = '';
$message = qa_lang('admin/no_privileges');
}
$response = array(
'state' => $state,
'message' => qa_html($message),
);
echo "QA_AJAX_RESPONSE\n1\n" . $state . "\n" . qa_html($message);
echo json_encode($response);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment