use xhrPost in even more places!

master
Andrew Dolgov 6 years ago
parent ed1262d55a
commit eaf7cfdba6

@ -855,65 +855,55 @@ 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) => {
handle_rpc_json(transport);
new Ajax.Request("backend.php", { viewCurrentFeed();
parameters: query,
onComplete: function (transport) {
handle_rpc_json(transport);
viewCurrentFeed();
}
}); });
} }
function archiveSelection() { function archiveSelection() {
const rows = getSelectedArticleIds2(); const rows = getSelectedArticleIds2();
if (rows.length == 0) {
alert(__("No articles are selected."));
return;
}
const fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
let str;
let op;
if (getActiveFeedId() != 0) { if (rows.length == 0) {
str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length); alert(__("No articles are selected."));
op = "archive"; return;
} else { }
str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
str += " " + __("Please note that unstarred articles might get purged on next feed update."); const fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
let str;
let op;
op = "unarchive"; if (getActiveFeedId() != 0) {
} str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
op = "archive";
} else {
str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
str = str.replace("%d", rows.length); str += " " + __("Please note that unstarred articles might get purged on next feed update.");
str = str.replace("%s", fn);
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { op = "unarchive";
return; }
}
const query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); str = str.replace("%d", rows.length);
str = str.replace("%s", fn);
console.log(query); if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
return;
}
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) {
handle_rpc_json(transport);
viewCurrentFeed();
} });
xhrPost("backend.php", query, (transport) => {
handle_rpc_json(transport);
viewCurrentFeed();
});
} }
function catchupSelection() { function catchupSelection() {
@ -955,31 +945,26 @@ 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, try {
onComplete: function(transport) { notify('');
try { dialog.hide();
notify('');
dialog.hide();
const data = JSON.parse(transport.responseText); const data = JSON.parse(transport.responseText);
if (data) { if (data) {
const id = data.id; const id = data.id;
console.log(id); const tags = $("ATSTR-" + id);
const tooltip = dijit.byId("ATSTRTIP-" + id);
const tags = $("ATSTR-" + id); if (tags) tags.innerHTML = data.content;
const tooltip = dijit.byId("ATSTRTIP-" + id); if (tooltip) tooltip.attr('label', data.content_full);
}
if (tags) tags.innerHTML = data.content; } catch (e) {
if (tooltip) tooltip.attr('label', data.content_full); exception_error(e);
} }
} catch (e) { });
exception_error(e);
}
}});
} }
}, },
href: query href: query
@ -1165,33 +1150,28 @@ 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) {
console.log(id); console.log(id);
const elem = $("RROW-" + id); const elem = $("RROW-" + id);
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, handle_rpc_json(transport);
onComplete: function (transport) {
handle_rpc_json(transport);
}
}); });
} }
} }
} }
@ -1422,19 +1398,18 @@ function cdmClicked(event, id, in_body) {
setActiveArticleId(id); setActiveArticleId(id);
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, handle_rpc_json(transport);
onComplete: function (transport) { });
handle_rpc_json(transport); }
}
});
return !event.shiftKey; return !event.shiftKey;
} }
@ -1812,31 +1787,25 @@ 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, if (reply) {
onComplete: function (transport) { reply.id.each((id) => {
const reply = JSON.parse(transport.responseText); const row = $("RROW-" + id);
if (reply) {
console.log(ids); if (row) {
const pic = row.getElementsByClassName("hlScorePic")[0];
ids.each(function (id) {
const row = $("RROW-" + id); if (pic) {
pic.src = pic.src.replace(/score_.*?\.png/,
if (row) { reply["score_pic"]);
const pic = row.getElementsByClassName("hlScorePic")[0]; pic.setAttribute("score", reply["score"]);
}
if (pic) { }
pic.src = pic.src.replace(/score_.*?\.png/, });
reply["score_pic"]); }
pic.setAttribute("score", 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) +
"&score=" + param_escape(new_score); xhrJson("backend.php", query, (reply) => {
if (reply) {
new Ajax.Request("backend.php", { pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
parameters: query, pic.setAttribute("score", new_score);
onComplete: function (transport) { pic.setAttribute("title", new_score);
const reply = JSON.parse(transport.responseText); }
if (reply) {
pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
pic.setAttribute("score", 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", { xhrJson("backend.php", query, (reply) => {
parameters: query, if (reply && reply.link) {
onComplete: function (transport) { prompt(__("Article URL:"), reply.link);
const reply = JSON.parse(transport.responseText); }
if (reply && reply.link) {
prompt(__("Article URL:"), reply.link);
}
}
}); });
} }
function scrollToRowId(id) { function scrollToRowId(id) {

Loading…
Cancel
Save