@@ -74,6 +74,11 @@ jQuery(document).ready(function () {
74
74
backendStatus = true ;
75
75
} ,
76
76
complete : function ( ) {
77
+ if ( table != undefined && table . rows ( ) . data ( ) . length == 0 ) {
78
+ toggleCheckboxesDisabled ( true ) ;
79
+ } else {
80
+ toggleCheckboxesDisabled ( ! backendStatus ) ;
81
+ }
77
82
toggleOnBackendStatus ( backendStatus ) ;
78
83
setTimeout ( loadSubButtons , 800 ) ;
79
84
}
@@ -112,6 +117,20 @@ jQuery(document).ready(function () {
112
117
toggleButtonsDisabled ( ! backendStatus ) ;
113
118
}
114
119
120
+ function toggleCheckboxesDisabled ( disabled ) {
121
+ $ ( '#check-all' ) . prop ( "disabled" , disabled ) ;
122
+ $ ( '.data-check' ) . prop ( "disabled" , disabled ) ;
123
+ }
124
+
125
+ function toggleButtonsDisabled ( disabled ) {
126
+ $ ( '#addSubscription' ) . prop ( "disabled" , disabled ) ;
127
+ $ ( '#bulkDelete' ) . prop ( "disabled" , disabled ) ;
128
+ $ ( '#uploadSubscription' ) . prop ( "disabled" , disabled ) ;
129
+ $ ( '#getTemplateButton' ) . prop ( "disabled" , disabled ) ;
130
+ $ ( '#reloadButton' ) . prop ( "disabled" , disabled ) ;
131
+ $ ( '.table-btn' ) . prop ( "disabled" , disabled ) ;
132
+ }
133
+
115
134
// Check if EI Backend Server is online when Status Connection button is pressed.
116
135
$ ( "#btnEIConnection" ) . click ( function ( ) {
117
136
checkBackendStatus ( ) ;
@@ -382,6 +401,11 @@ jQuery(document).ready(function () {
382
401
success : function ( data ) {
383
402
isSecured = JSON . parse ( ko . toJSON ( data ) ) . security ;
384
403
drawTable ( isSecured ) ;
404
+ } ,
405
+ complete : function ( ) {
406
+ $ ( "#check-all" ) . click ( function ( ) {
407
+ $ ( ".data-check" ) . prop ( 'checked' , $ ( this ) . prop ( 'checked' ) ) ;
408
+ } ) ;
385
409
}
386
410
} ) ;
387
411
}
@@ -402,7 +426,14 @@ jQuery(document).ready(function () {
402
426
"url" : frontendServiceUrl + "/subscriptions" ,
403
427
"type" : "GET" ,
404
428
"dataSrc" : "" , // Flat structure from EI backend REST API
405
- "error" : function ( ) { }
429
+ "error" : function ( ) { } ,
430
+ "complete" : function ( data ) {
431
+ if ( data . responseJSON . length != undefined && data . responseJSON . length > 0 ) {
432
+ toggleCheckboxesDisabled ( false ) ;
433
+ } else {
434
+ toggleCheckboxesDisabled ( true ) ;
435
+ }
436
+ }
406
437
} ,
407
438
//Set column definition initialisation properties.
408
439
"columnDefs" : [
@@ -486,9 +517,6 @@ jQuery(document).ready(function () {
486
517
if ( isSecured == false ) {
487
518
table . column ( 2 ) . visible ( false ) ;
488
519
}
489
- $ ( "#check-all" ) . click ( function ( ) {
490
- $ ( ".data-check" ) . prop ( 'checked' , $ ( this ) . prop ( 'checked' ) ) ;
491
- } ) ;
492
520
$ ( ".control" ) . click ( function ( ) {
493
521
setTimeout ( function ( ) { toggleOnBackendStatus ( backendStatus ) ; } , 50 ) ;
494
522
} ) ;
@@ -519,6 +547,38 @@ jQuery(document).ready(function () {
519
547
// /Stop ## Reload Table#################################################
520
548
521
549
// /Start ## Bulk delete#################################################
550
+ function deleteSubscriptions ( subscriptionsToDeleteString ) {
551
+ var callback = {
552
+ beforeSend : function ( ) {
553
+ } ,
554
+ success : function ( data , textStatus ) {
555
+ reload_table ( ) ;
556
+ } ,
557
+ error : function ( XMLHttpRequest , textStatus , errorThrown ) {
558
+ reload_table ( ) ;
559
+ var responseJSON = JSON . parse ( XMLHttpRequest . responseText ) ;
560
+ for ( var i = 0 ; i < responseJSON . length ; i ++ ) {
561
+ window . logMessages ( "Error deleting subscription: [" + responseJSON [ i ] . subscription + "] Reason: [" + responseJSON [ i ] . reason + "]" ) ;
562
+ }
563
+ } ,
564
+ complete : function ( ) {
565
+ }
566
+ } ;
567
+
568
+ $ ( '.confirm-delete .modal-body' ) . text ( subscriptionsToDeleteString ) ;
569
+ $ ( '.confirm-delete .btn-danger' ) . unbind ( ) ;
570
+ $ ( '.confirm-delete .btn-danger' ) . click ( function ( ) {
571
+ $ ( "#check-all" ) . prop ( 'checked' , false ) ;
572
+ var ajaxHttpSender = new AjaxHttpSender ( ) ;
573
+ // replace all /n with comma
574
+ if ( / \n / . exec ( subscriptionsToDeleteString ) ) {
575
+ subscriptionsToDeleteString = subscriptionsToDeleteString . replace ( new RegExp ( '\n' , 'g' ) , ',' ) . slice ( 0 , - 1 ) ;
576
+ }
577
+ ajaxHttpSender . sendAjax ( frontendServiceUrl + "/subscriptions/" + subscriptionsToDeleteString , "DELETE" , null , callback ) ;
578
+ } ) ;
579
+ $ ( '.confirm-delete' ) . modal ( 'show' ) ;
580
+ } ;
581
+
522
582
$ ( "#bulkDelete" ) . click ( function ( ) {
523
583
var subscriptionsToDelete = [ ] ;
524
584
var data = table . rows ( ) . nodes ( ) ;
@@ -539,39 +599,7 @@ jQuery(document).ready(function () {
539
599
subscriptionsToDeleteString += subscriptionsToDelete [ i ] + "\n" ;
540
600
}
541
601
542
- var callback = {
543
- beforeSend : function ( ) {
544
- } ,
545
- success : function ( data , textStatus ) {
546
- //if success reload ajax table
547
- $ ( '#modal_form' ) . modal ( 'hide' ) ;
548
- reload_table ( ) ;
549
- } ,
550
- error : function ( XMLHttpRequest , textStatus , errorThrown ) {
551
- reload_table ( ) ;
552
- var responseJSON = JSON . parse ( XMLHttpRequest . responseText ) ;
553
- for ( var i = 0 ; i < responseJSON . length ; i ++ ) {
554
- window . logMessages ( "Error deleteing subscription: [" + responseJSON [ i ] . subscription + "] Reason: [" + responseJSON [ i ] . reason + "]" ) ;
555
- }
556
- } ,
557
- complete : function ( ) {
558
- }
559
- } ;
560
-
561
- $ . confirm ( {
562
- title : 'Confirm!' ,
563
- content : 'Are you sure you want to delete these subscriptions?<pre>' + subscriptionsToDeleteString ,
564
- buttons : {
565
- confirm : function ( ) {
566
- var ajaxHttpSender = new AjaxHttpSender ( ) ;
567
- // replace all /n with comma
568
- subscriptionsToDeleteString = subscriptionsToDeleteString . replace ( new RegExp ( '\n' , 'g' ) , ',' ) . slice ( 0 , - 1 ) ;
569
- ajaxHttpSender . sendAjax ( frontendServiceUrl + "/subscriptions/" + subscriptionsToDeleteString , "DELETE" , null , callback ) ;
570
- } ,
571
- cancel : function ( ) {
572
- }
573
- }
574
- } ) ;
602
+ deleteSubscriptions ( subscriptionsToDeleteString ) ;
575
603
} ) ;
576
604
// /Stop ## Bulk delete##################################################
577
605
@@ -626,11 +654,11 @@ jQuery(document).ready(function () {
626
654
}
627
655
}
628
656
629
- var pom = document . getElementById ( ' upload_sub') ;
630
- pom . onchange = function uploadFinished ( ) {
631
- var subscriptionFile = pom . files [ 0 ] ;
657
+ $ ( '# upload_sub') . change ( function ( ) {
658
+ var subscriptionFile = document . getElementById ( 'upload_sub' ) . files [ 0 ] ;
659
+ $ ( '#upload_sub' ) . val ( "" ) ;
632
660
validateJsonAndCreateSubscriptions ( subscriptionFile ) ;
633
- } ;
661
+ } ) ;
634
662
function tryToCreateSubscription ( subscriptionJson ) {
635
663
// Send Subscription JSON file to Spring MVC
636
664
// AJAX Callback handling
@@ -667,22 +695,7 @@ jQuery(document).ready(function () {
667
695
// /Start ## upload_subscriptions #################################################
668
696
$ ( "#uploadSubscription" ) . click ( function ( ) {
669
697
function createUploadWindow ( ) {
670
- // var pom = document.createElement('input');
671
- // pom.setAttribute('id', 'uploadFile');
672
- // pom.setAttribute('type', 'file');
673
- // pom.setAttribute('name', 'upFile');
674
- // pom.onchange = function uploadFinished() {
675
- // var subscriptionFile = pom.files[0];
676
- // validateJsonAndCreateSubscriptions(subscriptionFile);
677
- // };
678
- if ( document . createEvent ) {
679
- var event = document . createEvent ( 'MouseEvents' ) ;
680
- event . initEvent ( 'click' , true , true ) ;
681
- pom . dispatchEvent ( event ) ;
682
- }
683
- else {
684
- pom . click ( ) ;
685
- }
698
+ $ ( '#upload_sub' ) . click ( ) ;
686
699
}
687
700
688
701
function createUploadWindowMSExplorer ( ) {
@@ -1113,47 +1126,12 @@ jQuery(document).ready(function () {
1113
1126
event . stopPropagation ( ) ;
1114
1127
event . preventDefault ( ) ;
1115
1128
// Get tag that contains subscriptionName
1116
- var id = $ ( this ) . attr ( "id" ) . split ( "-" ) [ 1 ] ;
1117
- var callback = {
1118
- beforeSend : function ( ) {
1119
- } ,
1120
- success : function ( data , textStatus ) {
1121
- //if success reload ajax table
1122
- $ ( '#modal_form' ) . modal ( 'hide' ) ;
1123
- reload_table ( ) ;
1124
-
1125
- } ,
1126
- error : function ( XMLHttpRequest , textStatus , errorThrown ) {
1127
- window . logMessages ( "Error: " + XMLHttpRequest . responseText ) ;
1128
- } ,
1129
- complete : function ( ) {
1130
- }
1131
- } ;
1129
+ var subscription = $ ( this ) . attr ( "id" ) . split ( "-" ) [ 1 ] ;
1132
1130
1133
- $ . confirm ( {
1134
- title : 'Confirm!' ,
1135
- content : 'Please confirm before deleting subscription!' ,
1136
- buttons : {
1137
- confirm : function ( ) {
1138
- var ajaxHttpSender = new AjaxHttpSender ( ) ;
1139
- ajaxHttpSender . sendAjax ( frontendServiceUrl + "/subscriptions/" + id , "DELETE" , null , callback ) ;
1140
- } ,
1141
- cancel : function ( ) {
1142
- }
1143
- }
1144
- } ) ;
1131
+ deleteSubscriptions ( subscription ) ;
1145
1132
} ) ;
1146
1133
// /Stop ## Delete Subscription #########################################
1147
1134
1148
- function toggleButtonsDisabled ( disabled ) {
1149
- $ ( '#addSubscription' ) . prop ( "disabled" , disabled ) ;
1150
- $ ( '#bulkDelete' ) . prop ( "disabled" , disabled ) ;
1151
- $ ( '#uploadSubscription' ) . prop ( "disabled" , disabled ) ;
1152
- $ ( '#getTemplateButton' ) . prop ( "disabled" , disabled ) ;
1153
- $ ( '#reloadButton' ) . prop ( "disabled" , disabled ) ;
1154
- $ ( '.table-btn' ) . prop ( "disabled" , disabled ) ;
1155
- }
1156
-
1157
1135
function loadTooltip ( ) {
1158
1136
$ ( '[data-toggle="tooltip"]' ) . tooltip ( { trigger : "click" , html : true } ) ;
1159
1137
}
0 commit comments