Commit 21d10429 by pupi1985

Recalc now returns JSON

parent 47d76b73
...@@ -56,28 +56,21 @@ function qa_recalc_update(elem, state, noteid) ...@@ -56,28 +56,21 @@ function qa_recalc_update(elem, state, noteid)
{ {
if (state) { if (state) {
var recalcCode = elem.form.elements.code_recalc ? elem.form.elements.code_recalc.value : elem.form.elements.code.value; var recalcCode = elem.form.elements.code_recalc ? elem.form.elements.code_recalc.value : elem.form.elements.code.value;
qa_ajax_post( qa_ajax_post(
'recalc', 'recalc',
{state: state, code: recalcCode}, {state: state, code: recalcCode},
function(lines) { function (response) {
if (lines[0] == '1') { if (response.message) {
if (lines[2]) document.getElementById(noteid).innerHTML = response.message;
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);
} else { if (elem.qa_recalc_stopped) {
qa_ajax_error();
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
} else {
qa_recalc_update(elem, response.state, noteid);
} }
} }, 1
); );
} else { } else {
qa_recalc_cleanup(elem); qa_recalc_cleanup(elem);
......
...@@ -26,7 +26,6 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { ...@@ -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'))) { if (!qa_check_form_security_code('admin/recalc', qa_post_text('code'))) {
$state = ''; $state = '';
$message = qa_lang('misc/form_security_reload'); $message = qa_lang('misc/form_security_reload');
} else { } else {
$recalc = new \Q2A\Recalc\RecalcMain(qa_post_text('state')); $recalc = new \Q2A\Recalc\RecalcMain(qa_post_text('state'));
$stoptime = time() + 3; $stoptime = time() + 3;
...@@ -37,13 +36,15 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { ...@@ -37,13 +36,15 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$message = $recalc->getMessage(); $message = $recalc->getMessage();
$state = $recalc->getState(); $state = $recalc->getState();
} }
} else { } else {
$state = ''; $state = '';
$message = qa_lang('admin/no_privileges'); $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