-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathMessage.js
97 lines (84 loc) · 2.91 KB
/
Message.js
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
89
90
91
92
93
94
95
96
97
BR.Message = L.Class.extend({
options: {
// true to manually attach click event to close button,
// Bootstrap data-api's auto-initialization doesn't work in Controls because of stopPropagation
alert: false,
onClosed: null,
},
initialize(id, options) {
L.setOptions(this, options);
this.id = id;
},
_show(msg, type) {
var ele = L.DomUtil.get(this.id),
iconClass,
alertClass;
switch (type) {
case 'error':
iconClass = 'fa-times-circle';
alertClass = 'alert-danger';
break;
case 'warning':
iconClass = 'fa-exclamation-triangle';
alertClass = 'alert-warning';
break;
case 'loading':
iconClass = 'fa-spinner fa-pulse';
alertClass = 'alert-secondary';
break;
default:
case 'info':
iconClass = 'fa-info-circle';
alertClass = 'alert-info';
break;
}
L.DomEvent.disableClickPropagation(ele);
ele.innerHTML =
'<div class="alert ' +
alertClass +
' alert-dismissible fade show" role="alert">' +
' <button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
' <span aria-hidden="true">×</span>' +
' </button>' +
' <span class="fa ' +
iconClass +
'" aria-hidden="true"/></span>' +
msg +
'</div>';
if (this.options.onClosed) {
$('#' + this.id + ' .alert').on('closed.bs.alert', this.options.onClosed);
}
if (this.options.alert) {
$('#' + this.id + ' .alert').alert();
}
},
hide() {
$('#' + this.id + ' .alert').alert('close');
},
showError(err) {
if (err && err.message) err = err.message;
if (err == 'target island detected for section 0\n') {
err = i18next.t('warning.no-route-found');
} else if (err == 'no track found at pass=0\n') {
err = i18next.t('warning.no-route-found');
} else if (err == 'to-position not mapped in existing datafile\n') {
err = i18next.t('warning.invalid-route-to');
} else if (err == 'from-position not mapped in existing datafile\n') {
err = i18next.t('warning.invalid-route-from');
} else if (err && err.startsWith('null description for: ')) {
err = i18next.t('warning.no-route-found');
}
this._show(err, 'error');
},
showWarning(msg) {
this._show(msg, 'warning');
},
showInfo(msg) {
this._show(msg, 'info');
},
showLoading(msg) {
this._show(msg, 'loading');
},
});
// static instance as global control
BR.message = new BR.Message('message');