use xhrPost in even more places!

master
Andrew Dolgov 6 years ago
parent ed1262d55a
commit eaf7cfdba6

@ -855,16 +855,11 @@ function deleteSelection() {
return; return;
} }
const query = "?op=rpc&method=delete&ids=" + param_escape(rows); const query = { op: "rpc", method: "delete", ids: rows.toString() };
console.log(query); xhrPost("backend.php", query, (transport) => {
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
handle_rpc_json(transport); handle_rpc_json(transport);
viewCurrentFeed(); viewCurrentFeed();
}
}); });
} }
@ -899,21 +894,16 @@ function archiveSelection() {
return; return;
} }
const query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
console.log(query);
for (let i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
cache_delete("article:" + rows[i]); cache_delete("article:" + rows[i]);
} }
new Ajax.Request("backend.php", { const query = {op: "rpc", method: op, ids: rows.toString()};
parameters: query,
onComplete: function(transport) { xhrPost("backend.php", query, (transport) => {
handle_rpc_json(transport); handle_rpc_json(transport);
viewCurrentFeed(); viewCurrentFeed();
} }); });
} }
function catchupSelection() { function catchupSelection() {
@ -955,9 +945,7 @@ function editArticleTags(id) {
notify_progress("Saving article tags...", true); notify_progress("Saving article tags...", true);
new Ajax.Request("backend.php", { xhrPost("backend.php", this.attr('value'), (transport) => {
parameters: query,
onComplete: function(transport) {
try { try {
notify(''); notify('');
dialog.hide(); dialog.hide();
@ -967,8 +955,6 @@ function editArticleTags(id) {
if (data) { if (data) {
const id = data.id; const id = data.id;
console.log(id);
const tags = $("ATSTR-" + id); const tags = $("ATSTR-" + id);
const tooltip = dijit.byId("ATSTRTIP-" + id); const tooltip = dijit.byId("ATSTRTIP-" + id);
@ -978,8 +964,7 @@ function editArticleTags(id) {
} catch (e) { } catch (e) {
exception_error(e); exception_error(e);
} }
});
}});
} }
}, },
href: query href: query
@ -1165,21 +1150,17 @@ function catchupBatchedArticles() {
// make a copy of the array // make a copy of the array
const batch = catchup_id_batch.slice(); const batch = catchup_id_batch.slice();
const query = "?op=rpc&method=catchupSelected" + const query = { op: "rpc", method: "catchupSelected",
"&cmode=0&ids=" + param_escape(batch.toString()); cmode: 0, ids: batch.toString() };
console.log(query);
_catchup_request_sent = true; _catchup_request_sent = true;
new Ajax.Request("backend.php", { xhrPost("backend.php", query, (transport) => {
parameters: query, const reply = handle_rpc_json(transport);
onComplete: function (transport) {
handle_rpc_json(transport);
_catchup_request_sent = false; _catchup_request_sent = false;
const reply = JSON.parse(transport.responseText); if (reply) {
const batch = reply.ids; const batch = reply.ids;
batch.each(function (id) { batch.each(function (id) {
@ -1188,10 +1169,9 @@ function catchupBatchedArticles() {
if (elem) elem.removeClassName("Unread"); if (elem) elem.removeClassName("Unread");
catchup_id_batch.remove(id); catchup_id_batch.remove(id);
}); });
}
updateFloatingTitle(true); updateFloatingTitle(true);
}
}); });
} }
} }
@ -1247,16 +1227,12 @@ function catchupRelativeToArticle(below, id) {
e.removeClassName("Unread"); e.removeClassName("Unread");
} }
const query = "?op=rpc&method=catchupSelected" + const query = { op: "rpc", method: "catchupSelected",
"&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); cmode: 0, ids: ids_to_mark.toString() };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, (transport) => {
parameters: query,
onComplete: function (transport) {
handle_rpc_json(transport); handle_rpc_json(transport);
}
}); });
} }
} }
} }
@ -1424,17 +1400,16 @@ function cdmClicked(event, id, in_body) {
if (article_is_unread) { if (article_is_unread) {
decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
updateFloatingTitle(true); updateFloatingTitle(true);
}
const query = "?op=rpc&method=catchupSelected" + const query = {
"&cmode=0&ids=" + param_escape(id); op: "rpc", method: "catchupSelected",
cmode: 0, ids: id
};
new Ajax.Request("backend.php", { xhrPost("backend.php", query, (transport) => {
parameters: query,
onComplete: function (transport) {
handle_rpc_json(transport); handle_rpc_json(transport);
}
}); });
}
return !event.shiftKey; return !event.shiftKey;
} }
@ -1812,17 +1787,12 @@ function setSelectionScore() {
const score = prompt(__("Please enter new score for selected articles:")); const score = prompt(__("Please enter new score for selected articles:"));
if (score != undefined) { if (score != undefined) {
const query = "op=article&method=setScore&id=" + param_escape(ids.toString()) + const query = { op: "article", method: "setScore", id: ids.toString(),
"&score=" + param_escape(score); score: score };
new Ajax.Request("backend.php", { xhrJson("backend.php", query, (reply) => {
parameters: query,
onComplete: function (transport) {
const reply = JSON.parse(transport.responseText);
if (reply) { if (reply) {
console.log(ids); reply.id.each((id) => {
ids.each(function (id) {
const row = $("RROW-" + id); const row = $("RROW-" + id);
if (row) { if (row) {
@ -1831,12 +1801,11 @@ function setSelectionScore() {
if (pic) { if (pic) {
pic.src = pic.src.replace(/score_.*?\.png/, pic.src = pic.src.replace(/score_.*?\.png/,
reply["score_pic"]); reply["score_pic"]);
pic.setAttribute("score", score); pic.setAttribute("score", reply["score"]);
} }
} }
}); });
} }
}
}); });
} }
@ -1845,6 +1814,7 @@ function setSelectionScore() {
} }
} }
/*
function updateScore(id) { function updateScore(id) {
const pic = $$("#RROW-" + id + " .hlScorePic")[0]; const pic = $$("#RROW-" + id + " .hlScorePic")[0];
@ -1867,7 +1837,7 @@ function updateScore(id) {
} }
}); });
} }
} } */
function changeScore(id, pic) { function changeScore(id, pic) {
const score = pic.getAttribute("score"); const score = pic.getAttribute("score");
@ -1875,38 +1845,27 @@ function changeScore(id, pic) {
const new_score = prompt(__("Please enter new score for this article:"), score); const new_score = prompt(__("Please enter new score for this article:"), score);
if (new_score != undefined) { if (new_score != undefined) {
const query = { op: "article", method: "setScore", id: id, score: new_score };
const query = "op=article&method=setScore&id=" + param_escape(id) + xhrJson("backend.php", query, (reply) => {
"&score=" + param_escape(new_score);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
const reply = JSON.parse(transport.responseText);
if (reply) { if (reply) {
pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
pic.setAttribute("score", new_score); pic.setAttribute("score", new_score);
pic.setAttribute("title", new_score); pic.setAttribute("title", new_score);
} }
}
}); });
} }
} }
function displayArticleUrl(id) { function displayArticleUrl(id) {
const query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id); const query = { op: "rpc", method: "getlinktitlebyid", id: id };
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
const reply = JSON.parse(transport.responseText);
xhrJson("backend.php", query, (reply) => {
if (reply && reply.link) { if (reply && reply.link) {
prompt(__("Article URL:"), reply.link); prompt(__("Article URL:"), reply.link);
} }
}
}); });
} }
function scrollToRowId(id) { function scrollToRowId(id) {

Loading…
Cancel
Save