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