##// END OF EJS Templates
notifications: replace testMessage with "force"
ergo -
r732:2c17b7fe default
parent child Browse files
Show More
@@ -1,47 +1,47 b''
1 "use strict";
1 "use strict";
2
2
3
3
4 function notifySystem(data) {
4 function notifySystem(data) {
5 var notification = new Notification(data.message.level + ': ' + data.message.message);
5 var notification = new Notification(data.message.level + ': ' + data.message.message);
6 };
6 };
7
7
8 function notifyToaster(data){
8 function notifyToaster(data){
9 var notifications = document.getElementById('notifications');
9 var notifications = document.getElementById('notifications');
10 notifications.push('toasts',
10 notifications.push('toasts',
11 { level: data.message.level,
11 { level: data.message.level,
12 message: data.message.message
12 message: data.message.message
13 });
13 });
14 notifications.open();
14 notifications.open();
15 }
15 }
16
16
17 function handleNotifications(data) {
17 function handleNotifications(data) {
18 if (!templateContext.rhodecode_user.notification_status && !data.message.testMessage) {
18 if (!templateContext.rhodecode_user.notification_status && !data.message.force) {
19 // do not act if notifications are disabled
19 // do not act if notifications are disabled
20 return
20 return
21 }
21 }
22 // use only js notifications for now
22 // use only js notifications for now
23 var onlyJS = true;
23 var onlyJS = true;
24 if (!("Notification" in window) || onlyJS) {
24 if (!("Notification" in window) || onlyJS) {
25 // use legacy notificartion
25 // use legacy notificartion
26 notifyToaster(data);
26 notifyToaster(data);
27 }
27 }
28 else {
28 else {
29 // Let's check whether notification permissions have already been granted
29 // Let's check whether notification permissions have already been granted
30 if (Notification.permission === "granted") {
30 if (Notification.permission === "granted") {
31 notifySystem(data);
31 notifySystem(data);
32 }
32 }
33 // Otherwise, we need to ask the user for permission
33 // Otherwise, we need to ask the user for permission
34 else if (Notification.permission !== 'denied') {
34 else if (Notification.permission !== 'denied') {
35 Notification.requestPermission(function (permission) {
35 Notification.requestPermission(function (permission) {
36 if (permission === "granted") {
36 if (permission === "granted") {
37 notifySystem(data);
37 notifySystem(data);
38 }
38 }
39 });
39 });
40 }
40 }
41 else{
41 else{
42 notifyToaster(data);
42 notifyToaster(data);
43 }
43 }
44 }
44 }
45 };
45 };
46
46
47 $.Topic('/notifications').subscribe(handleNotifications);
47 $.Topic('/notifications').subscribe(handleNotifications);
@@ -1,88 +1,88 b''
1 <template is="dom-bind" id="notificationsPage">
1 <template is="dom-bind" id="notificationsPage">
2 <iron-ajax id="toggleNotifications"
2 <iron-ajax id="toggleNotifications"
3 method="post"
3 method="post"
4 url="${url('my_account_notifications_toggle_visibility')}"
4 url="${url('my_account_notifications_toggle_visibility')}"
5 content-type="application/json"
5 content-type="application/json"
6 loading="{{changeNotificationsLoading}}"
6 loading="{{changeNotificationsLoading}}"
7 on-response="handleNotifications"
7 on-response="handleNotifications"
8 handle-as="json"></iron-ajax>
8 handle-as="json"></iron-ajax>
9
9
10 <div class="panel panel-default">
10 <div class="panel panel-default">
11 <div class="panel-heading">
11 <div class="panel-heading">
12 <h3 class="panel-title">${_('Your Live Notification Settings')}</h3>
12 <h3 class="panel-title">${_('Your Live Notification Settings')}</h3>
13 </div>
13 </div>
14 <div class="panel-body">
14 <div class="panel-body">
15
15
16 <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p>
16 <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p>
17
17
18 <p class="hidden">Status of browser notifications permission: <strong id="browser-notification-status"></strong></p>
18 <p class="hidden">Status of browser notifications permission: <strong id="browser-notification-status"></strong></p>
19
19
20 <div class="form">
20 <div class="form">
21 <div class="fields">
21 <div class="fields">
22 <div class="field">
22 <div class="field">
23 <div class="label">
23 <div class="label">
24 <label for="new_email">${_('Notifications Status')}:</label>
24 <label for="new_email">${_('Notifications Status')}:</label>
25 </div>
25 </div>
26 <div class="checkboxes">
26 <div class="checkboxes">
27 <rhodecode-toggle id="live-notifications" active="[[changeNotificationsLoading]]" on-change="toggleNotifications" ${'checked' if c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}></rhodecode-toggle>
27 <rhodecode-toggle id="live-notifications" active="[[changeNotificationsLoading]]" on-change="toggleNotifications" ${'checked' if c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}></rhodecode-toggle>
28 </div>
28 </div>
29 </div>
29 </div>
30 <div class="buttons">
30 <div class="buttons">
31 <a class="btn btn-default" id="test-notification">Test notification</a>
31 <a class="btn btn-default" id="test-notification">Test notification</a>
32 </div>
32 </div>
33 </div>
33 </div>
34 </div>
34 </div>
35
35
36 </div>
36 </div>
37 </div>
37 </div>
38
38
39 <script type="application/javascript">
39 <script type="application/javascript">
40 /** because im not creating a custom element for this page
40 /** because im not creating a custom element for this page
41 * we need to push the function onto the dom-template
41 * we need to push the function onto the dom-template
42 * ideally we turn this into notification-settings elements
42 * ideally we turn this into notification-settings elements
43 * then it will be cleaner
43 * then it will be cleaner
44 */
44 */
45 var ctrlr = $('#notificationsPage')[0];
45 var ctrlr = $('#notificationsPage')[0];
46 ctrlr.toggleNotifications = function(event){
46 ctrlr.toggleNotifications = function(event){
47 var ajax = $('#toggleNotifications')[0];
47 var ajax = $('#toggleNotifications')[0];
48 ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}
48 ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}
49 ajax.body = {notification_status:event.target.active};
49 ajax.body = {notification_status:event.target.active};
50 ajax.generateRequest();
50 ajax.generateRequest();
51 };
51 };
52 ctrlr.handleNotifications = function(event){
52 ctrlr.handleNotifications = function(event){
53 $('#live-notifications')[0].checked = event.detail.response;
53 $('#live-notifications')[0].checked = event.detail.response;
54 };
54 };
55
55
56 function checkBrowserStatus(){
56 function checkBrowserStatus(){
57 var browserStatus = 'Unknown';
57 var browserStatus = 'Unknown';
58
58
59 if (!("Notification" in window)) {
59 if (!("Notification" in window)) {
60 browserStatus = 'Not supported'
60 browserStatus = 'Not supported'
61 }
61 }
62 else if(Notification.permission === 'denied'){
62 else if(Notification.permission === 'denied'){
63 browserStatus = 'Denied';
63 browserStatus = 'Denied';
64 $('.flash_msg').append('<div class="alert alert-error">Notifications are blocked on browser level - you need to enable them in your browser settings.</div>')
64 $('.flash_msg').append('<div class="alert alert-error">Notifications are blocked on browser level - you need to enable them in your browser settings.</div>')
65 }
65 }
66 else if(Notification.permission === 'granted'){
66 else if(Notification.permission === 'granted'){
67 browserStatus = 'Allowed';
67 browserStatus = 'Allowed';
68 }
68 }
69
69
70 $('#browser-notification-status').text(browserStatus);
70 $('#browser-notification-status').text(browserStatus);
71 };
71 };
72
72
73 checkBrowserStatus();
73 checkBrowserStatus();
74
74
75 $('#test-notification').on('click', function(e){
75 $('#test-notification').on('click', function(e){
76 var levels = ['info', 'error', 'warning', 'success'];
76 var levels = ['info', 'error', 'warning', 'success'];
77 var level = levels[Math.floor(Math.random()*levels.length)];
77 var level = levels[Math.floor(Math.random()*levels.length)];
78 var payload = {
78 var payload = {
79 message: {
79 message: {
80 message: 'This is a test notification.',
80 message: 'This is a test notification.',
81 level: level,
81 level: level,
82 testMessage: true
82 force: true
83 }
83 }
84 };
84 };
85 $.Topic('/notifications').publish(payload);
85 $.Topic('/notifications').publish(payload);
86 })
86 })
87 </script>
87 </script>
88 </template>
88 </template>
General Comments 0
You need to be logged in to leave comments. Login now