@@ -361,12 +361,49 @@ $(document).ready(function() {
361
361
event . stopPropagation ( ) ;
362
362
event . preventDefault ( ) ;
363
363
364
- function validateSubscriptionFormat ( subscriptionFile ) {
364
+ function tryToCreateSubscription ( subscriptionJson ) {
365
365
// Send Subscription JSON file to Spring MVC
366
-
366
+ // AJAX Callback handling
367
+ var callback = {
368
+ beforeSend : function ( ) {
369
+ } ,
370
+ success : function ( data , textStatus ) {
371
+
372
+ var returnData = [ data ] ;
373
+ if ( returnData . length > 0 ) {
374
+ $ . jGrowl ( "Successful created subscription " + subscriptionJson . subscriptionName , {
375
+ sticky : false ,
376
+ theme : 'Error'
377
+ } ) ;
378
+ reload_table ( ) ;
379
+ }
380
+
381
+ } ,
382
+ error : function ( XMLHttpRequest , textStatus , errorThrown ) {
383
+
384
+ $ . jGrowl ( "Failed to create Subscription: " + subscriptionJson . subscriptionName + " Error: " + XMLHttpRequest . responseText , {
385
+ sticky : false ,
386
+ theme : 'Error'
387
+ } ) ;
388
+
389
+ } ,
390
+ complete : function ( ) {
391
+ }
392
+ } ;
393
+
394
+ // Fetch Date and format
395
+ var now = new Date ( ) ;
396
+ var nowStr = now . format ( "isoDate" ) + ' ' + now . format ( "isoTime" ) ;
397
+
398
+ // Update property created with datetime (formatted)
399
+ subscriptionJson . created = String ( nowStr ) ;
400
+
401
+ // Perform AJAX
402
+ var ajaxHttpSender = new AjaxHttpSender ( ) ;
403
+ ajaxHttpSender . sendAjax ( backendServiceUrl + "/subscriptions" , "POST" , ko . toJSON ( subscriptionJson ) , callback ) ;
367
404
}
368
405
369
- function validateJsonandSubscriptionFormat ( subscriptionFile ) {
406
+ function validateJsonAndCreateSubscriptions ( subscriptionFile ) {
370
407
371
408
var reader = new FileReader ( ) ;
372
409
@@ -386,7 +423,10 @@ $(document).ready(function() {
386
423
theme : 'Notify'
387
424
} ) ;
388
425
389
- validateSubscriptionFormat ( subscriptionFile ) ;
426
+ var subscriptionJsonList = JSON . parse ( fileContent ) ;
427
+ for ( i = 0 ; i < subscriptionJsonList . length ; i ++ ) {
428
+ tryToCreateSubscription ( subscriptionJsonList [ i ] ) ;
429
+ }
390
430
} ;
391
431
392
432
reader . readAsText ( subscriptionFile ) ;
@@ -411,7 +451,7 @@ $(document).ready(function() {
411
451
// All other Web Browser
412
452
pom . onchange = function uploadFinished ( ) {
413
453
var subscriptionFile = pom . files [ 0 ] ;
414
- validateJsonandSubscriptionFormat ( subscriptionFile ) ;
454
+ validateJsonAndCreateSubscriptions ( subscriptionFile ) ;
415
455
} ;
416
456
417
457
if ( document . createEvent ) {
0 commit comments