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 | <div class="panel panel-default"> |
|
2 | <div class="panel panel-default"> | |
21 | <div class="panel-heading"> |
|
3 | <div class="panel-heading"> | |
@@ -34,7 +16,18 b'' | |||||
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> | |
@@ -48,46 +41,48 b'' | |||||
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--) { | |
@@ -97,6 +92,7 b'' | |||||
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.", | |
@@ -118,16 +114,18 b'' | |||||
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