summaryrefslogtreecommitdiff
path: root/plugins/share/share.js
blob: 11748d8fe73e0dfb26d35017b7f8ea74c6dc076e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function shareArticle(id) {
	try {
		if (dijit.byId("shareArticleDlg"))
			dijit.byId("shareArticleDlg").destroyRecursive();

		var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + param_escape(id);

		dialog = new dijit.Dialog({
			id: "shareArticleDlg",
			title: __("Share article by URL"),
			style: "width: 600px",
			newurl: function() {
				if (confirm(__("Generate new share URL for this article?"))) {

					notify_progress("Trying to change URL...", true);

					const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };

					xhrJson("backend.php", query, (reply) => {
						if (reply) {
							const new_link = reply.link;
							const e = $('gen_article_url');

							if (new_link) {

								e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
									"&key=" + new_link);

								e.href = e.href.replace(/\&key=.*$/,
									"&key=" + new_link);

								new Effect.Highlight(e);

								const img = $("SHARE-IMG-" + id);
								if (img) img.src = img.src.replace("notshared.png", "share.png");

								notify('');

							} else {
								notify_error("Could not change URL.");
							}
						}
					});
				}

			},
			unshare: function() {
				if (confirm(__("Remove sharing for this article?"))) {

					notify_progress("Trying to unshare...", true);

					const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };

					xhrPost("backend.php", query, () => {
						notify("Article unshared.");

						var img = $("SHARE-IMG-" + id);
						if (img) img.src = img.src.replace("share.png", "notshared.png");

						dialog.hide();
					});
				}

			},
			href: query});

		dialog.show();

		const img = $("SHARE-IMG-" + id);
		if (img) img.src = img.src.replace("notshared.png", "share.png");

	} catch (e) {
		exception_error("shareArticle", e);
	}
}