967886ff4ed7083a4b0052dc28d4d5d9ffbe329b
[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'];
10
11     function EndpointsController($scope, $mdDialog, EndpointsListService) {
12         /* properties */
13         $scope.endpoints = EndpointsListService.createList();
14         $scope.disableKeyFieldsEditing = false;
15         $scope.endpointsTableQuery = {
16             order: "data['context-id']",
17             limit: 25,
18             page: 1,
19             options: [25, 50, 100],
20             filter: '',
21         };
22         /* methods */
23         $scope.openEndpointDialog = openEndpointDialog;
24         $scope.getEndpointsList = getEndpointsList;
25         $scope.deleteEndpointDialog = deleteEndpointDialog;
26
27         $scope.getEndpointsList();
28
29         function getEndpointsList() {
30             $scope.endpoints.clearData();
31             $scope.rootTenant ? $scope.endpoints.getByTenantId($scope.rootTenant) : $scope.endpoints.get($scope.rootTenant);
32
33             $scope.endpointSgtList.clearData();
34             $scope.endpointSgtList.get();
35         }
36
37         function openEndpointDialog(operation, endpointData) {
38             $scope.disableKeyFieldsEditing = operation === 'edit';
39             $mdDialog.show({
40                 clickOutsideToClose: true,
41                 controller: 'AddEndpointController',
42                 preserveScope: true,
43                 templateUrl: $scope.viewPath + 'endpoints/dialog-add-endpoint.tpl.html',
44                 parent: angular.element(document.body),
45                 scope: $scope,
46                 locals: {
47                     endpoint: endpointData,
48                 },
49             });
50         }
51
52         function deleteEndpointDialog(endpointData) {
53             var confirm = $mdDialog.confirm()
54                 .title('Delete endpoint')
55                 .textContent('Do you want to delete endpoint?')
56                 .ok('Delete')
57                 .cancel('Cancel');
58
59             $mdDialog.show(confirm).then(function () {
60                 endpointData.deleteEndpoint(function () {
61                     $scope.getEndpointsList();
62                 });
63             }, function () {
64
65             });
66         }
67
68         $scope.$on('ROOT_TENANT_CHANGED', function () {
69             $scope.getEndpointsList();
70         });
71     }
72 });