@@ -554,108 +554,23 @@ jQuery(document).ready(function() {
554
554
} ) ;
555
555
// /END ## upload_subscriptions #################################################
556
556
557
- // /Start ## Add Condition ##############################################
558
- /*
559
- $('div.modal-content').on( 'click', 'button.add_condition', function (event) {
560
557
561
- event.stopPropagation();
562
- event.preventDefault();
563
-
564
- /*var condition = {
565
- "conditions" : [
566
- {
567
- "jmespath" : ko.observable("")
568
- }
569
- ]
570
- }
571
- *
572
- var condition = {
573
- "jmespath" : ko.observable("test")
574
- }
575
-
576
-
577
-
578
- vm.subscription()[0].requirements()[0].conditions().push(new jmespath_model({"jmespath": ko.observable("cc")}));
579
-
580
- vm.subscription()[0].requirements()[0].conditions().push({"jmespath": ko.observable("cc")});
581
-
582
-
583
-
584
- console.log(ko.toJSON(vm.subscription()[0].requirements()[0].conditions()));
585
-
586
- vm.subscription.valueHasMutated();
587
-
588
-
589
- //var vm = new SubscriptionViewModel();
590
- //ko.applyBindings(vm);
591
-
592
- // ko.cleanNode(document.getElementById(element_id))
593
- // ko.applyBindings(viewModel, document.getElementById(element_id))
594
-
595
- });*/
596
- // /Stop ## Add Condition ################################################
597
-
598
-
599
- // /Start ## Delete Condition ##############################################
600
- /* $('div.modal-content').on( 'click', 'button.condition_delete', function (event) {
601
-
602
-
603
- event.stopPropagation();
604
- event.preventDefault();
605
-
606
- var context = ko.contextFor(event.target);
607
- var indexToRemove = context.$index();
608
-
609
- // Removing Requirement(Condition), based on index position, from Requirement form in Add_Subscription window.
610
- if (indexToRemove > 0 ){
611
- vm.subscription()[0].requirements.splice(indexToRemove,1);
612
- }
613
- else {
614
- $.alert("You need to have atleast one Condition.");
615
- }
616
- });*/
617
- // /Stop ## Delete Condition ################################################
618
-
619
-
620
558
// /Start ## Add Subscription ########################################
621
559
$ ( '.container' ) . on ( 'click' , 'button.btn.btn-success.add_subscription' , function ( event ) {
622
560
623
561
event . stopPropagation ( ) ;
624
562
event . preventDefault ( ) ;
625
-
626
- // Clear observable array
627
- vm . subscription ( [ ] ) ;
628
563
629
- // Map JSON to Model and observableArray
630
- var mappedPackageInfo = $ . map ( default_json_empty , function ( item ) {
631
-
632
- // Removing old Requirements and conditions from previous Add_subscription window.
633
- item . requirements . splice ( 1 , item . requirements . length - 1 ) ;
634
-
635
- // Defining Observable on all parameters in Requirements array(which is defined as ObservableArray)
636
- item . requirements [ 0 ] . conditions [ 0 ] = { "jmespath" : ko . observable ( "" ) } ;
637
- item . requirements [ 0 ] . type = ko . observable ( "" ) ;
638
564
639
- return new subscription_model ( item ) ;
640
- } ) ;
641
-
642
- // Load data into observable array
643
- vm . subscription ( mappedPackageInfo ) ;
565
+ json_obj_clone = JSON . parse ( JSON . stringify ( default_json_empty ) ) ;
644
566
645
- save_method = ' add' ;
567
+ populate_json ( json_obj_clone , " add" ) ;
646
568
647
- $ ( '.form-group' ) . removeClass ( 'has-error' ) ; // clear error class
648
- $ ( '.help-block' ) . empty ( ) ; // clear error string
649
-
650
- $ ( '#modal_form' ) . modal ( 'show' ) ; // show bootstrap modal
651
- $ ( '.modal-title' ) . text ( 'Add Subscription' ) ; // Set Title to Bootstrap modal title
652
569
653
570
} ) ;
654
571
// /Stop ## Add Subscription ############################################
655
572
656
573
657
-
658
-
659
574
// /Start ## Reload Datatables ###########################################
660
575
function reload_table ( )
661
576
{
@@ -680,61 +595,83 @@ jQuery(document).ready(function() {
680
595
} ,
681
596
success : function ( data , textStatus ) {
682
597
683
- var returnData = [ data ] ;
684
- if ( returnData . length > 0 ) {
598
+ populate_json ( data , "edit" ) ;
599
+
600
+ } ,
601
+ error : function ( XMLHttpRequest , textStatus , errorThrown ) {
602
+ $ . jGrowl ( "Error: " + XMLHttpRequest . responseText , {
603
+ sticky : true ,
604
+ theme : 'Error'
605
+ } ) ;
606
+ } ,
607
+ complete : function ( ) {
608
+ }
609
+ } ;
685
610
686
- // Map JSON to Model and observableArray
687
- var mappedPackageInfo = $ . map ( returnData , function ( item ) {
611
+ // Perform AJAX
612
+ var ajaxHttpSender = new AjaxHttpSender ( ) ;
613
+ ajaxHttpSender . sendAjax ( backendServiceUrl + "/subscriptions/" + id , "GET" , null , callback ) ;
688
614
689
- // Defining Observable on all parameters in Requirements array(which is defined as ObservableArray)
615
+ } ) ;
616
+ // /Stop ## Edit Subscription ###########################################
690
617
691
- for ( i = 0 ; i < item [ 0 ] . requirements . length ; i ++ ) {
692
618
693
- var conditions_array = [ ] ;
619
+ // /Start ## pupulate JSON ###########################################
620
+ function populate_json ( data , save_method_in )
621
+ {
622
+ var returnData = [ data ] ;
623
+ if ( returnData . length > 0 ) {
694
624
695
- for ( k = 0 ; k < item [ 0 ] . requirements [ i ] . conditions . length ; k ++ ) {
696
625
697
- var jmespath_temp = item [ 0 ] . requirements [ i ] . conditions [ k ] . jmespath ;
626
+ vm . subscription ( [ ] ) ;
698
627
699
- conditions_array . push ( new jmespath_model ( { "jmespath" : ko . observable ( jmespath_temp ) } ) ) ;
628
+ // Map JSON to Model and observableArray
629
+ var mappedPackageInfo = $ . map ( returnData , function ( item ) {
700
630
701
- }
631
+ // Defining Observable on all parameters in Requirements array(which is defined as ObservableArray)
702
632
703
- item [ 0 ] . requirements [ i ] = new conditions_model ( conditions_array ) ;
633
+ for ( i = 0 ; i < item [ 0 ] . requirements . length ; i ++ ) {
704
634
705
- }
706
- return new subscription_model ( item [ 0 ] ) ;
635
+ var conditions_array = [ ] ;
707
636
637
+ for ( k = 0 ; k < item [ 0 ] . requirements [ i ] . conditions . length ; k ++ ) {
708
638
709
- } ) ;
639
+ var jmespath_temp = item [ 0 ] . requirements [ i ] . conditions [ k ] . jmespath ;
710
640
711
- // Load data into observable array
712
- vm . subscription ( mappedPackageInfo ) ;
641
+ conditions_array . push ( new jmespath_model ( { "jmespath" : ko . observable ( jmespath_temp ) } ) ) ;
713
642
643
+ }
714
644
715
- $ ( '#modal_form' ) . modal ( 'show' ) ;
716
- $ ( '.modal-title' ) . text ( 'Subscription: ' + data . subscriptionName ) ;
645
+ item [ 0 ] . requirements [ i ] = new conditions_model ( conditions_array ) ;
717
646
718
- save_method = 'edit' ;
719
647
}
648
+ return new subscription_model ( item [ 0 ] ) ;
720
649
721
- } ,
722
- error : function ( XMLHttpRequest , textStatus , errorThrown ) {
723
- $ . jGrowl ( "Error: " + XMLHttpRequest . responseText , {
724
- sticky : true ,
725
- theme : 'Error'
726
- } ) ;
727
- } ,
728
- complete : function ( ) {
729
- }
730
- } ;
731
650
732
- // Perform AJAX
733
- var ajaxHttpSender = new AjaxHttpSender ( ) ;
734
- ajaxHttpSender . sendAjax ( backendServiceUrl + "/subscriptions/" + id , "GET" , null , callback ) ;
651
+ } ) ;
735
652
736
- } ) ;
737
- // /Stop ## Edit Subscription ###########################################
653
+ // Load data into observable array
654
+ vm . subscription ( mappedPackageInfo ) ;
655
+
656
+
657
+ $ ( '#modal_form' ) . modal ( 'show' ) ;
658
+
659
+ if ( data === "edit" )
660
+ {
661
+ title_ = 'Subscription: ' + data . subscriptionName
662
+
663
+ } else
664
+ {
665
+ title_ = 'Add Subscription' ;
666
+ }
667
+
668
+ $ ( '.modal-title' ) . text ( title_ ) ;
669
+
670
+ save_method = save_method_in ;
671
+ }
672
+
673
+ }
674
+ // /Stop ## pupulate JSON ###########################################
738
675
739
676
740
677
// /Start ## Save Subscription ##########################################
@@ -783,17 +720,21 @@ jQuery(document).ready(function() {
783
720
return ;
784
721
}
785
722
786
- /*
723
+
787
724
var requirementsArray = vm . subscription ( ) [ 0 ] . requirements ( ) ;
788
725
for ( i = 0 ; i < requirementsArray . length ; i ++ ) {
789
- if (requirementsArray[i].conditions[0].jmespath() == "") {
790
- $.jGrowl("Error: jmepath field must have a value", {
791
- sticky : true,
792
- theme : 'Error'
793
- });
794
- return;
795
- }
796
- }*/
726
+ var conditionsArray = requirementsArray [ i ] . conditions ( ) ;
727
+ for ( k = 0 ; k < conditionsArray . length ; k ++ ) {
728
+ var test_me = ko . toJSON ( conditionsArray [ k ] . jmespath ( ) ) ;
729
+ if ( test_me === '""' ) {
730
+ $ . jGrowl ( "Error: jmepath field must have a value" , {
731
+ sticky : true ,
732
+ theme : 'Error'
733
+ } ) ;
734
+ return ;
735
+ }
736
+ }
737
+ }
797
738
//END: Check of other subscription fields values
798
739
799
740
var id = ko . toJSON ( vm . subscription ( ) [ 0 ] . subscriptionName ) . trim ( ) ;
0 commit comments