Show More
@@ -1,21 +1,3 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 | 2 | <div class="panel panel-default"> |
|
21 | 3 | <div class="panel-heading"> |
@@ -34,7 +16,18 b'' | |||
|
34 | 16 | <label for="new_email">${_('Notifications Status')}:</label> |
|
35 | 17 | </div> |
|
36 | 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 | 31 | </div> |
|
39 | 32 | </div> |
|
40 | 33 | </div> |
@@ -48,46 +41,48 b'' | |||
|
48 | 41 | </div> |
|
49 | 42 | <div class="panel-body"> |
|
50 | 43 | |
|
51 | ||
|
52 | 44 | <div style="padding: 0px 0px 20px 0px"> |
|
53 |
<button class="btn" id="test-notification" on |
|
|
54 |
<button class="btn" id="test-notification-live" on |
|
|
45 | <button class="btn" id="test-notification" onclick="notificationsController.testNotifications(); return false">Test flash message</button> | |
|
46 | <button class="btn" id="test-notification-live" onclick="notificationsController.testNotificationsLive(); return false">Test live notification</button> | |
|
55 | 47 | </div> |
|
56 | 48 |
|
|
57 | 49 | |
|
58 | 50 | </div> |
|
59 | 51 | |
|
60 | ||
|
61 | ||
|
62 | 52 | </div> |
|
63 | 53 | |
|
64 | ||
|
65 | </template> | |
|
66 | </dom-bind> | |
|
67 | ||
|
68 | 54 | <script type="text/javascript"> |
|
69 | /** because im not creating a custom element for this page | |
|
70 | * we need to push the function onto the dom-template | |
|
71 | * ideally we turn this into notification-settings elements | |
|
72 | * then it will be cleaner | |
|
73 | */ | |
|
74 | var ctrlr = $('#notificationsPage')[0]; | |
|
75 |
|
|
|
76 | var ajax = $('#toggleNotifications')[0]; | |
|
77 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; | |
|
78 | ajax.body = {notification_status:event.target.active}; | |
|
79 | ajax.generateRequest(); | |
|
80 | }; | |
|
81 | ctrlr.handleNotifications = function(event){ | |
|
82 | $('#live-notifications')[0].checked = event.detail.response; | |
|
55 | ||
|
56 | var NotificationsController = function () { | |
|
57 | var self = this; | |
|
58 | this.$testResponse = $('#test-response'); | |
|
59 | this.$notificationPage = $('#notificationsPage'); | |
|
60 | ||
|
61 | this.toggleNotifications = function (elem) { | |
|
62 | var $elem = $(elem); | |
|
63 | ||
|
64 | var post_data = {'val': $elem.val(), 'csrf_token': CSRF_TOKEN}; | |
|
65 | var url = pyroutes.url('my_account_notifications_toggle_visibility'); | |
|
66 | ||
|
67 | ajaxPOST(url, post_data, function (resp) { | |
|
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 | 79 | var levels = ['info', 'error', 'warning', 'success']; |
|
87 | 80 | var level = levels[Math.floor(Math.random()*levels.length)]; |
|
81 | ||
|
88 | 82 | function getRandomArbitrary(min, max) { |
|
89 | 83 | return parseInt(Math.random() * (max - min) + min); |
|
90 | 84 | } |
|
85 | ||
|
91 | 86 | function shuffle(a) { |
|
92 | 87 | var j, x, i; |
|
93 | 88 | for (i = a.length; i; i--) { |
@@ -97,6 +92,7 b'' | |||
|
97 | 92 | a[j] = x; |
|
98 | 93 | } |
|
99 | 94 | } |
|
95 | ||
|
100 | 96 | var wordDb = [ |
|
101 | 97 | "Leela,", "Bender,", "we are", "going", "grave", "robbing.", |
|
102 | 98 | "Oh,", "I", "think", "we", "should", "just", "stay", "friends.", |
@@ -118,16 +114,18 b'' | |||
|
118 | 114 | }; |
|
119 | 115 | $.Topic('/notifications').publish(payload); |
|
120 | 116 | }; |
|
121 | ctrlr.testNotificationsLive = function(event){ | |
|
122 | var ajax = $('#sendTestNotification')[0]; | |
|
123 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; | |
|
124 | ajax.body = {test_msg: 'Hello !'}; | |
|
125 | ajax.generateRequest(); | |
|
117 | ||
|
118 | this.testNotificationsLive = function (event) { | |
|
119 | var post_data = {'test_msg': 'Hello Server', 'csrf_token': CSRF_TOKEN}; | |
|
120 | var url = pyroutes.url('my_account_notifications_test_channelstream'); | |
|
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 | 131 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now