ttrss/plugins/share/share.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */
Plugins.Share = {
shareArticle: function(id) {
const dialog = new fox.SingleUseDialog({
2011-12-21 04:46:39 +00:00
id: "shareArticleDlg",
title: __("Share article by URL"),
newurl: function () {
2018-11-30 10:05:59 +00:00
if (confirm(__("Generate new share URL for this article?"))) {
2018-12-02 17:56:30 +00:00
Notify.progress("Trying to change URL...", true);
const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id};
2018-11-30 12:23:48 +00:00
xhrJson("backend.php", query, (reply) => {
if (reply) {
const new_link = reply.link;
const target = dialog.domNode.querySelector(".target-url");
if (new_link && target) {
target.innerHTML = target.innerHTML.replace(/&key=.*$/,
2018-11-30 12:23:48 +00:00
"&key=" + new_link);
target.href = target.href.replace(/&key=.*$/,
2018-11-30 12:23:48 +00:00
"&key=" + new_link);
// eslint-disable-next-line no-new
new Effect.Highlight(target);
const icon = document.querySelector(".share-icon-" + id);
if (icon)
icon.addClassName("is-shared");
2018-12-02 17:56:30 +00:00
Notify.close();
2018-11-30 12:23:48 +00:00
} else {
2018-12-02 17:56:30 +00:00
Notify.error("Could not change URL.");
2018-11-30 12:23:48 +00:00
}
}
});
}
},
unshare: function () {
2018-11-30 10:05:59 +00:00
if (confirm(__("Remove sharing for this article?"))) {
xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "unshare", id: id}, (transport) => {
Notify.info(transport.responseText);
const icon = document.querySelector(".share-icon-" + id);
if (icon)
icon.removeClassName("is-shared");
dialog.hide();
2018-11-30 12:23:48 +00:00
});
}
},
content: __("Loading, please wait...")
});
2011-12-21 04:46:39 +00:00
const tmph = dojo.connect(dialog, 'onShow', function () {
dojo.disconnect(tmph);
2011-12-21 04:46:39 +00:00
xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "shareDialog", id: id}, (transport) => {
dialog.attr('content', transport.responseText)
const icon = document.querySelector(".share-icon-" + id);
if (icon)
icon.addClassName("is-shared");
});
});
dialog.show();
2011-12-21 04:46:39 +00:00
}
}