##// END OF EJS Templates
cleanup: removing unused checkBrowserStatus function
lisaq -
r834:07f543fe default
parent child Browse files
Show More
@@ -1,87 +1,70 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" on-tap="testNotifications">Test notification</a>
31 <a class="btn btn-default" id="test-notification" on-tap="testNotifications">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="text/javascript">
39 <script type="text/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(){
57 var browserStatus = 'Unknown';
58
59 if (!("Notification" in window)) {
60 browserStatus = 'Not supported'
61 }
62 else if(Notification.permission === '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>')
65 }
66 else if(Notification.permission === 'granted'){
67 browserStatus = 'Allowed';
68 }
69
70 $('#browser-notification-status').text(browserStatus);
71 }
72
73 ctrlr.testNotifications = function(event){
56 ctrlr.testNotifications = function(event){
74 var levels = ['info', 'error', 'warning', 'success'];
57 var levels = ['info', 'error', 'warning', 'success'];
75 var level = levels[Math.floor(Math.random()*levels.length)];
58 var level = levels[Math.floor(Math.random()*levels.length)];
76 var payload = {
59 var payload = {
77 message: {
60 message: {
78 message: 'This is a test notification.',
61 message: 'This is a test notification.',
79 level: level,
62 level: level,
80 force: true
63 force: true
81 }
64 }
82 };
65 };
83 $.Topic('/notifications').publish(payload);
66 $.Topic('/notifications').publish(payload);
84 }
67 }
85
68
86 </script>
69 </script>
87 </template>
70 </template>
General Comments 0
You need to be logged in to leave comments. Login now