@@ -46,23 +46,45 @@ nttApp.controller('CloudCtrl', function($scope, $routeParams, $location, cloudSe
4646 } ;
4747
4848 } ;
49+
50+ $scope . deleteTraffic = function ( $index ) {
51+ if ( confirm ( "Are you sure want to delete?" ) ) {
52+ cloudTrafficService . delete ( $scope . cloudTrafficList [ $index ] . id ) . then ( function ( data ) {
53+ $scope . cloudTrafficList . splice ( $index , 1 ) ;
54+ } ) ;
55+ }
56+ }
4957} ) ;
5058
5159
5260
5361nttApp . controller ( 'CloudTrafficCtrl' , function ( $scope , $routeParams , $location , cloudService , cloudTrafficService ) {
5462 $scope . cloud = { } ;
63+ $scope . event = $routeParams . event ;
5564 cloudService . get ( $routeParams . cloudId ) . then ( function ( data ) {
5665 $scope . cloud = data ;
5766 } ) ;
5867
5968 $scope . cloudTraffic = { } ;
60- $scope . save = function ( ) {
61- $scope . cloudTraffic [ "cloud" ] = $scope . cloud . id ;
62- cloudTrafficService . create ( $scope . cloudTraffic ) . then ( function ( data ) {
63- $location . path ( "cloudtraffic/view/" + data . id + "/" ) ;
69+ if ( $scope . event == 'edit' ) {
70+ cloudTrafficService . get ( $routeParams . trafficId ) . then ( function ( data ) {
71+ $scope . cloudTraffic = data ;
6472 } ) ;
6573 } ;
74+
75+ $scope . save = function ( ) {
76+ if ( $scope . event == 'add' ) {
77+ $scope . cloudTraffic [ "cloud" ] = $scope . cloud . id ;
78+ cloudTrafficService . create ( $scope . cloudTraffic ) . then ( function ( data ) {
79+ $location . path ( "cloudtraffic/view/" + data . id + "/" ) ;
80+ } ) ;
81+ }
82+ else {
83+ cloudTrafficService . update ( $scope . cloudTraffic . id , $scope . cloudTraffic ) . then ( function ( data ) {
84+ $location . path ( "cloudtraffic/view/" + data . id + "/" ) ;
85+ } ) ;
86+ }
87+ } ;
6688} ) ;
6789
6890nttApp . controller ( 'CloudTrafficViewCtrl' , function ( $scope , $routeParams , $location , cloudService , cloudTrafficService , cloudTrafficTenantService ) {
@@ -97,9 +119,9 @@ nttApp.controller('CloudTrafficViewCtrl', function($scope, $routeParams, $locati
97119 } ;
98120
99121 $scope . saveExternalHost = function ( ) {
100- // cloudTrafficService.update($scope.cloudTraffic).then(function (data) {
122+ cloudTrafficService . update ( $scope . cloudTraffic . id , $scope . cloudTraffic ) . then ( function ( data ) {
101123 $location . path ( "cloudtraffictest" ) ;
102- // });
124+ } ) ;
103125 } ;
104126} ) ;
105127
0 commit comments