16a92fa29129134ba5db6c42e98843f5e732446d
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / tenant / tenant.controller.js
1 define([
2     'app/gbp/tenant/tenant.service',
3     'app/gbp/tenant/tenant-list.service',
4 ], function () {
5     'use strict';
6
7     angular.module('app.gbp').controller('TenantController', TenantController);
8
9     TenantController.$inject = ['$mdDialog', '$scope', 'TenantListService'];
10     /* @ngInject */
11     function TenantController($mdDialog, $scope, TenantListService) {
12         /* properties */
13         $scope.tenants = TenantListService.createList();
14         $scope.tenantsTableQuery = {};
15
16         /* methods */
17         $scope.getTenantList = getTenantList;
18         $scope.openTenantDialog = openTenantDialog;
19         $scope.deleteTenantDialog = deleteTenantDialog;
20
21         init();
22
23         /* Implementations */
24
25         /**
26          * fills $scope.tenants array with data from data store
27          */
28         function getTenantList() {
29             $scope.tenants = TenantListService.createList();
30             $scope.tenants.get('config');
31         }
32
33         /**
34          * Initializing function
35          */
36         function init() {
37             $scope.tenantsTableQuery = {
38                 order: "data.id",
39                 limit: 25,
40                 page: 1,
41                 options: [25, 50, 100],
42                 filter: ''
43             };
44
45             getTenantList();
46         }
47
48         function openTenantDialog(tenantData) {
49             $mdDialog.show({
50                 clickOutsideToClose: true,
51                 controller: 'AddTenantController',
52                 preserveScope: true,
53                 templateUrl: 'src/app/gbp/tenant/dialog-add-tenant.tpl.html',
54                 parent: angular.element(document.body),
55                 scope: $scope,
56                 locals: {
57                     tenant: tenantData
58                 }
59             });
60         }
61
62         function deleteTenantDialog(tenantData) {
63             var confirm = $mdDialog.confirm()
64                 .title('Delete tenant')
65                 .textContent('Do you want to delete tenant ' + tenantData.data.name + '?')
66                 .ok('Delete')
67                 .cancel('Cancel');
68
69             $mdDialog.show(confirm).then(function() {
70                 tenantData.deleteTenant(
71                     function() {
72                         $scope.getTenantList();
73                     }
74                 );
75             }, function() {
76
77             });
78         }
79
80     }
81 });