Endpoint added
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / endpoints / endpoints.controller.js
1 define([
2     'app/gbp/endpoints/endpoint.service',
3     'app/gbp/endpoints/endpoints-list.service',
4 ], function () {
5     'use strict';
6
7     angular.module('app.gbp').controller('EndpointsController', EndpointsController);
8
9     EndpointsController.$inject = ['$scope', '$mdDialog', 'EndpointsListService', 'EndpointService'];
10
11     function EndpointsController($scope, $mdDialog, EndpointsListService, EndpointService) {
12         $scope.endpoints = EndpointsListService.createList();
13         $scope.openEndpointDialog = openEndpointDialog;
14         $scope.getEndpointsList = getEndpointsList;
15         $scope.deleteEndpointDialog = deleteEndpointDialog;
16         $scope.endpointsTableQuery = {
17             order: "data['context-id']",
18             limit: 25,
19             page: 1,
20             options: [25, 50, 100],
21             filter: '',
22         };
23
24         getEndpointsList();
25
26         function getEndpointsList() {
27             $scope.endpoints.clearData();
28             $scope.endpoints.get();
29         }
30
31         function openEndpointDialog(endpointData) {
32             $mdDialog.show({
33                 clickOutsideToClose: true,
34                 controller: 'AddEndpointController',
35                 preserveScope: true,
36                 templateUrl: $scope.viewPath + 'endpoints/dialog-add-endpoint.tpl.html',
37                 parent: angular.element(document.body),
38                 scope: $scope,
39                 locals: {
40                     endpoint: endpointData,
41                 },
42             });
43         }
44
45         function deleteEndpointDialog(endpointData) {
46             var confirm = $mdDialog.confirm()
47                 .title('Delete endpoint')
48                 .textContent('Do you want to delete endpoint?')
49                 .ok('Delete')
50                 .cancel('Cancel');
51
52             $mdDialog.show(confirm).then(function () {
53                 contractData.deleteEndpoint($scope.rootTenant.data.id,
54                     function () {
55                         $scope.getEndpointsList();
56                     }
57                 );
58             }, function () {
59
60             });
61         }
62     }
63 });