summaryrefslogtreecommitdiffstats
path: root/browser/src/control/Control.Infobar.js
blob: 59c27f6665d90359bde0b8983116c597645f771d (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
/* -*- js-indent-level: 8 -*- */
/*
 * L.Control.Infobar used for displaying non-annoying info messages
 */

/* global vex $ */
L.Control.Infobar = L.Control.extend({
	onAdd: function (map) {
		map.on('infobar', this._onInfobar, this);
	},

	_onInfobar: function(e) {
		if (!e.msg)
			return;

		var product = function () {
			var integratorUrl = encodeURIComponent(window.buyProductUrl);
			var productUrl = window.feedbackUrl;
			productUrl = productUrl.substring(0, productUrl.lastIndexOf('/')) +
				    '/product.html?integrator='+ integratorUrl;
			var newWin = window.open(productUrl, '_blank');
			newWin.focus();
		};

		var buttons = [];
		var callback = function() {};
		if (e.actionLabel && e.action) {
			buttons.push($.extend({}, vex.dialog.buttons.YES, { text: e.actionLabel }));
			if (window.feedbackUrl)
				buttons.push($.extend({}, vex.dialog.buttons.YES, {
					text: 'Buy Product',
					click: product
				}));
			callback = function (value) {
				if (value === false) // close btn clicked
					return;

				if (e.action.startsWith('http')) { // We have a link
					var win = window.open(e.action, '_blank');
					win.focus();
				}
			};
		}

		vex.dialog.open({
			message: e.msg,
			className: 'vex-theme-bottom-right-corner',
			showCloseButton: true,
			buttons: buttons,
			callback: callback
		});
	}
});

L.control.infobar = function (options) {
	return new L.Control.Infobar(options);
};