From 29064218d07081fb1325102a380cd828704324f0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 31 Oct 2012 15:17:49 +0400 Subject: [PATCH] allow batch setting of article scores --- classes/feeds.php | 3 +++ classes/rpc.php | 4 ++-- js/viewfeed.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 1926d0c3..99d8efc7 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -45,6 +45,8 @@ class Feeds extends Handler_Protected { $tog_marked_link = "selectionToggleMarked()"; $tog_published_link = "selectionTogglePublished()"; + $set_score_link = "setSelectionScore()"; + if ($is_cat) $cat_q = "&is_cat=$is_cat"; if ($search) { @@ -107,6 +109,7 @@ class Feeds extends Handler_Protected { $reply .= ""; $reply .= ""; + $reply .= ""; if ($feed_id != "0") { $reply .= ""; diff --git a/classes/rpc.php b/classes/rpc.php index 88c6f1dd..98418791 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -764,11 +764,11 @@ class RPC extends Handler_Protected { } function setScore() { - $id = db_escape_string($_REQUEST['id']); + $ids = db_escape_string($_REQUEST['id']); $score = (int)db_escape_string($_REQUEST['score']); db_query($this->link, "UPDATE ttrss_user_entries SET - score = '$score' WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + score = '$score' WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); print json_encode(array("id" => $id, "score_pic" => theme_image($link, get_score_pic($score)))); diff --git a/js/viewfeed.js b/js/viewfeed.js index cbb10c3f..7daf0212 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -2138,6 +2138,51 @@ function cancelSearch() { } } +function setSelectionScore() { + try { + var ids = getSelectedArticleIds2(); + + if (ids.length > 0) { + console.log(ids); + + var score = prompt(__("Please enter new score for selected articles:"), score); + + if (score != undefined) { + var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) + + "&score=" + param_escape(score); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + var reply = JSON.parse(transport.responseText); + if (reply) { + console.log(ids); + + ids.each(function(id) { + var row = $("RROW-" + id); + + if (row) { + var pic = row.getElementsByClassName("hlScorePic")[0]; + + if (pic) { + pic.src = pic.src.replace(/score_.*?\.png/, + reply["score_pic"]); + pic.setAttribute("score", score); + } + } + }); + } + } }); + } + + } else { + alert(__("No articles are selected.")); + } + } catch (e) { + exception_error("setSelectionScore", e); + } +} + function changeScore(id, pic) { try { var score = pic.getAttribute("score");