2021-02-17 05:52:39 +00:00
|
|
|
/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
Plugins.Share = {
|
|
|
|
shareArticle: function(id) {
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2011-12-21 04:46:39 +00:00
|
|
|
id: "shareArticleDlg",
|
|
|
|
title: __("Share article by URL"),
|
2018-12-03 07:51:14 +00:00
|
|
|
newurl: function () {
|
2018-11-30 10:05:59 +00:00
|
|
|
if (confirm(__("Generate new share URL for this article?"))) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Trying to change URL...", true);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 18:44:21 +00:00
|
|
|
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;
|
2021-02-17 05:52:39 +00:00
|
|
|
const target = dialog.domNode.querySelector(".target-url");
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
if (new_link && target) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
target.innerHTML = target.innerHTML.replace(/&key=.*$/,
|
2018-11-30 12:23:48 +00:00
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
target.href = target.href.replace(/&key=.*$/,
|
2018-11-30 12:23:48 +00:00
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
const icon = document.querySelector(".share-icon-" + id);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
if (icon)
|
|
|
|
icon.addClassName("is-shared");
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2013-07-11 10:03:40 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-07-11 10:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2018-12-03 07:51:14 +00:00
|
|
|
unshare: function () {
|
2018-11-30 10:05:59 +00:00
|
|
|
if (confirm(__("Remove sharing for this article?"))) {
|
2021-02-17 18:44:21 +00:00
|
|
|
xhrPost("backend.php", App.getPhArgs("share", "unshare", {id: id}), (transport) => {
|
2021-02-17 05:52:39 +00:00
|
|
|
Notify.info(transport.responseText);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
const icon = document.querySelector(".share-icon-" + id);
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
if (icon)
|
|
|
|
icon.removeClassName("is-shared");
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
dialog.hide();
|
2018-11-30 12:23:48 +00:00
|
|
|
});
|
2013-07-11 10:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2021-02-17 05:52:39 +00:00
|
|
|
content: __("Loading, please wait...")
|
2018-12-03 07:51:14 +00:00
|
|
|
});
|
2011-12-21 04:46:39 +00:00
|
|
|
|
2021-02-17 05:52:39 +00:00
|
|
|
const tmph = dojo.connect(dialog, 'onShow', function () {
|
|
|
|
dojo.disconnect(tmph);
|
2011-12-21 04:46:39 +00:00
|
|
|
|
2021-02-17 18:44:21 +00:00
|
|
|
xhrPost("backend.php", App.getPhArgs("share", "shareDialog", {id: id}), (transport) => {
|
2021-02-17 05:52:39 +00:00
|
|
|
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
|
|
|
}
|
2021-02-12 12:22:10 +00:00
|
|
|
}
|