@@ -363,16 +363,17 @@ jQuery(document).ready(function() {
363
363
"orderable" : false ,
364
364
"title" : "Action" ,
365
365
"data" : null ,
366
- "width" :"150px" ,
367
366
"render" : function ( data , type , row , meta ) {
368
367
if ( isSecured == true && row . userName == currentUser && row . userName != null ) {
369
- return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
370
- + '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>' ;
368
+ return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button> '
369
+ + '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
370
+ + '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>' ;
371
371
} else if ( isSecured == false ) {
372
- return '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
372
+ return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button> '
373
+ + '<button data-toggle="tooltip" title="Edit subscription" class="btn btn-sm btn-primary edit_record">Edit</button> '
373
374
+ '<button data-toggle="tooltip" title="Delete subscription from EI" class="btn btn-sm btn-danger delete_record">Delete</button>' ;
374
375
} else {
375
- return '' ;
376
+ return '<button data-toggle="tooltip" title="View subscription" class="btn btn-sm btn-success view_record">View</button> ' ;
376
377
}
377
378
}
378
379
}
@@ -586,46 +587,50 @@ jQuery(document).ready(function() {
586
587
587
588
588
589
// /Start ## Reload Datatables ###########################################
589
- function reload_table ( )
590
- {
590
+ function reload_table ( ) {
591
591
table . ajax . reload ( null , false ) ; //reload datatable ajax
592
592
}
593
593
// /Stop ## Reload Datatables ############################################
594
594
595
-
596
- // /Start ## Edit Subscription ###########################################
597
- $ ( '#table' ) . on ( 'click' , 'tbody tr td button.edit_record' , function ( event ) {
598
- event . stopPropagation ( ) ;
595
+ function get_subscription_data ( object , mode ) {
596
+ event . stopPropagation ( ) ;
599
597
event . preventDefault ( ) ;
600
598
// Fetch datatable row -> subscriptionName
601
- var datatable_row_data = table . row ( $ ( this ) . parents ( 'tr' ) ) . data ( ) ;
599
+ var datatable_row_data = table . row ( $ ( object ) . parents ( 'tr' ) ) . data ( ) ;
602
600
var id = datatable_row_data . subscriptionName ;
603
601
// AJAX Callback handling
604
602
var callback = {
605
- beforeSend : function ( ) {
606
- } ,
603
+ beforeSend : function ( ) { } ,
607
604
success : function ( data , textStatus ) {
608
- populate_json ( data , "edit" ) ;
605
+ populate_json ( data , mode ) ;
609
606
} ,
610
607
error : function ( XMLHttpRequest , textStatus , errorThrown ) {
611
608
$ . jGrowl ( "Error: " + XMLHttpRequest . responseText , {
612
609
sticky : true ,
613
610
theme : 'Error'
614
611
} ) ;
615
612
} ,
616
- complete : function ( ) {
617
- }
613
+ complete : function ( ) { }
618
614
} ;
619
615
// Perform AJAX
620
616
var ajaxHttpSender = new AjaxHttpSender ( ) ;
621
617
ajaxHttpSender . sendAjax ( frontendServiceUrl + "/subscriptions/" + id , "GET" , null , callback ) ;
618
+ }
619
+
620
+ // /Start ## Edit Subscription ###########################################
621
+ $ ( '#table' ) . on ( 'click' , 'tbody tr td button.edit_record' , function ( event ) {
622
+ get_subscription_data ( this , "edit" ) ;
622
623
} ) ;
623
624
// /Stop ## Edit Subscription ###########################################
624
625
626
+ // /Start ## View Subscription ###########################################
627
+ $ ( '#table' ) . on ( 'click' , 'tbody tr td button.view_record' , function ( event ) {
628
+ get_subscription_data ( this , "view" ) ;
629
+ } ) ;
630
+ // /Stop ## View Subscription ###########################################
625
631
626
632
// /Start ## populate JSON ###########################################
627
- function populate_json ( data , save_method_in )
628
- {
633
+ function populate_json ( data , save_method_in ) {
629
634
var returnData = [ data ] ;
630
635
if ( returnData . length > 0 ) {
631
636
vm . subscription ( [ ] ) ;
@@ -650,18 +655,31 @@ jQuery(document).ready(function() {
650
655
// Force update
651
656
vm . subscription ( ) [ 0 ] . restPostBodyMediaType . valueHasMutated ( ) ;
652
657
$ ( '#modal_form' ) . modal ( 'show' ) ;
653
- if ( save_method_in === "edit" )
654
- {
655
- title_ = 'Edit Subscription' ;
656
-
657
- } else
658
- {
659
- title_ = 'Add Subscription' ;
660
- }
661
- $ ( '.modal-title' ) . text ( title_ ) ;
658
+ if ( save_method_in === "edit" ) {
659
+ title_ = 'Edit Subscription' ;
660
+ addEditMode ( ) ;
661
+ } else if ( save_method_in === "add" ) {
662
+ title_ = 'Add Subscription' ;
663
+ addEditMode ( ) ;
664
+ } else {
665
+ title_ = 'View Subscription' ;
666
+ viewMode ( ) ;
667
+ }
668
+ $ ( '.modal-title' ) . text ( title_ ) ;
662
669
save_method = save_method_in ;
663
670
}
664
671
}
672
+
673
+ function addEditMode ( ) {
674
+ $ ( '#modal_form :button' ) . show ( ) ;
675
+ $ ( '#modal_form :input' ) . prop ( "disabled" , false ) ;
676
+ }
677
+ function viewMode ( ) {
678
+ $ ( '#modal_form :button' ) . hide ( ) ;
679
+ $ ( '#modal_form :input' ) . prop ( "disabled" , true ) ;
680
+ $ ( '#modal_form .close' ) . show ( ) ;
681
+ $ ( '#modal_form .close' ) . prop ( "disabled" , false ) ;
682
+ }
665
683
// /Stop ## pupulate JSON ###########################################
666
684
667
685
@@ -670,8 +688,7 @@ jQuery(document).ready(function() {
670
688
event . stopPropagation ( ) ;
671
689
event . preventDefault ( ) ;
672
690
var notificationMessageKeyValuesArray = vm . subscription ( ) [ 0 ] . notificationMessageKeyValues ( ) ;
673
- if ( ! vm . formpostkeyvaluepairs ( ) )
674
- {
691
+ if ( ! vm . formpostkeyvaluepairs ( ) ) {
675
692
notificationMessageKeyValuesArray [ 0 ] . formkey = "" ; // OBS must be empty when NOT using REST POST Form key/value pairs
676
693
}
677
694
@@ -790,7 +807,7 @@ jQuery(document).ready(function() {
790
807
url = frontendServiceUrl + "/subscriptions" ;
791
808
type = "POST" ;
792
809
793
- } else { // Update existing
810
+ } else if ( save_method === 'edit' ) { // Update existing
794
811
url = frontendServiceUrl + "/subscriptions" ;
795
812
type = "PUT" ;
796
813
}
0 commit comments