@@ -55,7 +55,7 @@ jQuery(document).ready(function() {
55
55
}
56
56
// /Stop ## Global AJAX Sender function ##################################
57
57
58
-
58
+ var checkEiBackend = false ;
59
59
// Check EI Backend Server Status ########################################
60
60
function checkEiBackendServer ( ) {
61
61
var EIConnBtn = document . getElementById ( "btnEIConnection" ) ;
@@ -74,14 +74,31 @@ jQuery(document).ready(function() {
74
74
// console.log("EI BACKEND ONLINE");
75
75
var green = "#00ff00" ;
76
76
EIConnBtn . style . background = green ;
77
+ checkEiBackend = true ;
77
78
} ,
78
79
complete : function ( XMLHttpRequest , textStatus ) {
79
80
}
80
81
} ) ;
81
82
82
83
}
83
-
84
-
84
+ function getInstanceInfo ( ) {
85
+ var text = document . getElementById ( 'info_text' ) ;
86
+ $ . ajax ( {
87
+ url : backendServiceUrl + "/information" ,
88
+ contentType : 'application/json;charset=UTF-8' ,
89
+ type : 'GET' ,
90
+ error : function ( XMLHttpRequest , textStatus , errorThrown ) {
91
+ document . getElementById ( 'info_text' ) . innerHTML = errorThrown ;
92
+ } ,
93
+ success : function ( data , textStatus , xhr ) {
94
+
95
+ } ,
96
+ complete : function ( XMLHttpRequest , textStatus ) {
97
+ var s = JSON . parse ( XMLHttpRequest . responseText ) ;
98
+ text . innerHTML = JSON . stringify ( s , undefined , 2 ) ;
99
+ }
100
+ } ) ;
101
+ }
85
102
// Check if EI Backend Server is online every X seconds
86
103
window . setInterval ( function ( ) {
87
104
checkEiBackendServer ( ) ;
@@ -95,6 +112,23 @@ jQuery(document).ready(function() {
95
112
96
113
checkEiBackendServer ( ) ;
97
114
} ) ;
115
+
116
+ $ ( '.container' ) . on ( 'click' , 'button.btnEIInstanceInfo' , function ( ) {
117
+ if ( checkEiBackend ) {
118
+ getInstanceInfo ( ) ;
119
+ var modal = document . getElementById ( 'modal_info' ) ;
120
+ var span = document . getElementsByClassName ( "close_instance" ) [ 0 ] ;
121
+ modal . style . display = "block" ;
122
+ span . onclick = function ( ) {
123
+ modal . style . display = "none" ;
124
+ }
125
+ window . onclick = function ( event ) {
126
+ if ( event . target == modal ) {
127
+ modal . style . display = "none" ;
128
+ } } } else {
129
+ alert ( "EI BACKEND OFFLINE" ) ;
130
+ }
131
+ } ) ;
98
132
// END OF EI Backend Server check #########################################
99
133
100
134
@@ -380,12 +414,49 @@ jQuery(document).ready(function() {
380
414
event . stopPropagation ( ) ;
381
415
event . preventDefault ( ) ;
382
416
383
- function validateSubscriptionFormat ( subscriptionFile ) {
417
+ function tryToCreateSubscription ( subscriptionJson ) {
384
418
// Send Subscription JSON file to Spring MVC
385
-
419
+ // AJAX Callback handling
420
+ var callback = {
421
+ beforeSend : function ( ) {
422
+ } ,
423
+ success : function ( data , textStatus ) {
424
+
425
+ var returnData = [ data ] ;
426
+ if ( returnData . length > 0 ) {
427
+ $ . jGrowl ( "Successful created subscription " + subscriptionJson . subscriptionName , {
428
+ sticky : false ,
429
+ theme : 'Error'
430
+ } ) ;
431
+ reload_table ( ) ;
432
+ }
433
+
434
+ } ,
435
+ error : function ( XMLHttpRequest , textStatus , errorThrown ) {
436
+
437
+ $ . jGrowl ( "Failed to create Subscription: " + subscriptionJson . subscriptionName + " Error: " + XMLHttpRequest . responseText , {
438
+ sticky : false ,
439
+ theme : 'Error'
440
+ } ) ;
441
+
442
+ } ,
443
+ complete : function ( ) {
444
+ }
445
+ } ;
446
+
447
+ // Fetch Date and format
448
+ var now = new Date ( ) ;
449
+ var nowStr = now . format ( "isoDate" ) + ' ' + now . format ( "isoTime" ) ;
450
+
451
+ // Update property created with datetime (formatted)
452
+ subscriptionJson . created = String ( nowStr ) ;
453
+
454
+ // Perform AJAX
455
+ var ajaxHttpSender = new AjaxHttpSender ( ) ;
456
+ ajaxHttpSender . sendAjax ( backendServiceUrl + "/subscriptions" , "POST" , ko . toJSON ( subscriptionJson ) , callback ) ;
386
457
}
387
458
388
- function validateJsonandSubscriptionFormat ( subscriptionFile ) {
459
+ function validateJsonAndCreateSubscriptions ( subscriptionFile ) {
389
460
390
461
var reader = new FileReader ( ) ;
391
462
@@ -405,7 +476,10 @@ jQuery(document).ready(function() {
405
476
theme : 'Notify'
406
477
} ) ;
407
478
408
- validateSubscriptionFormat ( subscriptionFile ) ;
479
+ var subscriptionJsonList = JSON . parse ( fileContent ) ;
480
+ for ( i = 0 ; i < subscriptionJsonList . length ; i ++ ) {
481
+ tryToCreateSubscription ( subscriptionJsonList [ i ] ) ;
482
+ }
409
483
} ;
410
484
411
485
reader . readAsText ( subscriptionFile ) ;
@@ -430,7 +504,7 @@ jQuery(document).ready(function() {
430
504
// All other Web Browser
431
505
pom . onchange = function uploadFinished ( ) {
432
506
var subscriptionFile = pom . files [ 0 ] ;
433
- validateJsonandSubscriptionFormat ( subscriptionFile ) ;
507
+ validateJsonAndCreateSubscriptions ( subscriptionFile ) ;
434
508
} ;
435
509
436
510
if ( document . createEvent ) {
@@ -521,8 +595,12 @@ jQuery(document).ready(function() {
521
595
var indexToRemove = context . $index ( ) ;
522
596
523
597
// Removing Requirement(Condition), based on index position, from Requirement form in Add_Subscription window.
524
- vm . subscription ( ) [ 0 ] . requirements . splice ( indexToRemove , 1 ) ;
525
-
598
+ if ( indexToRemove > 0 ) {
599
+ vm . subscription ( ) [ 0 ] . requirements . splice ( indexToRemove , 1 ) ;
600
+ }
601
+ else {
602
+ $ . alert ( "You need to have atleast one Condition." ) ;
603
+ }
526
604
} ) ;
527
605
// /Stop ## Delete Condition ################################################
528
606
0 commit comments