Commit 5baf8603 by pupi1985

Use DOM updates controlled by the backend

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