Show More
@@ -1,60 +1,59 b'' | |||||
1 | "use strict"; |
|
1 | "use strict"; | |
2 |
|
2 | |||
3 | toastr.options = { |
|
3 | toastr.options = { | |
4 | "closeButton": true, |
|
4 | "closeButton": true, | |
5 | "debug": false, |
|
5 | "debug": false, | |
6 | "newestOnTop": false, |
|
6 | "newestOnTop": false, | |
7 | "progressBar": false, |
|
7 | "progressBar": false, | |
8 | "positionClass": "toast-top-center", |
|
8 | "positionClass": "toast-top-center", | |
9 | "preventDuplicates": false, |
|
9 | "preventDuplicates": false, | |
10 | "onclick": null, |
|
10 | "onclick": null, | |
11 | "showDuration": "300", |
|
11 | "showDuration": "300", | |
12 | "hideDuration": "300", |
|
12 | "hideDuration": "300", | |
13 | "timeOut": "0", |
|
13 | "timeOut": "0", | |
14 | "extendedTimeOut": "0", |
|
14 | "extendedTimeOut": "0", | |
15 | "showEasing": "swing", |
|
15 | "showEasing": "swing", | |
16 | "hideEasing": "linear", |
|
16 | "hideEasing": "linear", | |
17 | "showMethod": "fadeIn", |
|
17 | "showMethod": "fadeIn", | |
18 | "hideMethod": "fadeOut" |
|
18 | "hideMethod": "fadeOut" | |
19 | }; |
|
19 | }; | |
20 |
|
20 | |||
21 | function notifySystem(data) { |
|
21 | function notifySystem(data) { | |
22 | var notification = new Notification(data.message.level + ': ' + data.message.message); |
|
22 | var notification = new Notification(data.message.level + ': ' + data.message.message); | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | function notifyToaster(data){ |
|
25 | function notifyToaster(data){ | |
26 | toastr[data.message.level](data.message.message); |
|
26 | toastr[data.message.level](data.message.message); | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | function handleNotifications(data) { |
|
29 | function handleNotifications(data) { | |
30 |
|
30 | if (!templateContext.rhodecode_user.notification_status && !data.message.testMessage) { | ||
31 | if (!templateContext.rhodecode_user.notification_status && !data.testMessage) { |
|
|||
32 | // do not act if notifications are disabled |
|
31 | // do not act if notifications are disabled | |
33 | return |
|
32 | return | |
34 | } |
|
33 | } | |
35 | // use only js notifications for now |
|
34 | // use only js notifications for now | |
36 | var onlyJS = true; |
|
35 | var onlyJS = true; | |
37 | if (!("Notification" in window) || onlyJS) { |
|
36 | if (!("Notification" in window) || onlyJS) { | |
38 | // use legacy notificartion |
|
37 | // use legacy notificartion | |
39 | notifyToaster(data); |
|
38 | notifyToaster(data); | |
40 | } |
|
39 | } | |
41 | else { |
|
40 | else { | |
42 | // Let's check whether notification permissions have already been granted |
|
41 | // Let's check whether notification permissions have already been granted | |
43 | if (Notification.permission === "granted") { |
|
42 | if (Notification.permission === "granted") { | |
44 | notifySystem(data); |
|
43 | notifySystem(data); | |
45 | } |
|
44 | } | |
46 | // Otherwise, we need to ask the user for permission |
|
45 | // Otherwise, we need to ask the user for permission | |
47 | else if (Notification.permission !== 'denied') { |
|
46 | else if (Notification.permission !== 'denied') { | |
48 | Notification.requestPermission(function (permission) { |
|
47 | Notification.requestPermission(function (permission) { | |
49 | if (permission === "granted") { |
|
48 | if (permission === "granted") { | |
50 | notifySystem(data); |
|
49 | notifySystem(data); | |
51 | } |
|
50 | } | |
52 | }); |
|
51 | }); | |
53 | } |
|
52 | } | |
54 | else{ |
|
53 | else{ | |
55 | notifyToaster(data); |
|
54 | notifyToaster(data); | |
56 | } |
|
55 | } | |
57 | } |
|
56 | } | |
58 | }; |
|
57 | }; | |
59 |
|
58 | |||
60 | $.Topic('/notifications').subscribe(handleNotifications); |
|
59 | $.Topic('/notifications').subscribe(handleNotifications); |
General Comments 0
You need to be logged in to leave comments.
Login now