Show More
@@ -1,133 +1,131 b'' | |||||
1 | <dom-bind id="notificationsPage"> |
|
|||
2 | <template> |
|
|||
3 | <iron-ajax id="toggleNotifications" |
|
|||
4 | method="post" |
|
|||
5 | url="${h.route_path('my_account_notifications_toggle_visibility')}" |
|
|||
6 | content-type="application/json" |
|
|||
7 | loading="{{changeNotificationsLoading}}" |
|
|||
8 | on-response="handleNotifications" |
|
|||
9 | handle-as="json"> |
|
|||
10 | </iron-ajax> |
|
|||
11 |
|
||||
12 | <iron-ajax id="sendTestNotification" |
|
|||
13 | method="post" |
|
|||
14 | url="${h.route_path('my_account_notifications_test_channelstream')}" |
|
|||
15 | content-type="application/json" |
|
|||
16 | on-response="handleTestNotification" |
|
|||
17 | handle-as="json"> |
|
|||
18 | </iron-ajax> |
|
|||
19 |
|
1 | |||
20 | <div class="panel panel-default"> |
|
2 | <div class="panel panel-default"> | |
21 | <div class="panel-heading"> |
|
3 | <div class="panel-heading"> | |
22 | <h3 class="panel-title">${_('Your Live Notification Settings')}</h3> |
|
4 | <h3 class="panel-title">${_('Your Live Notification Settings')}</h3> | |
23 | </div> |
|
5 | </div> | |
24 | <div class="panel-body"> |
|
6 | <div class="panel-body"> | |
25 |
|
7 | |||
26 | <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p> |
|
8 | <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p> | |
27 |
|
9 | |||
28 | <p class="hidden">Status of browser notifications permission: <strong id="browser-notification-status"></strong></p> |
|
10 | <p class="hidden">Status of browser notifications permission: <strong id="browser-notification-status"></strong></p> | |
29 |
|
11 | |||
30 | <div class="form"> |
|
12 | <div class="form"> | |
31 | <div class="fields"> |
|
13 | <div class="fields"> | |
32 | <div class="field"> |
|
14 | <div class="field"> | |
33 | <div class="label"> |
|
15 | <div class="label"> | |
34 | <label for="new_email">${_('Notifications Status')}:</label> |
|
16 | <label for="new_email">${_('Notifications Status')}:</label> | |
35 | </div> |
|
17 | </div> | |
36 | <div class="checkboxes"> |
|
18 | <div class="checkboxes"> | |
37 | <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> |
|
19 | ||
|
20 | <div class="form-check"> | |||
|
21 | <label class="form-check-label"> | |||
|
22 | <input type="radio" name="notification" id="notificationEnable1" value="1" onchange="notificationsController.toggleNotifications(this);return false" ${'checked' if c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}> | |||
|
23 | ${_('Enabled')} | |||
|
24 | </label> | |||
|
25 | <label class="form-check-label"> | |||
|
26 | <input type="radio" name="notification" id="notificationEnable2" value="0" onchange="notificationsController.toggleNotifications(this);return false" ${'checked' if not c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}> | |||
|
27 | ${_('Disabled')} | |||
|
28 | </label> | |||
|
29 | </div> | |||
|
30 | ||||
38 | </div> |
|
31 | </div> | |
39 | </div> |
|
32 | </div> | |
40 | </div> |
|
33 | </div> | |
41 | </div> |
|
34 | </div> | |
42 | </div> |
|
35 | </div> | |
43 | </div> |
|
36 | </div> | |
44 |
|
37 | |||
45 | <div class="panel panel-default"> |
|
38 | <div class="panel panel-default"> | |
46 | <div class="panel-heading"> |
|
39 | <div class="panel-heading"> | |
47 | <h3 class="panel-title">${_('Test Notifications')}</h3> |
|
40 | <h3 class="panel-title">${_('Test Notifications')}</h3> | |
48 | </div> |
|
41 | </div> | |
49 | <div class="panel-body"> |
|
42 | <div class="panel-body"> | |
50 |
|
43 | |||
51 |
|
||||
52 | <div style="padding: 0px 0px 20px 0px"> |
|
44 | <div style="padding: 0px 0px 20px 0px"> | |
53 |
<button class="btn" id="test-notification" on |
|
45 | <button class="btn" id="test-notification" onclick="notificationsController.testNotifications(); return false">Test flash message</button> | |
54 |
<button class="btn" id="test-notification-live" on |
|
46 | <button class="btn" id="test-notification-live" onclick="notificationsController.testNotificationsLive(); return false">Test live notification</button> | |
55 | </div> |
|
47 | </div> | |
56 |
|
|
48 | <h4 id="test-response"></h4> | |
57 |
|
49 | |||
58 | </div> |
|
50 | </div> | |
59 |
|
51 | |||
60 |
|
||||
61 |
|
||||
62 | </div> |
|
52 | </div> | |
63 |
|
53 | |||
64 |
|
||||
65 | </template> |
|
|||
66 | </dom-bind> |
|
|||
67 |
|
||||
68 | <script type="text/javascript"> |
|
54 | <script type="text/javascript"> | |
69 | /** because im not creating a custom element for this page |
|
55 | ||
70 | * we need to push the function onto the dom-template |
|
56 | var NotificationsController = function () { | |
71 | * ideally we turn this into notification-settings elements |
|
57 | var self = this; | |
72 | * then it will be cleaner |
|
58 | this.$testResponse = $('#test-response'); | |
73 | */ |
|
59 | this.$notificationPage = $('#notificationsPage'); | |
74 | var ctrlr = $('#notificationsPage')[0]; |
|
60 | ||
75 |
|
|
61 | this.toggleNotifications = function (elem) { | |
76 | var ajax = $('#toggleNotifications')[0]; |
|
62 | var $elem = $(elem); | |
77 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; |
|
63 | ||
78 | ajax.body = {notification_status:event.target.active}; |
|
64 | var post_data = {'val': $elem.val(), 'csrf_token': CSRF_TOKEN}; | |
79 | ajax.generateRequest(); |
|
65 | var url = pyroutes.url('my_account_notifications_toggle_visibility'); | |
80 | }; |
|
66 | ||
81 | ctrlr.handleNotifications = function(event){ |
|
67 | ajaxPOST(url, post_data, function (resp) { | |
82 | $('#live-notifications')[0].checked = event.detail.response; |
|
68 | if (resp === true) { | |
|
69 | $('input[name="notification"]').filter('[value="1"]').prop('checked', true); | |||
|
70 | $('input[name="notification"]').filter('[value="0"]').prop('checked', false); | |||
|
71 | } else { | |||
|
72 | $('input[name="notification"]').filter('[value="1"]').prop('checked', false); | |||
|
73 | $('input[name="notification"]').filter('[value="0"]').prop('checked', true); | |||
|
74 | } | |||
|
75 | }) | |||
83 | }; |
|
76 | }; | |
84 |
|
77 | |||
85 |
|
|
78 | this.testNotifications = function (elem) { | |
86 | var levels = ['info', 'error', 'warning', 'success']; |
|
79 | var levels = ['info', 'error', 'warning', 'success']; | |
87 | var level = levels[Math.floor(Math.random()*levels.length)]; |
|
80 | var level = levels[Math.floor(Math.random() * levels.length)]; | |
|
81 | ||||
88 | function getRandomArbitrary(min, max) { |
|
82 | function getRandomArbitrary(min, max) { | |
89 | return parseInt(Math.random() * (max - min) + min); |
|
83 | return parseInt(Math.random() * (max - min) + min); | |
90 | } |
|
84 | } | |
|
85 | ||||
91 | function shuffle(a) { |
|
86 | function shuffle(a) { | |
92 | var j, x, i; |
|
87 | var j, x, i; | |
93 | for (i = a.length; i; i--) { |
|
88 | for (i = a.length; i; i--) { | |
94 | j = Math.floor(Math.random() * i); |
|
89 | j = Math.floor(Math.random() * i); | |
95 | x = a[i - 1]; |
|
90 | x = a[i - 1]; | |
96 | a[i - 1] = a[j]; |
|
91 | a[i - 1] = a[j]; | |
97 | a[j] = x; |
|
92 | a[j] = x; | |
98 | } |
|
93 | } | |
99 | } |
|
94 | } | |
|
95 | ||||
100 | var wordDb = [ |
|
96 | var wordDb = [ | |
101 | "Leela,", "Bender,", "we are", "going", "grave", "robbing.", |
|
97 | "Leela,", "Bender,", "we are", "going", "grave", "robbing.", | |
102 | "Oh,", "I", "think", "we", "should", "just", "stay", "friends.", |
|
98 | "Oh,", "I", "think", "we", "should", "just", "stay", "friends.", | |
103 | "got", "to", "find", "a", "way", "to", "escape", "the", "horrible", |
|
99 | "got", "to", "find", "a", "way", "to", "escape", "the", "horrible", | |
104 | "ravages", "of", "youth.", "Suddenly,", "going", "to", |
|
100 | "ravages", "of", "youth.", "Suddenly,", "going", "to", | |
105 | "the", "bathroom", "like", "clockwork,", "every", "three", |
|
101 | "the", "bathroom", "like", "clockwork,", "every", "three", | |
106 | "hours.", "And", "those", "jerks", "at", "Social", "Security", |
|
102 | "hours.", "And", "those", "jerks", "at", "Social", "Security", | |
107 | "stopped", "sending", "me", "checks.", "Now", "have", "to", "pay" |
|
103 | "stopped", "sending", "me", "checks.", "Now", "have", "to", "pay" | |
108 | ]; |
|
104 | ]; | |
109 | shuffle(wordDb); |
|
105 | shuffle(wordDb); | |
110 | wordDb = wordDb.slice(0, getRandomArbitrary(3, wordDb.length)); |
|
106 | wordDb = wordDb.slice(0, getRandomArbitrary(3, wordDb.length)); | |
111 | var randomMessage = wordDb.join(" "); |
|
107 | var randomMessage = wordDb.join(" "); | |
112 | var payload = { |
|
108 | var payload = { | |
113 | message: { |
|
109 | message: { | |
114 | message: randomMessage + " " + new Date(), |
|
110 | message: randomMessage + " " + new Date(), | |
115 | level: level, |
|
111 | level: level, | |
116 | force: true |
|
112 | force: true | |
117 | } |
|
113 | } | |
118 | }; |
|
114 | }; | |
119 | $.Topic('/notifications').publish(payload); |
|
115 | $.Topic('/notifications').publish(payload); | |
120 | }; |
|
116 | }; | |
121 | ctrlr.testNotificationsLive = function(event){ |
|
117 | ||
122 | var ajax = $('#sendTestNotification')[0]; |
|
118 | this.testNotificationsLive = function (event) { | |
123 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; |
|
119 | var post_data = {'test_msg': 'Hello Server', 'csrf_token': CSRF_TOKEN}; | |
124 | ajax.body = {test_msg: 'Hello !'}; |
|
120 | var url = pyroutes.url('my_account_notifications_test_channelstream'); | |
125 | ajax.generateRequest(); |
|
121 | ||
|
122 | ajaxPOST(url, post_data, function (resp) { | |||
|
123 | resp = resp['response'] || 'no reply form server'; | |||
|
124 | self.$testResponse.html(resp); | |||
|
125 | self.$testResponse.show(); | |||
|
126 | }) | |||
126 | }; |
|
127 | }; | |
127 | ctrlr.handleTestNotification = function(event){ |
|
|||
128 | var reply = event.detail.response.response; |
|
|||
129 | reply = reply || 'no reply form server'; |
|
|||
130 | $('#test-response').html(reply); |
|
|||
131 | }; |
|
128 | }; | |
132 |
|
129 | |||
|
130 | notificationsController = new NotificationsController(); | |||
133 | </script> |
|
131 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now