15
15
* specific language governing permissions and limitations
16
16
* under the License.
17
17
*/
18
- var modalPopup = '.wr-modalpopup' ,
19
- modalPopupContainer = modalPopup + ' .modalpopup-container' ,
20
- modalPopupContent = modalPopup + ' .modalpopup-content' ;
21
- function openCollapsedNav ( ) {
22
- $ ( ".wr-hidden-nav-toggle-btn" ) . addClass ( "active" ) ;
23
- $ ( "#hiddenNav" ) . slideToggle ( "slideDown" , function ( ) {
24
- if ( $ ( this ) . css ( "display" ) == "none" ) {
25
- $ ( ".wr-hidden-nav-toggle-btn" ) . removeClass ( "active" ) ;
26
- }
27
- } ) ;
28
- }
29
18
19
+ var modalPopup = ".wr-modalpopup" ,
20
+ modalPopupContainer = modalPopup + " .modalpopup-container" ,
21
+ modalPopupContent = modalPopup + " .modalpopup-content" ;
22
+
23
+ //function openCollapsedNav() {
24
+ // $(".wr-hidden-nav-toggle-btn").addClass("active");
25
+ // $("#hiddenNav").slideToggle("slideDown", function () {
26
+ // if ($(this).css("display") == "none") {
27
+ // $(".wr-hidden-nav-toggle-btn").removeClass("active");
28
+ // }
29
+ // });
30
+ //}
30
31
31
32
/*
32
33
* set popup maximum height function.
@@ -56,7 +57,9 @@ function hidePopup() {
56
57
$ ( modalPopup ) . hide ( ) ;
57
58
}
58
59
59
-
60
+ /*
61
+ * QR-code generation function.
62
+ */
60
63
function generateQRCode ( qrCodeClass ) {
61
64
var enrollmentURL = $ ( "#qr-code-modal" ) . data ( "enrollment-url" ) ;
62
65
$ ( qrCodeClass ) . qrcode ( {
@@ -72,74 +75,85 @@ function toggleEnrollment() {
72
75
showPopup ( ) ;
73
76
}
74
77
75
- var showNotificationCount = function ( data ) {
76
- if ( data ) {
77
- data = JSON . parse ( data ) ;
78
- if ( data . length > 0 ) {
79
- $ ( "#notification-bubble" ) . html ( data . length ) ;
78
+ var updateNotificationCount = function ( data , jqXHR ) {
79
+ if ( jqXHR . status == 200 && data ) {
80
+ var responsePayload = JSON . parse ( data ) ;
81
+ var newNotificationsCount = responsePayload . devices . length ;
82
+ if ( newNotificationsCount > 0 ) {
83
+ $ ( "#notification-bubble" ) . html ( newNotificationsCount ) ;
80
84
} else {
81
- hideNotificationCount ( ) ;
85
+ $ ( "#notification-bubble" ) . html ( "Error" ) ;
82
86
}
83
- } else {
84
- hideNotificationCount ( ) ;
85
87
}
86
88
} ;
87
89
88
- function loadNotificationCount ( ) {
90
+ function loadNotificationsPanel ( ) {
89
91
if ( "true" == $ ( "#right-sidebar" ) . attr ( "is-authorized" ) ) {
90
- var serviceURL = "/mdm-admin/notifications/ NEW" ;
91
- invokerUtil . get ( serviceURL , showNotificationCount , hideNotificationCount ) ;
92
- loadNotifications ( ) ;
92
+ var serviceURL = "/api/device-mgt/v1.0/notifications?status= NEW" ;
93
+ invokerUtil . get ( serviceURL , updateNotificationCount , hideNotificationCount ) ;
94
+ loadNewNotifications ( ) ;
93
95
} else {
94
96
$ ( "#notification-bubble-wrapper" ) . remove ( ) ;
95
97
}
96
98
}
97
99
98
- function hideNotificationCount ( ) {
99
- $ ( "#notification-bubble" ) . hide ( ) ;
100
+ function hideNotificationCount ( jqXHR ) {
101
+ if ( jqXHR . status == 404 ) {
102
+ // this means "no new notifications to show"
103
+ $ ( "#notification-bubble" ) . hide ( ) ;
104
+ } else {
105
+ $ ( "#notification-bubble" ) . html ( "Error" ) ;
106
+ }
100
107
}
101
108
102
- function loadNotifications ( ) {
103
- if ( "true" == $ ( "#right-sidebar" ) . attr ( "is-authorized" ) ) {
104
- var notificationListing = $ ( "#notifications" ) ;
105
- var notificationListingSrc = notificationListing . attr ( "src" ) ;
106
- var currentUser = notificationListing . data ( "currentUser" ) ;
107
- $ . template ( "notification-listing" , notificationListingSrc , function ( template ) {
108
- var serviceURL = "/mdm-admin/notifications/NEW" ;
109
- var successCallback = function ( data ) {
110
- var viewModel = { } ;
111
- data = JSON . parse ( data ) ;
112
- viewModel . notifications = data ;
113
- if ( data . length > 0 ) {
114
- var content = template ( viewModel ) ;
115
- $ ( ".sidebar-messages" ) . html ( content ) ;
109
+ function loadNewNotifications ( ) {
110
+ var messageSideBar = ".sidebar-messages" ;
111
+ if ( $ ( "#right-sidebar" ) . attr ( "is-authorized" ) == "true" ) {
112
+ var notifications = $ ( "#notifications" ) ;
113
+ var currentUser = notifications . data ( "currentUser" ) ;
114
+
115
+ $ . template ( "notification-listing" , notifications . attr ( "src" ) , function ( template ) {
116
+ var serviceURL = "/api/device-mgt/v1.0/notifications?status=NEW" ;
117
+
118
+ var successCallback = function ( data , textStatus , jqXHR ) {
119
+ if ( jqXHR . status == 200 && data ) {
120
+ var viewModel = { } ;
121
+ var responsePayload = JSON . parse ( data ) ;
122
+
123
+ if ( responsePayload . devices && responsePayload . devices . length > 0 ) {
124
+ viewModel . notifications = responsePayload . devices ;
125
+ $ ( messageSideBar ) . html ( template ( viewModel ) ) ;
126
+ } else {
127
+ $ ( messageSideBar ) . html ( "<h4 class='text-center'>Error in getting new notifications.</h4>" ) ;
128
+ }
129
+ }
130
+ } ;
131
+
132
+ var errorCallback = function ( jqXHR ) {
133
+ if ( jqXHR . status = 404 ) {
134
+ $ ( messageSideBar ) . html ( "<h4 class='text-center'>No new notifications found...</h4>" ) ;
116
135
} else {
117
- var content = "<h4 class='text-center' >You have no new notifications</a></h4>" ;
118
- $ ( ".sidebar-messages" ) . html ( content ) ;
136
+ $ ( messageSideBar ) . html ( "<h4 class ='message-danger'>Unexpected error occurred while trying " +
137
+ "to retrieve any new notifications.</h4>" ) ;
119
138
}
120
139
} ;
121
- invokerUtil . get ( serviceURL , successCallback , function ( message ) {
122
- var content = "<p>Unexpected error occurred while notification listing </p>" ;
123
- $ ( ".sidebar-messages" ) . html ( content ) ;
124
- } ) ;
140
+ invokerUtil . get ( serviceURL , successCallback , errorCallback ) ;
125
141
} ) ;
126
142
} else {
127
- var content = "<h4 class ='message-danger'>You are not authorized to view notifications</h4>" ;
128
- $ ( ".sidebar-messages" ) . html ( content ) ;
143
+ $ ( messageSideBar ) . html ( "<h4 class ='message-danger'>You are not authorized to view notifications</h4>" ) ;
129
144
}
130
145
}
131
146
132
147
/**
133
- * Sidebar function
148
+ * Toggle function for
149
+ * notification listing sidebar.
134
150
* @return {Null }
135
151
*/
136
152
$ . sidebar_toggle = function ( action , target , container ) {
137
153
var elem = '[data-toggle=sidebar]' ,
138
154
button ,
139
- container ,
140
- conrainerOffsetLeft ,
141
- conrainerOffsetRight ,
142
- target ,
155
+ containerOffsetLeft ,
156
+ containerOffsetRight ,
143
157
targetOffsetLeft ,
144
158
targetOffsetRight ,
145
159
targetWidth ,
@@ -150,18 +164,20 @@ $.sidebar_toggle = function (action, target, container) {
150
164
151
165
var sidebar_window = {
152
166
update : function ( target , container , button ) {
153
- conrainerOffsetLeft = $ ( container ) . data ( 'offset-left' ) ? $ ( container ) . data ( 'offset-left' ) : 0 ,
154
- conrainerOffsetRight = $ ( container ) . data ( 'offset-right' ) ? $ ( container ) . data ( 'offset-right' ) : 0 ,
155
- targetOffsetLeft = $ ( target ) . data ( 'offset-left' ) ? $ ( target ) . data ( 'offset-left' ) : 0 ,
156
- targetOffsetRight = $ ( target ) . data ( 'offset-right' ) ? $ ( target ) . data ( 'offset-right' ) : 0 ,
157
- targetWidth = $ ( target ) . data ( 'width' ) ,
158
- targetSide = $ ( target ) . data ( "side" ) ,
159
- pushType = $ ( container ) . parent ( ) . is ( 'body' ) == true ? 'padding' : 'margin' ;
167
+ containerOffsetLeft = $ ( container ) . data ( 'offset-left' ) ? $ ( container ) . data ( 'offset-left' ) : 0 ;
168
+ containerOffsetRight = $ ( container ) . data ( 'offset-right' ) ? $ ( container ) . data ( 'offset-right' ) : 0 ;
169
+ targetOffsetLeft = $ ( target ) . data ( 'offset-left' ) ? $ ( target ) . data ( 'offset-left' ) : 0 ;
170
+ targetOffsetRight = $ ( target ) . data ( 'offset-right' ) ? $ ( target ) . data ( 'offset-right' ) : 0 ;
171
+ targetWidth = $ ( target ) . data ( 'width' ) ;
172
+ targetSide = $ ( target ) . data ( "side" ) ;
173
+ pushType = $ ( container ) . parent ( ) . is ( 'body' ) == true ? 'padding' : 'margin' ;
174
+
160
175
if ( button !== undefined ) {
161
176
relationship = button . attr ( 'rel' ) ? button . attr ( 'rel' ) : '' ;
162
177
buttonParent = $ ( button ) . parent ( ) ;
163
178
}
164
179
} ,
180
+
165
181
show : function ( ) {
166
182
if ( $ ( target ) . data ( 'sidebar-fixed' ) == true ) {
167
183
$ ( target ) . height ( $ ( window ) . height ( ) - $ ( target ) . data ( 'fixed-offset' ) ) ;
@@ -206,6 +222,7 @@ $.sidebar_toggle = function (action, target, container) {
206
222
}
207
223
$ ( target ) . trigger ( 'shown.sidebar' ) ;
208
224
} ,
225
+
209
226
hide : function ( ) {
210
227
$ ( target ) . trigger ( 'hide.sidebar' ) ;
211
228
$ ( target ) . removeClass ( 'toggled' ) ;
@@ -252,8 +269,9 @@ $.sidebar_toggle = function (action, target, container) {
252
269
sidebar_window . hide ( ) ;
253
270
}
254
271
// binding click function
255
- $ ( 'body' ) . off ( 'click' , elem ) ;
256
- $ ( 'body' ) . on ( 'click' , elem , function ( e ) {
272
+ var body = 'body' ;
273
+ $ ( body ) . off ( 'click' , elem ) ;
274
+ $ ( body ) . on ( 'click' , elem , function ( e ) {
257
275
e . preventDefault ( ) ;
258
276
button = $ ( this ) ;
259
277
container = button . data ( 'container' ) ;
@@ -322,13 +340,15 @@ $.fn.collapse_nav_sub = function () {
322
340
} ;
323
341
324
342
$ ( document ) . ready ( function ( ) {
325
- loadNotificationCount ( ) ;
343
+ loadNotificationsPanel ( ) ;
326
344
$ . sidebar_toggle ( ) ;
327
345
328
- $ ( "#right-sidebar" ) . on ( "click" , ".new-notification" , function ( e ) {
346
+ $ ( "#right-sidebar" ) . on ( "click" , ".new-notification" , function ( ) {
329
347
var notificationId = $ ( this ) . data ( "id" ) ;
330
348
var redirectUrl = $ ( this ) . data ( "url" ) ;
331
349
var markAsReadNotificationsAPI = "/mdm-admin/notifications/" + notificationId + "/CHECKED" ;
350
+ var messageSideBar = ".sidebar-messages" ;
351
+
332
352
invokerUtil . put (
333
353
markAsReadNotificationsAPI ,
334
354
null ,
@@ -337,12 +357,11 @@ $(document).ready(function () {
337
357
if ( data . statusCode == responseCodes [ "ACCEPTED" ] ) {
338
358
location . href = redirectUrl ;
339
359
}
340
- } , function ( data ) {
360
+ } , function ( ) {
341
361
var content = "<li class='message message-danger'><h4><i class='icon fw fw-error'></i>Warning</h4>" +
342
- "<p>Unexpected error occurred while loading notification. Please refresh the page and" +
343
- " try again</p></li>" ;
344
- $ ( ".sidebar-messages" ) . html ( content ) ;
345
- $ ( ".sidebar-messages" ) . html ( content ) ;
362
+ "<p>Unexpected error occurred while loading notification. Please refresh the page and" +
363
+ " try again</p></li>" ;
364
+ $ ( messageSideBar ) . html ( content ) ;
346
365
}
347
366
) ;
348
367
} ) ;
0 commit comments