Commit 5baf8603 by pupi1985

Use DOM updates controlled by the backend

parent ac8b85cb
......@@ -112,6 +112,27 @@ function qa_mailing_start(noteid, pauseid)
);
}
function qa_update_dom(response)
{
if (!response.hasOwnProperty('domUpdates')) {
return;
}
for (var i = 0; i < response.domUpdates.length; i++) {
var domUpdate = response.domUpdates[i];
switch (domUpdate.action) {
case 'conceal':
qa_conceal(document.querySelector(domUpdate.selector));
break;
case 'reveal':
qa_reveal(document.querySelector(domUpdate.selector));
break;
default: // replace
$(domUpdate.selector).html(domUpdate.html);
}
}
}
function qa_admin_click(target)
{
var p = target.name.split('_');
......@@ -121,12 +142,9 @@ function qa_admin_click(target)
qa_ajax_post('click_admin', params,
function (response) {
if (response.hideEntitySelector !== null) {
qa_conceal(document.getElementById('p' + params.entityid), 'admin');
$('.qa-nav-sub-counter-' + response.hideEntitySelector).text(response.entityCount);
}
qa_update_dom(response);
if (response.result !== 'success') {
if (response.result === 'error' && response.error.severity === 'fatal') {
alert(response.error.message);
}
......
......@@ -52,4 +52,3 @@ switch ($version) {
else
echo "QA_AJAX_RESPONSE\n0\n" . qa_lang('main/general_error');
}
......@@ -602,19 +602,25 @@ function qa_admin_single_click_array($entityid, $action)
if (isset($useraccount) && qa_get_logged_in_level() >= QA_USER_LEVEL_MODERATOR) {
switch ($action) {
case 'userapprove':
$response['entityCount'] = (int)qa_opt('cache_uapprovecount');
if ($useraccount['level'] >= QA_USER_LEVEL_APPROVED) { // don't demote higher level users
$response['result'] = 'error';
$response['error']['type'] = 'user-already-approved';
$response['error']['message'] = qa_lang_html('main/general_error');
$response['hideEntitySelector'] = null;
} else {
require_once QA_INCLUDE_DIR . 'app/users-edit.php';
qa_set_user_level($useraccount['userid'], $useraccount['handle'], QA_USER_LEVEL_APPROVED, $useraccount['level']);
$response['result'] = 'success';
$response['entityCount'] = max($response['entityCount'] - 1, 0);
$response['hideEntitySelector'] = 'approve';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-approve',
'html' => max((int)qa_opt('cache_uapprovecount') - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
}
break;
......@@ -623,8 +629,16 @@ function qa_admin_single_click_array($entityid, $action)
qa_set_user_blocked($useraccount['userid'], $useraccount['handle'], true);
$response['result'] = 'success';
$response['entityCount'] = max((int)qa_opt('cache_uapprovecount') - 1, 0);
$response['hideEntitySelector'] = 'approve';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-approve',
'html' => max((int)qa_opt('cache_uapprovecount') - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
break;
default:
......@@ -641,18 +655,26 @@ function qa_admin_single_click_array($entityid, $action)
switch ($action) {
case 'approve':
case 'reject':
$response['entityCount'] = (int)qa_opt('cache_queuedcount');
$entityCount = (int)qa_opt('cache_queuedcount');
if (!$queued) {
$response['result'] = 'error';
$response['error']['type'] = 'post-not-queued';
$response['error']['message'] = qa_lang_html('main/general_error');
$response['entityCount'] = max($response['entityCount'] - 1, 0);
$response['hideEntitySelector'] = 'moderate';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-moderate',
'html' => max($entityCount - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
} elseif (qa_user_post_permit_error('permit_moderate', $post) !== false) {
$response['result'] = 'error';
$response['error']['type'] = 'no-permission';
$response['error']['message'] = qa_lang_html('users/no_permission');
$response['hideEntitySelector'] = null;
$response['error']['severity'] = 'fatal';
} else {
$postStatus = $action === 'approve'
? QA_POST_STATUS_NORMAL
......@@ -660,8 +682,16 @@ function qa_admin_single_click_array($entityid, $action)
qa_post_set_status($entityid, $postStatus, $userid);
$response['result'] = 'success';
$response['entityCount'] = max($response['entityCount'] - 1, 0);
$response['hideEntitySelector'] = 'moderate';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-moderate',
'html' => max($entityCount - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
}
break;
......@@ -671,12 +701,17 @@ function qa_admin_single_click_array($entityid, $action)
$response['result'] = 'error';
$response['error']['type'] = 'post-not-hidden';
$response['error']['message'] = qa_lang_html('main/general_error');
$response['hideEntitySelector'] = 'hidden';
$response['domUpdates'] = array(
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
} elseif (qa_user_post_permit_error('permit_hide_show', $post) !== false) {
$response['result'] = 'error';
$response['error']['type'] = 'no-permission';
$response['error']['message'] = qa_lang_html('users/no_permission');
$response['hideEntitySelector'] = null;
$response['error']['severity'] = 'fatal';
} else {
if ($action === 'reshow') {
qa_post_set_status($entityid, QA_POST_STATUS_NORMAL, $userid);
......@@ -685,24 +720,37 @@ function qa_admin_single_click_array($entityid, $action)
}
$response['result'] = 'success';
$response['hideEntitySelector'] = 'hidden';
$response['domUpdates'] = array(
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
}
break;
case 'hide':
case 'clearflags':
$response['entityCount'] = (int)qa_opt('cache_flaggedcount');
$entityCount = (int)qa_opt('cache_flaggedcount');
if ($action === 'hide' && $queued) {
$response['result'] = 'error';
$response['error']['type'] = 'post-queued';
$response['error']['message'] = qa_lang_html('main/general_error');
$response['entityCount'] = max($response['entityCount'] - 1, 0);
$response['hideEntitySelector'] = 'flagged';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-flagged',
'html' => max($entityCount - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
} elseif (qa_user_post_permit_error('permit_hide_show', $post) !== false) {
$response['result'] = 'error';
$response['error']['type'] = 'no-permission';
$response['error']['message'] = qa_lang_html('users/no_permission');
$response['hideEntitySelector'] = null;
$response['error']['severity'] = 'fatal';
} else {
if ($action === 'hide') {
qa_post_set_status($entityid, QA_POST_STATUS_HIDDEN, $userid);
......@@ -713,8 +761,16 @@ function qa_admin_single_click_array($entityid, $action)
}
$response['result'] = 'success';
$response['entityCount'] = max($response['entityCount'] - 1, 0);
$response['hideEntitySelector'] = 'flagged';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-flagged',
'html' => max($entityCount - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
);
}
break;
......
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