Moved src/app/network to modules/network-resources
[dlux.git] / modules / network-resources / src / main / resources / network / network.controller.js
1 define(['app/network/network.module', 'jquery', 'footable', 'app/network/network.services'], function(network, $) {
2
3   network.register.controller('NetworkCtrl', function($rootScope, $scope, $state) {
4     $rootScope['section_logo'] = 'logo_network';
5     $scope.isState = function(name) {
6       return $state.includes(name);
7     };
8     $scope.getText = function(text) { // firefox use textContent while chrome use innerText...
9       return text.innerText||text.textContent;
10     };
11   });
12
13
14   network.register.controller('StaticRouteCtrl', ['$scope', 'StaticRouteSvc', function ($scope, StaticRouteSvc) {
15     StaticRouteSvc.routesUrl(null).getList().then(
16       function (data) {
17         $scope.data = data;
18       }
19     );
20
21     $('table').footable().on('click', '.row-delete', function(e) {
22       e.preventDefault();
23       //get the footable object
24       var footable = $('table').data('footable');
25
26       //get the row we are wanting to delete
27       var row = $(this).parents('tr:first');
28       //delete the row
29       StaticRouteSvc.delete($scope.getText(row[0].cells[0]));
30       footable.removeRow(row);
31     });
32
33
34   }]);
35
36   network.register.controller('StaticRouteCreateCtrl', ['$scope', 'StaticRouteSvc', '$state', function ($scope, StaticRouteSvc, $state) {
37     $scope.submit = function () {
38        StaticRouteSvc.routeUrl(null, $scope.data.name).customPUT($scope.data).then(
39         function (data) {
40           $state.transitionTo('main.network.staticroutes', null, { location: true, inherit: true, relative: $state.$current, notify: true });
41         }, function(resp) {
42           $scope.error = resp.data;
43         }
44       );
45     };
46   }]);
47
48   network.register.controller('StaticRouteEditCtrl', ['$scope', 'StaticRouteSvc', '$state', '$stateParams', function ($scope, StaticRouteSvc, $state, $stateParams) {
49     $scope.submit = function () {
50       console.log(StaticRouteSvc.routeUrl(null, $scope.data.name));
51       StaticRouteSvc.routeUrl(null, $scope.data.name).customPOST($scope.data).then(
52         function (data) {
53           $state.transitionTo('main.network.staticroutes', null, { location: true, inherit: true, relative: $state.$current, notify: true });
54         }, function(resp) {
55           $scope.error = resp.data;
56         }
57       );
58     };
59     StaticRouteSvc.routeUrl(null, $stateParams.name).get().then(
60       function (data) {
61         $scope.data = data;
62       }
63     );
64   }]);
65
66   network.register.controller('SubnetCtrl', ['$scope', 'SubnetSvc', function ($scope, SubnetSvc) {
67     SubnetSvc.subnetsUrl(null).getList().then(
68       function (data) {
69         $scope.data = data;
70       }
71     );
72
73     $('table').footable().on('click', '.row-delete', function(e) {
74       e.preventDefault();
75
76       //get the footable object
77       var footable = $('table').data('footable');
78       //get the row we are wanting to delete
79       var row = $(this).parents('tr:first');
80       //delete the row
81       SubnetSvc.delete($scope.getText(row[0].cells[0]));
82       footable.removeRow(row);
83     });
84   }]);
85
86  network.register.controller('SubnetCreateCtrl', ['$scope', 'SubnetSvc', '$state', function ($scope, SubnetSvc, $state) {
87     $scope.submit = function () {
88       SubnetSvc.subnetUrl(null, $scope.data.name).customPUT($scope.data).then(
89         function(data) {
90           $state.transitionTo('main.network.subnets', null, { location: true, inherit: true, relative: $state.$current, notify: true });
91         }, function(resp) {
92           $scope.error = resp.data;
93         }
94       );
95     };
96   }]);
97
98   network.register.controller('SubnetEditCtrl', ['$scope', 'SubnetSvc', '$state', '$stateParams', function ($scope, SubnetSvc, $state, $stateParams) {
99     SubnetSvc.subnetUrl(null, $stateParams.name).get().then(
100       function(data) {
101         $scope.data = data;
102       }
103     );
104     $scope.submit = function () {
105       SubnetSvc.subnetUrl(null, $scope.data.name).customPOST($scope.data).then(
106         function(data) {
107           $state.transitionTo('main.network.subnets', null, { location: true, inherit: true, relative: $state.$current, notify: true });
108         }, function(resp) {
109           $scope.error = resp.data;
110         }
111       );
112     };
113   }]);
114
115 });