EPG CRUD
[groupbasedpolicy.git] / groupbasedpolicy-ui / module / src / main / resources / gbp / epg / epg.controller.js
1 define([
2     'app/gbp/epg/epg.service',
3     'app/gbp/epg/epg-list.service',
4 ], function() {
5     'use strict';
6
7     angular.module('app.gbp').controller('EpgController', EpgController);
8
9     EpgController.$inject = ['$scope', '$stateParams', '$mdDialog', 'EpgService', 'EpgListService'];
10
11     function EpgController($scope, $stateParams, $mdDialog, EpgService, EpgListService) {
12         $scope.epgsTableQuery = {};
13
14         // $scope.epg = EpgService.createObject();
15         // $scope.epg.get($stateParams.epgId, $stateParams.tenantId);
16
17         $scope.epgs = EpgListService.createList();
18
19         /* methods */
20         $scope.getEpgList = getEpgList;
21         $scope.openEpgDialog = openEpgDialog;
22         $scope.deleteEpgDialog = deleteEpgDialog;
23
24         init();
25
26         /* Implementations */
27
28         /**
29          * fills $scope.epgs array with data from data store
30          */
31         function getEpgList() {
32             if($stateParams.tenantId) {
33                 $scope.epgs = EpgListService.createList();
34                 $scope.epgs.get('config', $stateParams.tenantId);
35             }
36             else {
37                 $scope.epgs = EpgListService.createList();
38                 $scope.epgs.get('config', $scope.rootTenant);
39             }
40         }
41
42         /**
43          * Initializing function
44          */
45         function init() {
46             $scope.epgsTableQuery = {
47                 order: 'data.id',
48                 limit: 25,
49                 page: 1,
50                 options: [25, 50, 100],
51                 filter: ''
52             };
53
54             getEpgList();
55         }
56
57         function openEpgDialog(epgData) {
58             $mdDialog.show({
59                 clickOutsideToClose: true,
60                 controller: 'AddEpgController',
61                 preserveScope: true,
62                 templateUrl: 'src/app/gbp/epg/dialog-add-epg.tpl.html',
63                 parent: angular.element(document.body),
64                 scope: $scope,
65                 locals: {
66                     epg: epgData
67                 }
68             });
69         }
70
71         function deleteEpgDialog(epgData) {
72             var confirm = $mdDialog.confirm()
73                 .title('Delete EPG')
74                 .textContent('Do you want to delete EPG ' + epgData.data.name + '?')
75                 .ok('Delete')
76                 .cancel('Cancel');
77
78             $mdDialog.show(confirm).then(function() {
79                 epgData.deleteEpg($scope.rootTenant,
80                     function() {
81                         $scope.getEpgList();
82                     }
83                 );
84             }, function() {
85
86             });
87         }
88     }
89 });