2018-12-03 07:51:14 +00:00
|
|
|
Plugins.Share = {
|
|
|
|
shareArticle: function(id) {
|
2011-12-21 04:46:39 +00:00
|
|
|
if (dijit.byId("shareArticleDlg"))
|
|
|
|
dijit.byId("shareArticleDlg").destroyRecursive();
|
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id);
|
2011-12-21 04:46:39 +00:00
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const dialog = new dijit.Dialog({
|
2011-12-21 04:46:39 +00:00
|
|
|
id: "shareArticleDlg",
|
|
|
|
title: __("Share article by URL"),
|
|
|
|
style: "width: 600px",
|
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
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id};
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
xhrJson("backend.php", query, (reply) => {
|
|
|
|
if (reply) {
|
|
|
|
const new_link = reply.link;
|
|
|
|
const e = $('gen_article_url');
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
if (new_link) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
e.href = e.href.replace(/\&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
new Effect.Highlight(e);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
const img = $("SHARE-IMG-" + id);
|
2018-12-05 19:19:46 +00:00
|
|
|
img.addClassName("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?"))) {
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Trying to unshare...", true);
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-12-03 07:51:14 +00:00
|
|
|
const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
|
2013-07-11 10:03:40 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
xhrPost("backend.php", query, () => {
|
|
|
|
notify("Article unshared.");
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2018-12-05 19:19:46 +00:00
|
|
|
const img = $("SHARE-IMG-" + id);
|
|
|
|
img.removeClassName("shared");
|
2013-07-11 12:20:24 +00:00
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
dialog.hide();
|
|
|
|
});
|
2013-07-11 10:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2018-12-03 07:51:14 +00:00
|
|
|
href: query
|
|
|
|
});
|
2011-12-21 04:46:39 +00:00
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
2018-11-30 12:23:48 +00:00
|
|
|
const img = $("SHARE-IMG-" + id);
|
2018-12-05 19:19:46 +00:00
|
|
|
img.addClassName("shared");
|
2011-12-21 04:46:39 +00:00
|
|
|
}
|
2018-12-03 07:51:14 +00:00
|
|
|
};
|
|
|
|
|
2011-12-21 04:46:39 +00:00
|
|
|
|
|
|
|
|