ttrss/plugins/share/share.js

75 lines
1.8 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);
xhrJson("backend.php", App.getPhArgs("share", "newkey", {id: id}), (reply) => {
2018-11-30 12:23:48 +00:00
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);
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", App.getPhArgs("share", "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", App.getPhArgs("share", "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
}
}