1 define([ 'app/cpeui/cpeui.module' ], function(cpeui) {
3 cpeui.register.controller('AdminPageCtrl',
4 function($scope, CpeuiSvc, CpeuiDialogs, $mdDialog, $mdMedia) {
8 $scope.selectedTenant = {};
10 $scope.updateTenantView = function() {
11 CpeuiSvc.getTenantList(function(tenant_list) {
12 $scope.tenantArray = tenant_list;
16 $scope.AddTenant = function() {
17 CpeuiSvc.addTenant($scope.tenantId, function() {
22 $scope.tenantDialog = new CpeuiDialogs.Dialog('AddTenant', {},
24 CpeuiSvc.addTenant(obj.id, function() {
29 $scope.OpenTenantPortal = function(tenant) {
30 $scope.currentTenent = tenant;
31 window.location = "#cpeui/tenant/" + tenant.name +"/";
34 $scope.DeleteTenant = function(tenantID) {
35 CpeuiDialogs.confirm(function() {
36 CpeuiSvc.deleteTenant(tenantID, function() {
44 $scope.updateProfilesView = function() {
45 CpeuiSvc.getProfiles(function(profiles) {
46 $scope.profiles = profiles;
50 $scope.addProfile = new CpeuiDialogs.Dialog('AddProfile', {}, function(obj) {
51 CpeuiSvc.addProfile(obj['bw-profile'], obj.cir, obj.cbs, function() {
52 $scope.updateProfilesView();
56 $scope.deleteProfile = function(profileName) {
57 CpeuiDialogs.confirm(function() {
58 CpeuiSvc.deleteProfile(profileName, function() {
59 $scope.updateProfilesView();
65 $scope.updateCesView = function() {
66 CpeuiSvc.getCes(function(ces) {
71 $scope.cesDialog = new CpeuiDialogs.Dialog('AddCE', {}, function(obj) {
72 CpeuiSvc.addCe(obj.id, obj.name, function() {
73 $scope.updateCesView();
77 $scope.deleteCe = function(tenantid, ceid) {
78 CpeuiDialogs.confirm(function() {
79 CpeuiSvc.removeCe(ceid, function() {
80 $scope.updateCesView();
85 $scope.assignCpeToTenant = function(cpeId) {
86 CpeuiDialogs.customConfirm("Are You Sure?",
87 "Are you sure you want to override all this CPE's unis tenants?",
89 for (var i = 0; i < $scope.unis.length; ++i) {
90 if ($scope.unis[i].device == cpeId) {
91 CpeuiSvc.updateUni($scope.unis[i]['uni-id'],
92 $scope.selectedTenant[cpeId]);
96 $scope.selectedTenant[cpeId] = undefined;
100 $scope.assignNetworkToTenant = function(svc) {
101 CpeuiDialogs.customConfirm("Are You Sure?",
102 "Are you sure you want to assign service "+ svc['svc-id'] +" to tenant " + $scope.selectedTenant[svc['svc-id']] +"?",
104 CpeuiSvc.addTenantToService(svc['svc-id'], $scope.selectedTenant[svc['svc-id']], function(){
105 svc['tenant-id'] = $scope.selectedTenant[svc['svc-id']];
107 $scope.selectedTenant[svc['svc-id']] = undefined;
110 $scope.selectedTenant[svc['svc-id']] = undefined;
114 function updateCpeTenants(unis) {
115 // update tenant cpe tenant column
116 var hasMultipleTenants = [];
117 var device2tenant = {};
118 for (var i = 0; i < $scope.unis.length; ++i) {
119 var tenant = $scope.unis[i]["tenant-id"];
121 if (hasMultipleTenants.indexOf($scope.unis[i].device) != -1) {
124 if (device2tenant[$scope.unis[i].device] == undefined) {
126 device2tenant[$scope.unis[i].device] = tenant;
128 device2tenant[$scope.unis[i].device] = ""; // none
130 } else if (device2tenant[$scope.unis[i].device] != tenant) {
131 if ((device2tenant[$scope.unis[i].device] != "") || (tenant)) {
132 device2tenant[$scope.unis[i].device] = true; // multiple
133 hasMultipleTenants.push($scope.unis[i].device);
137 var devices = Object.keys(device2tenant);
138 for (var i = 0; i < devices.length; ++i) {
139 if (device2tenant[devices[i]] == true) {
140 $scope.selectedTenant[devices[i]] = undefined;
142 $scope.selectedTenant[devices[i]] = device2tenant[devices[i]];
148 $scope.updateUniView = function() {
149 CpeuiSvc.getUnis(function(unis) {
151 updateCpeTenants(unis);
155 $scope.linkUniDialog = new CpeuiDialogs.Dialog('LinkUni', {}, function(
157 CpeuiSvc.updateUni(obj.id, obj.tenant, function() {
158 $scope.updateUniView();
162 $scope.deleteUni = function(id) {
163 CpeuiDialogs.confirm(function() {
164 CpeuiSvc.removeUni(id, function() {
165 $scope.updateUniView();
170 $scope.addCEName = function(ce){
172 var input = $('#INPUT_' +ce['dev-id']);
173 // hack to focus input after show is complete
174 setTimeout(function(){input.focus();},20);
175 input.parent().on('blur',function(){
176 setTimeout(function(){
182 input.bind("keyup", function (eventSubmit) {
183 if(eventSubmit.which === 13) {
184 $('#OK_' +ce['dev-id']).click();
185 } else if(eventSubmit.which === 27) {
186 input.parent().blur();
191 $scope.renameCE = function(ce){
192 CpeuiSvc.addCeName(ce, ce._new_name, function(){
193 ce['device-name'] = ce._new_name;
198 $scope.services = [];
199 $scope.networkNames = {};
201 $scope.updateNetworksView = function() {
202 CpeuiSvc.getAllServices(function(services) {
203 $scope.services = services;
205 CpeuiSvc.getNetworkNames(function(networks){
206 networks.forEach(function(net){
207 $scope.networkNames[net.uuid] = net.name;
213 $scope.updateView = function() {
214 if ($scope.isTabSet('admin',4)){
215 $scope.updateNetworksView();
217 $scope.updateTenantView();
218 $scope.updateCesView();
219 $scope.updateUniView();
220 $scope.updateProfilesView()