##// END OF EJS Templates
notifications: removed polymer from notifications page.
marcink -
r4029:d99c3ed4 default
parent child Browse files
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,86 +41,91 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-tap="testNotifications">Test flash message</button>
54 <button class="btn" id="test-notification-live" on-tap="testNotificationsLive">Test live notification</button>
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 <h4 id="test-response"></h4>
48 <h4 id="test-response"></h4>
57 49
58 50 </div>
59 51
60
61
62 52 </div>
63 53
54 <script type="text/javascript">
64 55
65 </template>
66 </dom-bind>
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 })
76 };
77
78 this.testNotifications = function (elem) {
79 var levels = ['info', 'error', 'warning', 'success'];
80 var level = levels[Math.floor(Math.random() * levels.length)];
81
82 function getRandomArbitrary(min, max) {
83 return parseInt(Math.random() * (max - min) + min);
84 }
67 85
68 <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 ctrlr.toggleNotifications = function(event){
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;
86 function shuffle(a) {
87 var j, x, i;
88 for (i = a.length; i; i--) {
89 j = Math.floor(Math.random() * i);
90 x = a[i - 1];
91 a[i - 1] = a[j];
92 a[j] = x;
93 }
94 }
95
96 var wordDb = [
97 "Leela,", "Bender,", "we are", "going", "grave", "robbing.",
98 "Oh,", "I", "think", "we", "should", "just", "stay", "friends.",
99 "got", "to", "find", "a", "way", "to", "escape", "the", "horrible",
100 "ravages", "of", "youth.", "Suddenly,", "going", "to",
101 "the", "bathroom", "like", "clockwork,", "every", "three",
102 "hours.", "And", "those", "jerks", "at", "Social", "Security",
103 "stopped", "sending", "me", "checks.", "Now", "have", "to", "pay"
104 ];
105 shuffle(wordDb);
106 wordDb = wordDb.slice(0, getRandomArbitrary(3, wordDb.length));
107 var randomMessage = wordDb.join(" ");
108 var payload = {
109 message: {
110 message: randomMessage + " " + new Date(),
111 level: level,
112 force: true
113 }
114 };
115 $.Topic('/notifications').publish(payload);
116 };
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 })
127 };
83 128 };
84 129
85 ctrlr.testNotifications = function(event){
86 var levels = ['info', 'error', 'warning', 'success'];
87 var level = levels[Math.floor(Math.random()*levels.length)];
88 function getRandomArbitrary(min, max) {
89 return parseInt(Math.random() * (max - min) + min);
90 }
91 function shuffle(a) {
92 var j, x, i;
93 for (i = a.length; i; i--) {
94 j = Math.floor(Math.random() * i);
95 x = a[i - 1];
96 a[i - 1] = a[j];
97 a[j] = x;
98 }
99 }
100 var wordDb = [
101 "Leela,", "Bender,", "we are", "going", "grave", "robbing.",
102 "Oh,", "I", "think", "we", "should", "just", "stay", "friends.",
103 "got", "to", "find", "a", "way", "to", "escape", "the", "horrible",
104 "ravages", "of", "youth.", "Suddenly,", "going", "to",
105 "the", "bathroom", "like", "clockwork,", "every", "three",
106 "hours.", "And", "those", "jerks", "at", "Social", "Security",
107 "stopped", "sending", "me", "checks.", "Now", "have", "to", "pay"
108 ];
109 shuffle(wordDb);
110 wordDb = wordDb.slice(0, getRandomArbitrary(3, wordDb.length));
111 var randomMessage = wordDb.join(" ");
112 var payload = {
113 message: {
114 message: randomMessage + " " + new Date(),
115 level: level,
116 force: true
117 }
118 };
119 $.Topic('/notifications').publish(payload);
120 };
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();
126 };
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 };
132
130 notificationsController = new NotificationsController();
133 131 </script>
General Comments 0
You need to be logged in to leave comments. Login now