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