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() {
43 $scope.updateCesView = function() {
44 CpeuiSvc.getCes(function(ces) {
49 $scope.cesDialog = new CpeuiDialogs.Dialog('AddCE', {}, function(obj) {
50 CpeuiSvc.addCe(obj.id, obj.name, function() {
51 $scope.updateCesView();
55 $scope.deleteCe = function(tenantid, ceid) {
56 CpeuiDialogs.confirm(function() {
57 CpeuiSvc.removeCe(ceid, function() {
58 $scope.updateCesView();
63 $scope.assignCpeToTenant = function(cpeId) {
64 CpeuiDialogs.customConfirm("Are You Sure?",
65 "Are you sure you want to override all this CPE's unis tenants?",
67 for (var i = 0; i < $scope.unis.length; ++i) {
68 if ($scope.unis[i].device == cpeId) {
69 CpeuiSvc.updateUni($scope.unis[i]['uni-id'],
70 $scope.selectedTenant[cpeId]);
74 $scope.selectedTenant[cpeId] = undefined;
78 $scope.assignNetworkToTenant = function(svc) {
79 CpeuiDialogs.customConfirm("Are You Sure?",
80 "Are you sure you want to assign service "+ svc['svc-id'] +" to tenant " + $scope.selectedTenant[svc['svc-id']] +"?",
82 CpeuiSvc.addTenantToService(svc['svc-id'], $scope.selectedTenant[svc['svc-id']], function(){
83 svc['tenant-id'] = $scope.selectedTenant[svc['svc-id']];
85 $scope.selectedTenant[svc['svc-id']] = undefined;
88 $scope.selectedTenant[svc['svc-id']] = undefined;
92 function updateCpeTenants(unis) {
93 // update tenant cpe tenant column
94 var hasMultipleTenants = [];
95 var device2tenant = {};
96 for (var i = 0; i < $scope.unis.length; ++i) {
97 var tenant = $scope.unis[i]["tenant-id"];
99 if (hasMultipleTenants.indexOf($scope.unis[i].device) != -1) {
102 if (device2tenant[$scope.unis[i].device] == undefined) {
104 device2tenant[$scope.unis[i].device] = tenant;
106 device2tenant[$scope.unis[i].device] = ""; // none
108 } else if (device2tenant[$scope.unis[i].device] != tenant) {
109 if ((device2tenant[$scope.unis[i].device] != "") || (tenant)) {
110 device2tenant[$scope.unis[i].device] = true; // multiple
111 hasMultipleTenants.push($scope.unis[i].device);
115 var devices = Object.keys(device2tenant);
116 for (var i = 0; i < devices.length; ++i) {
117 if (device2tenant[devices[i]] == true) {
118 $scope.selectedTenant[devices[i]] = undefined;
120 $scope.selectedTenant[devices[i]] = device2tenant[devices[i]];
126 $scope.updateUniView = function() {
127 CpeuiSvc.getUnis(function(unis) {
129 updateCpeTenants(unis);
133 $scope.linkUniDialog = new CpeuiDialogs.Dialog('LinkUni', {}, function(
135 CpeuiSvc.updateUni(obj.id, obj.tenant, function() {
136 $scope.updateUniView();
140 $scope.deleteUni = function(id) {
141 CpeuiDialogs.confirm(function() {
142 CpeuiSvc.removeUni(id, function() {
143 $scope.updateUniView();
148 $scope.addCEName = function(ce){
150 var input = $('#INPUT_' +ce['dev-id']);
151 // hack to focus input after show is complete
152 setTimeout(function(){input.focus();},20);
153 input.parent().on('blur',function(){
154 setTimeout(function(){
160 input.bind("keyup", function (eventSubmit) {
161 if(eventSubmit.which === 13) {
162 $('#OK_' +ce['dev-id']).click();
163 } else if(eventSubmit.which === 27) {
164 input.parent().blur();
169 $scope.renameCE = function(ce){
170 CpeuiSvc.addCeName(ce, ce._new_name, function(){
171 ce['device-name'] = ce._new_name;
176 $scope.services = [];
177 $scope.networkNames = {};
179 $scope.updateNetworksView = function() {
180 CpeuiSvc.getAllServices(function(services) {
181 $scope.services = services;
183 CpeuiSvc.getNetworkNames(function(networks){
184 networks.forEach(function(net){
185 $scope.networkNames[net.uuid] = net.name;
191 $scope.updateView = function() {
192 if ($scope.isTabSet('admin',4)){
193 $scope.updateNetworksView();
195 $scope.updateTenantView();
196 $scope.updateCesView();
197 $scope.updateUniView();