summaryrefslogtreecommitdiff
path: root/mail.js
blob: 2b81d232dd75e78e3be605af6e65755ca8bf42a4 (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
/* global require, PluginHost, Plugins, Headlines, dojo, App, xhr, Notify, fox, __ */

Plugins.Mail = {
	init: function() {
		PluginHost.register(PluginHost.HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM2, (action) => {
			if (action == "Plugins.Mail.send()")
				this.send();

				return true;
		});
	},
	send: function(id) {
		if (!id) {
			const ids = Headlines.getSelected();

			if (ids.length == 0) {
				alert(__("No articles selected."));
				return;
			}

			id = ids.toString();
		}

		const dialog = new fox.SingleUseDialog({
			title: __("Forward article by email"),
			execute: function () {
				if (this.validate()) {
					xhr.json("backend.php", this.attr('value'), (reply) => {
						if (reply) {
							const error = reply['error'];

							if (error) {
								alert(__('Error sending email:') + ' ' + error);
							} else {
								Notify.info('Your message has been sent.');
								dialog.hide();
							}

						}
					});
				}
			},
			content: __("Loading, please wait...")
		});

		const tmph = dojo.connect(dialog, 'onShow', function () {
			dojo.disconnect(tmph);

			xhr.post("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (reply) => {
				dialog.attr('content', reply);
			});
		});

		dialog.show();
	},
	onHotkey: function(id) {
		Plugins.Mail.send(id);
	}
};

require(['dojo/_base/kernel', 'dojo/ready'], function  (dojo, ready, script) {
	ready(function() {
		Plugins.Mail.init();
	})
});