assign/remove to label rpc: use JSON
This commit is contained in:
parent
2cd992574a
commit
8eb592ec71
|
@ -533,41 +533,10 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subop == "removeFromLabel") {
|
if ($subop == "assignToLabel" || $subop == "removeFromLabel") {
|
||||||
|
header("Content-Type: text/plain");
|
||||||
|
|
||||||
$ids = explode(",", db_escape_string($_REQUEST["ids"]));
|
$reply = array();
|
||||||
$label_id = db_escape_string($_REQUEST["lid"]);
|
|
||||||
|
|
||||||
$label = db_escape_string(label_find_caption($link, $label_id,
|
|
||||||
$_SESSION["uid"]));
|
|
||||||
|
|
||||||
print "<rpc-reply>";
|
|
||||||
print "<info-for-headlines>";
|
|
||||||
|
|
||||||
if ($label) {
|
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
label_remove_article($link, $id, $label, $_SESSION["uid"]);
|
|
||||||
|
|
||||||
print "<entry id=\"$id\"><![CDATA[";
|
|
||||||
|
|
||||||
$labels = get_article_labels($link, $id, $_SESSION["uid"]);
|
|
||||||
print format_article_labels($labels, $id);
|
|
||||||
|
|
||||||
print "]]></entry>";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print "</info-for-headlines>";
|
|
||||||
|
|
||||||
print "<message>UPDATE_COUNTERS</message>";
|
|
||||||
print "</rpc-reply>";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($subop == "assignToLabel") {
|
|
||||||
|
|
||||||
$ids = split(",", db_escape_string($_REQUEST["ids"]));
|
$ids = split(",", db_escape_string($_REQUEST["ids"]));
|
||||||
$label_id = db_escape_string($_REQUEST["lid"]);
|
$label_id = db_escape_string($_REQUEST["lid"]);
|
||||||
|
@ -575,29 +544,28 @@
|
||||||
$label = db_escape_string(label_find_caption($link, $label_id,
|
$label = db_escape_string(label_find_caption($link, $label_id,
|
||||||
$_SESSION["uid"]));
|
$_SESSION["uid"]));
|
||||||
|
|
||||||
print "<rpc-reply>";
|
$reply["info-for-headlines"] = array();
|
||||||
|
|
||||||
print "<info-for-headlines>";
|
|
||||||
|
|
||||||
if ($label) {
|
if ($label) {
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
label_add_article($link, $id, $label, $_SESSION["uid"]);
|
|
||||||
|
|
||||||
print "<entry id=\"$id\"><![CDATA[";
|
if ($subop == "assignToLabel")
|
||||||
|
label_add_article($link, $id, $label, $_SESSION["uid"]);
|
||||||
|
else
|
||||||
|
label_remove_article($link, $id, $label, $_SESSION["uid"]);
|
||||||
|
|
||||||
$labels = get_article_labels($link, $id, $_SESSION["uid"]);
|
$labels = get_article_labels($link, $id, $_SESSION["uid"]);
|
||||||
print format_article_labels($labels, $id);
|
|
||||||
|
|
||||||
print "]]></entry>";
|
array_push($reply["info-for-headlines"],
|
||||||
|
array("id" => $id, "labels" => format_article_labels($labels, $id)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</info-for-headlines>";
|
$reply["message"] = "UPDATE_COUNTERS";
|
||||||
|
|
||||||
print "<message>UPDATE_COUNTERS</message>";
|
print json_encode($reply);
|
||||||
print "</rpc-reply>";
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
28
viewfeed.js
28
viewfeed.js
|
@ -683,8 +683,8 @@ function selectionRemoveLabel(id, ids) {
|
||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
parameters: query,
|
parameters: query,
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
|
handle_rpc_json(transport);
|
||||||
show_labels_in_headlines(transport);
|
show_labels_in_headlines(transport);
|
||||||
handle_rpc_reply(transport);
|
|
||||||
} });
|
} });
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
@ -721,8 +721,8 @@ function selectionAssignLabel(id, ids) {
|
||||||
new Ajax.Request("backend.php", {
|
new Ajax.Request("backend.php", {
|
||||||
parameters: query,
|
parameters: query,
|
||||||
onComplete: function(transport) {
|
onComplete: function(transport) {
|
||||||
|
handle_rpc_json(transport);
|
||||||
show_labels_in_headlines(transport);
|
show_labels_in_headlines(transport);
|
||||||
handle_rpc_reply(transport);
|
|
||||||
} });
|
} });
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
@ -1776,29 +1776,17 @@ function scrollArticle(offset) {
|
||||||
|
|
||||||
function show_labels_in_headlines(transport) {
|
function show_labels_in_headlines(transport) {
|
||||||
try {
|
try {
|
||||||
if (transport.responseXML) {
|
var data = JSON.parse(transport.responseText);
|
||||||
var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
|
|
||||||
|
|
||||||
var elems = info.getElementsByTagName("entry");
|
if (data) {
|
||||||
|
data['info-for-headlines'].each(function(elem) {
|
||||||
for (var l = 0; l < elems.length; l++) {
|
var ctr = $("HLLCTR-" + elem.id);
|
||||||
var e_id = elems[l].getAttribute("id");
|
|
||||||
|
|
||||||
if (e_id) {
|
|
||||||
|
|
||||||
var ctr = $("HLLCTR-" + e_id);
|
|
||||||
|
|
||||||
if (ctr) {
|
|
||||||
ctr.innerHTML = elems[l].firstChild.nodeValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (ctr) ctr.innerHTML = elem.labels;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exception_error("show_labels_in_headlines", e);
|
exception_error("show_labels_in_headlines", e);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue