plugins: add some xhrPost refactoring

This commit is contained in:
Andrew Dolgov 2018-11-30 15:23:48 +03:00
parent 764434a491
commit 2f961ee830
5 changed files with 54 additions and 99 deletions

View File

@ -1690,31 +1690,6 @@ function setSelectionScore() {
} }
} }
/*
function updateScore(id) {
const pic = $$("#RROW-" + id + " .hlScorePic")[0];
if (pic) {
const query = "op=article&method=getScore&id=" + param_escape(id);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
console.log(transport.responseText);
const reply = JSON.parse(transport.responseText);
if (reply) {
pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
pic.setAttribute("score", reply["score"]);
pic.setAttribute("title", reply["score"]);
}
}
});
}
} */
function changeScore(id, pic) { function changeScore(id, pic) {
const score = pic.getAttribute("score"); const score = pic.getAttribute("score");

View File

@ -7,9 +7,6 @@ function embedOriginalArticle(id) {
return; return;
} }
const query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
param_escape(id);
let c = false; let c = false;
if (isCdmMode()) { if (isCdmMode()) {
@ -33,34 +30,29 @@ function embedOriginalArticle(id) {
} }
} }
new Ajax.Request("backend.php", { const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id };
parameters: query,
onComplete: function(transport) {
const ti = JSON.parse(transport.responseText);
if (ti) { xhrJson("backend.php", query, (reply) => {
if (reply) {
const iframe = new Element("iframe", {
class: "embeddedContent",
src: reply.url,
width: (c.parentNode.offsetWidth - 5) + 'px',
height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px',
style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;",
sandbox: 'allow-scripts',
});
const iframe = new Element("iframe", { if (c) {
class: "embeddedContent", Element.hide(c);
src: ti.url, c.parentNode.insertBefore(iframe, c);
width: (c.parentNode.offsetWidth-5)+'px',
height: (c.parentNode.parentNode.offsetHeight-c.parentNode.firstChild.offsetHeight-5)+'px',
style: "overflow: auto; border: none; min-height: "+(document.body.clientHeight/2)+"px;",
sandbox: 'allow-scripts',
});
if (c) { if (isCdmMode()) {
Element.hide(c); cdmScrollToArticleId(id, true);
c.parentNode.insertBefore(iframe,c);
if (isCdmMode()) {
cdmScrollToArticleId(id, true);
}
} }
} }
}
} }); });
} catch (e) { } catch (e) {
exception_error("embedOriginalArticle", e); exception_error("embedOriginalArticle", e);

View File

@ -22,15 +22,9 @@ function emailArticle(id) {
style: "width: 600px", style: "width: 600px",
execute: function() { execute: function() {
if (this.validate()) { if (this.validate()) {
xhrJson("backend.php", this.attr('value'), (reply) => {
new Ajax.Request("backend.php", { if (reply) {
parameters: dojo.objectToQuery(this.attr('value')), const error = reply['error'];
onComplete: function(transport) {
console.log(transport.responseText);
var reply = JSON.parse(transport.responseText);
var error = reply['error'];
if (error) { if (error) {
alert(__('Error sending email:') + ' ' + error); alert(__('Error sending email:') + ' ' + error);
@ -39,7 +33,8 @@ function emailArticle(id) {
dialog.hide(); dialog.hide();
} }
} }); }
});
} }
}, },
href: query}); href: query});

View File

@ -14,36 +14,33 @@ function shareArticle(id) {
notify_progress("Trying to change URL...", true); notify_progress("Trying to change URL...", true);
var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id); const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };
new Ajax.Request("backend.php", { xhrJson("backend.php", query, (reply) => {
parameters: query, if (reply) {
onComplete: function(transport) { const new_link = reply.link;
var reply = JSON.parse(transport.responseText); const e = $('gen_article_url');
var new_link = reply.link;
var e = $('gen_article_url'); if (new_link) {
if (new_link) { e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
"&key=" + new_link);
e.innerHTML = e.innerHTML.replace(/\&key=.*$/, e.href = e.href.replace(/\&key=.*$/,
"&key=" + new_link); "&key=" + new_link);
e.href = e.href.replace(/\&key=.*$/, new Effect.Highlight(e);
"&key=" + new_link);
new Effect.Highlight(e); const img = $("SHARE-IMG-" + id);
if (img) img.src = img.src.replace("notshared.png", "share.png");
var img = $("SHARE-IMG-" + id); notify('');
if (img) img.src = img.src.replace("notshared.png", "share.png");
notify('');
} else {
notify_error("Could not change URL.");
}
} });
} else {
notify_error("Could not change URL.");
}
}
});
} }
}, },
@ -52,18 +49,16 @@ function shareArticle(id) {
notify_progress("Trying to unshare...", true); notify_progress("Trying to unshare...", true);
var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id); const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, notify("Article unshared.");
onComplete: function(transport) {
notify("Article unshared.");
var img = $("SHARE-IMG-" + id); var img = $("SHARE-IMG-" + id);
if (img) img.src = img.src.replace("share.png", "notshared.png"); if (img) img.src = img.src.replace("share.png", "notshared.png");
dialog.hide(); dialog.hide();
} }); });
} }
}, },
@ -71,7 +66,7 @@ function shareArticle(id) {
dialog.show(); dialog.show();
var img = $("SHARE-IMG-" + id); const img = $("SHARE-IMG-" + id);
if (img) img.src = img.src.replace("notshared.png", "share.png"); if (img) img.src = img.src.replace("notshared.png", "share.png");
} catch (e) { } catch (e) {

View File

@ -2,13 +2,11 @@ function clearArticleAccessKeys() {
if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) {
notify_progress("Clearing URLs..."); notify_progress("Clearing URLs...");
var query = "?op=pluginhandler&plugin=share&method=clearArticleKeys"; const query = { op: "pluginhandler", plugin: "share", method: "clearArticleKeys" };
new Ajax.Request("backend.php", { xhrPost("backend.php", query, () => {
parameters: query, notify_info("Shared URLs cleared.");
onComplete: function(transport) { });
notify_info("Shared URLs cleared.");
} });
} }
return false; return false;