]> git.wh0rd.org - tt-rss.git/blob - plugins/share/share.js
plugins: add some xhrPost refactoring
[tt-rss.git] / plugins / share / share.js
1 function shareArticle(id) {
2 try {
3 if (dijit.byId("shareArticleDlg"))
4 dijit.byId("shareArticleDlg").destroyRecursive();
5
6 var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + param_escape(id);
7
8 dialog = new dijit.Dialog({
9 id: "shareArticleDlg",
10 title: __("Share article by URL"),
11 style: "width: 600px",
12 newurl: function() {
13 if (confirm(__("Generate new share URL for this article?"))) {
14
15 notify_progress("Trying to change URL...", true);
16
17 const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };
18
19 xhrJson("backend.php", query, (reply) => {
20 if (reply) {
21 const new_link = reply.link;
22 const e = $('gen_article_url');
23
24 if (new_link) {
25
26 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
27 "&key=" + new_link);
28
29 e.href = e.href.replace(/\&key=.*$/,
30 "&key=" + new_link);
31
32 new Effect.Highlight(e);
33
34 const img = $("SHARE-IMG-" + id);
35 if (img) img.src = img.src.replace("notshared.png", "share.png");
36
37 notify('');
38
39 } else {
40 notify_error("Could not change URL.");
41 }
42 }
43 });
44 }
45
46 },
47 unshare: function() {
48 if (confirm(__("Remove sharing for this article?"))) {
49
50 notify_progress("Trying to unshare...", true);
51
52 const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };
53
54 xhrPost("backend.php", query, () => {
55 notify("Article unshared.");
56
57 var img = $("SHARE-IMG-" + id);
58 if (img) img.src = img.src.replace("share.png", "notshared.png");
59
60 dialog.hide();
61 });
62 }
63
64 },
65 href: query});
66
67 dialog.show();
68
69 const img = $("SHARE-IMG-" + id);
70 if (img) img.src = img.src.replace("notshared.png", "share.png");
71
72 } catch (e) {
73 exception_error("shareArticle", e);
74 }
75 }
76
77