summaryrefslogtreecommitdiff
path: root/plugins/share/share.js
blob: 09c973ed843f8cc838e5a546f8baa4cf386dc7f6 (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
78
79
80
81
82
83
84
85
86
87
88
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() {

				var ok = confirm(__("Generate new share URL for this article?"));

				if (ok) {

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

					var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);

					new Ajax.Request("backend.php", {
						parameters: query,
						onComplete: function(transport) {
								var reply = JSON.parse(transport.responseText);
								var new_link = reply.link;

								var 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);

									var 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() {

				var ok = confirm(__("Remove sharing for this article?"));

				if (ok) {

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

					var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);

					new Ajax.Request("backend.php", {
						parameters: query,
						onComplete: function(transport) {
							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();

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

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