From 8eb592ec71c27c740fb3339e1e2a413fce6613f7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 29 Nov 2010 14:11:54 +0300 Subject: [PATCH] assign/remove to label rpc: use JSON --- modules/backend-rpc.php | 58 +++++++++-------------------------------- viewfeed.js | 28 ++++++-------------- 2 files changed, 21 insertions(+), 65 deletions(-) diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php index 59faee7b..e027ff39 100644 --- a/modules/backend-rpc.php +++ b/modules/backend-rpc.php @@ -533,41 +533,10 @@ return; } - if ($subop == "removeFromLabel") { - - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $label_id = db_escape_string($_REQUEST["lid"]); - - $label = db_escape_string(label_find_caption($link, $label_id, - $_SESSION["uid"])); - - print ""; - print ""; - - if ($label) { - - foreach ($ids as $id) { - label_remove_article($link, $id, $label, $_SESSION["uid"]); - - print ""; - - } - } - - print ""; - - print "UPDATE_COUNTERS"; - print ""; - - return; - } + if ($subop == "assignToLabel" || $subop == "removeFromLabel") { + header("Content-Type: text/plain"); - if ($subop == "assignToLabel") { + $reply = array(); $ids = split(",", db_escape_string($_REQUEST["ids"])); $label_id = db_escape_string($_REQUEST["lid"]); @@ -575,29 +544,28 @@ $label = db_escape_string(label_find_caption($link, $label_id, $_SESSION["uid"])); - print ""; - - print ""; + $reply["info-for-headlines"] = array(); if ($label) { foreach ($ids as $id) { - label_add_article($link, $id, $label, $_SESSION["uid"]); - print ""; + + array_push($reply["info-for-headlines"], + array("id" => $id, "labels" => format_article_labels($labels, $id))); } } - print ""; + $reply["message"] = "UPDATE_COUNTERS"; - print "UPDATE_COUNTERS"; - print ""; + print json_encode($reply); return; } diff --git a/viewfeed.js b/viewfeed.js index f36c75b4..22523fa1 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -683,8 +683,8 @@ function selectionRemoveLabel(id, ids) { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { + handle_rpc_json(transport); show_labels_in_headlines(transport); - handle_rpc_reply(transport); } }); // } @@ -721,8 +721,8 @@ function selectionAssignLabel(id, ids) { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { + handle_rpc_json(transport); show_labels_in_headlines(transport); - handle_rpc_reply(transport); } }); // } @@ -1776,29 +1776,17 @@ function scrollArticle(offset) { function show_labels_in_headlines(transport) { try { - if (transport.responseXML) { - var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0]; - - var elems = info.getElementsByTagName("entry"); - - for (var l = 0; l < elems.length; l++) { - var e_id = elems[l].getAttribute("id"); - - if (e_id) { + var data = JSON.parse(transport.responseText); - var ctr = $("HLLCTR-" + e_id); - - if (ctr) { - ctr.innerHTML = elems[l].firstChild.nodeValue; - } - } - - } + if (data) { + data['info-for-headlines'].each(function(elem) { + var ctr = $("HLLCTR-" + elem.id); + if (ctr) ctr.innerHTML = elem.labels; + }); } } catch (e) { exception_error("show_labels_in_headlines", e); - } } -- 2.39.5