Merge "Use AAAShiroFilter as TokenAuthFilter was deprecated in Be"
[groupbasedpolicy.git] / groupbasedpolicy-old-ui / module / src / main / resources / gbp-old / gbp.controller.js
1 var modules = ['app/gbp-old/gbp.module',
2                'app/gbp-old/gbp.services'
3                ];
4
5
6 define(modules, function(gbpOld) {
7
8     gbpOld.register.controller('gbpCtrl', ['$scope', '$rootScope', 'GBPTenantServices','DesignGbpFactory', 'GBPConstants',
9         function ($scope, $rootScope, GBPTenantServices, DesignGbpFactory, GBPConstants) {
10             $rootScope['section_logo'] = 'logo_gbp';
11             $scope.view_path =  'src/app/gbp-old/views/';
12
13             $scope.mainView = {
14                 main: true,
15                 'policy-renderer': false,
16                 governance: false
17             };
18
19             $scope.policyRendererView = {
20                 slider : true,
21                 basic : true,
22                 policy: false,
23                 tenants : false,
24                 l2l3 : false,
25                 epg : false,
26                 contracts : false,
27                 docs : false,
28                 groupMenu: false,
29                 classifiers: false,
30                 actions: false,
31                 registerEndpoint : false,
32                 registerL3PrefixEndpoint : false
33             };
34
35             $scope.subMenuView = {
36                 governance : false,
37                 policy : false,
38                 policySub : false,
39                 renderers : false,
40                 endpoints : false
41             };
42
43             $scope.breadcrumbs = {'l1' : null,
44                                   'l2' : null,
45                                   'l3' : null};
46
47             $scope.wizards = {
48                 accessModelWizard: false,
49                 actionReferenceWizard: false
50             };
51
52             $scope.setBreadcrumb = function(level, label, visible){
53                 $scope.breadcrumbs[level] = visible ? label : null;
54                 if(level === 'l1'){
55                     $scope.breadcrumbs.l2 = null;
56                     $scope.breadcrumbs.l3 = null;
57                 }
58                 if(level === 'l2'){
59                     $scope.breadcrumbs.l3 = null;
60                 }
61             };
62
63             $scope.setViewExpand = function(menu, expand, show){
64                 $scope[menu][expand] = show ? true : !$scope[menu][expand];
65                 for ( var property in $scope[menu] ) {
66                     $scope[menu][property] = expand !== property ? false : $scope[menu][expand];
67                 }
68
69             };
70
71             $scope.toggleExpandedMM = function(expand, show, broadcast){
72                 $scope.setViewExpand('mainView',expand, show);
73
74                 if ( broadcast ) {
75                     $scope.$broadcast(broadcast);
76                 }
77             };
78
79             $scope.sliceLabel = function(label){
80                 return label.length > GBPConstants.numbers.displayLabelLength ? label.slice(0,GBPConstants.numbers.displayLabelLength)+'...' : label;
81             };
82
83             $scope.getDisplayLabel = function(obj, labelArray, dontSlice){
84                 var ret = '';
85
86                 if((typeof labelArray) === 'string'){
87                     ret = obj[labelArray];
88                 } else if (angular.isFunction(labelArray)) {
89                     ret = labelArray(obj);
90                 } else {
91                     labelArray.some(function(labelParam) {
92                         if(angular.isFunction(labelParam)) {
93                             ret = labelParam(obj);
94                         } else if(obj.hasOwnProperty(labelParam)) {
95                             ret = obj[labelParam];
96                         }
97                         return ret;
98                     });
99                 }
100
101                 return dontSlice ? ret : $scope.sliceLabel(ret);
102             };
103
104             // TENANTS
105             $scope.tenantList = [];
106             $scope.selectedTenant = null;
107             $scope.tenantDisplayLabel = ['name' , 'id'];
108
109             $scope.loadTenants = function() {
110                 GBPTenantServices.load(
111                     function(tenants) {
112                         $scope.tenantList = tenants;
113                         console.log('$scope.tenantList', $scope.tenantList);
114                     },
115                     function(){
116                         //TODO error
117                     });
118
119                 DesignGbpFactory.setMainClass();
120             };
121
122             $scope.setTenant = function(selectedTenant) {
123                 $scope.selectedTenant = selectedTenant;
124                 $scope.$broadcast('GBP_TENANT_RELOAD', $scope.selectedTenant);
125             };
126
127             $scope.loadTenants();
128
129             $scope.$on('GBP_GLOBAL_TENANT_RELOAD',function(){
130                 $scope.loadTenants();
131             });
132
133             $scope.sendReloadEventFromRoot = function(eventName, val) {
134                 $scope.$broadcast(eventName, val);
135             };
136
137
138             // TODO: rework, use $scope.setViewContent or something
139             $scope.showWizard = function(wizardName, broadcast, broadcastedData, path) {
140                 $scope.wizards[wizardName] = true;
141
142                 if ( broadcast ) {
143                     $scope.sendReloadEventFromRoot(broadcast, {data: broadcastedData, path: path});
144                 }
145             };
146
147             $scope.closeWizard = function(wizardName) {
148                 $scope.wizards[wizardName] = false;
149             };
150
151             $scope.updateList = function(list, object, key) {
152                 var elementPos = list.map(function(x) {return x[key]; }).indexOf(object[key]);
153
154                 if(elementPos < 0) {
155                     list.push(object);
156                 }
157                 else {
158                     list[elementPos] = object;
159                 }
160             };
161
162     }]);
163
164     gbpOld.register.controller('governanceCtrl', ['$rootScope','$scope',
165         function ($rootScope, $scope) {
166             $scope.menuTpl = 'main-menu';
167             $scope.menuBox = null;
168             $scope.contentTpl = 'main';
169             // $scope.selectedTenant = null;
170             $scope.rendererList = [];
171             var broadcastObj = {};
172
173             $scope.rendererList.push({'name' : 'of_overlay', 'id' : 0});
174
175             $scope.toggleExpanded = function(expand, menu, tplType){
176                 var type = tplType ? tplType : 'contentTpl';
177                 $scope.menuBox = null;
178
179                 $scope[type] = expand;
180
181                 if ( menu && menu === false ) {
182                     $scope.menuTpl = !menu ? null : menu;
183                 }
184             };
185
186
187
188             $scope.setViewContent = function(tplName, data, broadcast, tplType) {
189
190                 if ( $scope[tplType] === tplName ) {
191                     $scope.$broadcast(broadcast, data, true);
192                 } else {
193
194                     broadcastObj[tplType] = {};
195                     broadcastObj[tplType].name = broadcast;
196                     broadcastObj[tplType].data = data;
197
198                     $scope.toggleExpanded(tplName, null, tplType);
199                     $scope.$apply();
200
201                 }
202             };
203
204             $scope.broadcastCalling = function(tplType){
205                 $scope.$broadcast(broadcastObj[tplType].name, broadcastObj[tplType].data);
206             };
207
208             $scope.checkBroadcastCalling = function(tplName){
209                 var objClickAction = {
210                     'epg-detail': function(){
211                         $scope.broadcastCalling('contentTpl');
212                     },
213                     'subject-detail': function(){
214                         $scope.broadcastCalling('contentTpl');
215                     }
216                 };
217
218                 if ( angular.isFunction(objClickAction[tplName]) ) {
219                     objClickAction[tplName]();
220                 }
221
222             };
223
224
225             $scope.$on('GOV_INIT', function(){
226                 $scope.menuTpl = 'main-menu';
227                 $scope.contentTpl = 'main';
228                 // $scope.$emit('GBP_GLOBAL_TENANT_RELOAD');
229                 $scope.menuBox = null;
230             });
231
232             $scope.$on('GBP_TENANT_RELOAD', function(e, obj){
233                 $scope.selectedTenant = obj;
234             });
235
236
237     }]);
238
239     gbpOld.register.controller('boxStaticCtrl',['$scope',
240         function($scope){
241
242         $scope.selectedObj = null;
243
244         $scope.getLabel = function(id, type){
245                 var objAction = {
246                 providerItems: function(){
247                     var name = $scope.selectedObj[type][id].attributes.objData['name'];
248                     return name ? name + ' : ' + id : id;
249                 },
250                 consumerItems: function(){
251                     var name = $scope.selectedObj[type][id].attributes.objData['name'];
252                     return name ? name + ' : ' + id : id;
253                 }
254             };
255
256             if ( angular.isFunction(objAction[type]) ) {
257                 return objAction[type]();
258             }
259         };
260
261         $scope.$on('SET_SEL_STA_OBJ', function(obj, data, apply){
262             $scope.selectedObj = data;
263
264             if ( apply ) {
265                 $scope.$apply();
266             }
267
268         });
269
270     }]);
271
272     gbpOld.register.controller('graphCtrl', ['$scope', function($scope){
273         var paper = null,
274             paperScale = 1;
275
276         $scope.init = function(paperInstance){
277             paper = paperInstance;
278             $scope.loadMouseScrollEvent();
279         };
280
281
282         $scope.zoom = function(out){
283             paperScale = out ? paperScale - 0.1 : paperScale >= 1 ? 1 : paperScale + 0.1;
284             paper.scale(paperScale, paperScale);
285         };
286
287
288
289         $scope.loadMouseScrollEvent = function(){
290             /*mouse wheel event for zooming*/
291             var graph = document.getElementById('graph'),
292             MouseWheelHandler = function(e){
293                 var mouseEvent = window.event || e; // old IE support
294                 var delta = Math.max(-1, Math.min(1, (mouseEvent.wheelDelta || -mouseEvent.detail)));
295                 $scope.zoom(delta === 1 ? false : true);
296             };
297
298             if (graph.addEventListener) {
299                 // IE9, Chrome, Safari, Opera
300                 graph.addEventListener("mousewheel", MouseWheelHandler, false);
301                 // Firefox
302                 graph.addEventListener("DOMMouseScroll", MouseWheelHandler, false);
303             }
304             // IE 6/7/8
305             else {graph.attachEvent("onmousewheel", MouseWheelHandler);}
306             /*mouse wheel event for zooming - end*/
307         };
308
309     }]);
310
311     gbpOld.register.controller('expressedPolicyCtrl', ['$scope', 'JointGraphFactory', 'JointGraphOffsetFactory', 'GBPConstants',
312         function ($scope, JointGraphFactory, JointGraphOffsetFactory, GBPConstants) {
313             var paper = JointGraphFactory.createGraph(),
314                 epgItems = [],
315                 contractItems = [],
316                 linkItems = [];
317
318             var objClickAction = {
319                 epg: function(data){
320                     $scope.setViewContent('epg-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
321                 },
322                 contract: function(data){
323                     $scope.setViewContent('contract-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
324                 }
325             };
326
327             paper.on('cell:pointerdown', function(cell) {
328                 if ( angular.isFunction(objClickAction[cell.model.attributes.objType]) ) {
329                     objClickAction[cell.model.attributes.objType](cell.model.attributes.objData);
330                 }
331             });
332
333             var createEpgLinks = function(epg, epgItem, contracts) {
334                 var providers = epg['provider-named-selector'] && epg['provider-named-selector'].length>0 ? epg['provider-named-selector'] : [];
335                 var consumers = epg['consumer-named-selector'] && epg['consumer-named-selector'].length>0 ? epg['consumer-named-selector'] : [];
336                 var consumerLinkItems = [];
337                 var providerLinkItems = [];
338
339                 consumers.forEach(function(c) {
340                     c.contract.forEach(function(con) {
341                         consumerLinkItems.push(JointGraphFactory.createLink(contracts[con].id, epgItem.id, 'green'));
342                     });
343                 });
344
345                 providers.forEach(function(p) {
346                     p.contract.forEach(function(con) {
347                         providerLinkItems.push(JointGraphFactory.createLink(epgItem.id, contracts[con].id, 'blue'));
348                     });
349                 });
350
351                 JointGraphFactory.addItemList(paper.model, providerLinkItems);
352                 JointGraphFactory.addItemList(paper.model, consumerLinkItems);
353
354             };
355
356             var loadData = function() {
357                 if($scope.selectedTenant) {
358                     var offsetObj = {
359                             ow: 100,
360                             oh: 100,
361                             w: 100,
362                             h: 100
363                         },
364                         marginObj = {
365                             w: 50,
366                             h: 80
367                         },
368                         offsetHobj = {
369                             contract: 0,
370                             epg: 0
371                         },
372                         itemsArray = {
373                             contract: [],
374                             epg: []
375                         };
376
377                     JointGraphFactory.reloadGraph(paper.model);
378
379                     if ( $scope.selectedTenant && $scope.selectedTenant.contract ) {
380
381                         $scope.selectedTenant.contract.forEach(function(c, i) {
382                             var label = c.description ? $scope.sliceLabel(c.description) : c.id,
383                                 width = JointGraphFactory.getLabelLength(label.length);
384                                 item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.contract, c, 'Click to see contract info', GBPConstants.colors.graph['subject'], 'Contract');
385
386                             itemsArray.contract.push(item);
387
388                             JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width, paper.options.height), paper);
389                             JointGraphFactory.addItem(paper.model, item);
390                             contractItems[c.id] = item;
391                         });
392
393                         offsetHobj.contract = offsetObj.h;
394
395                     }
396
397                     if ( $scope.selectedTenant && $scope.selectedTenant['endpoint-group'] ) {
398
399                         JointGraphOffsetFactory.resetOffsets(offsetObj, offsetObj.ow, offsetObj.h > 400 ? offsetObj.h : 400);
400                         $scope.selectedTenant['endpoint-group'].forEach(function(e, i) {
401                             var label = e.name || e.id,
402                                 width = JointGraphFactory.getLabelLength(label.length);
403                                 item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.epg, e, 'Click to see epg info', GBPConstants.colors.graph['pns'], 'EP group');
404
405                             itemsArray.epg.push(item);
406
407                             JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width, paper.options.height), paper);
408                             JointGraphFactory.addItem(paper.model, item);
409                             epgItems[e.id] = item;
410
411                             createEpgLinks(e, item, contractItems);
412                         });
413
414                     }
415
416                     offsetHobj.epg = JointGraphOffsetFactory.getCurrentOffset(itemsArray.contract, 'y');
417                     JointGraphOffsetFactory.checkObjsHoffsets(itemsArray.epg ,offsetHobj.epg, paper);
418                 }
419
420             };
421
422             $scope.getPaperObj = function(){
423                 return paper;
424             };
425
426             $scope.$on('GBP_TENANT_RELOAD',function(){
427                 if ($scope.selectedTenant) {
428                     loadData();
429                 }
430                 else {
431                     JointGraphFactory.reloadGraph(paper.model);
432                 }
433             });
434
435             loadData();
436     }]);
437
438     gbpOld.register.controller('deliveredPolicyCtrl', ['$scope', 'GPBServices', 'JointGraphFactory', 'GBPGovernanceServices', 'JointGraphOffsetFactory', 'GBPConstants',
439         function ($scope, GPBServices, JointGraphFactory, GBPGovernanceServices, JointGraphOffsetFactory, GBPConstants) {
440             var paper = JointGraphFactory.createGraph(),
441                 providerItems = {},
442                 consumerItems = {},
443                 subjectItems = {};
444
445             var getEpList = function() {
446                 var providerEpKeys = Object.keys(providerItems),
447                     consumerEpKeys = Object.keys(consumerItems),
448                     epList = providerEpKeys.map(function (k) {
449                         return providerItems[k].attributes.objData;
450                     });
451
452                 consumerEpKeys.forEach(function(k) {
453                     if(providerEpKeys.indexOf(k) === -1) {
454                         epList.push(consumerItems[k].attributes.objData);
455                     }
456                 });
457
458                 return epList;
459             };
460
461             var getSubjList = function() {
462                 return Object.keys(subjectItems).map(function (k) {
463                     return subjectItems[k].attributes.objData;
464                 });
465             };
466
467             var objClickAction = {
468                 subject: function(data){
469                         data.providerItems = providerItems;
470                         data.consumerItems = consumerItems;
471                     $scope.setViewContent('subject-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
472                 },
473                 consumer: function(data) {
474                     $scope.setViewContent('epg-content-static', data, 'SET_SEL_STA_OBJ', 'menuBox');
475                 },
476                 provider: function(data) {
477                     $scope.setViewContent('epg-content-static', data, 'SET_SEL_STA_OBJ', 'menuBox');
478                 }
479             };
480
481             var objDblClickAction = {
482                 consumer: function(data){
483                        $scope.setBreadcrumb('l3', 'Endpoint group detail', true);
484                        $scope.setViewContent('epg-detail', { ep: data, epList: getEpList() }, 'SET_SELECTED_EPG','contentTpl');
485                 },
486                 provider: function(data){
487                        $scope.setBreadcrumb('l3', 'Endpoint group detail', true);
488                        $scope.setViewContent('epg-detail', { ep: data, epList: getEpList() }, 'SET_SELECTED_EPG','contentTpl');
489                 },
490                 subject: function(data) {
491                         var obj = { subject: data,
492                                     subjList: Object.keys(subjectItems).map(function (k) {
493                                                 return subjectItems[k].attributes.objData;
494                                             }),
495                                     providerItems: providerItems,
496                                     consumerItems: consumerItems
497                                 };
498                         $scope.setBreadcrumb('l3', 'Subject detail', true);
499                         $scope.setViewContent('subject-detail', obj, 'SET_SELECTED_SUBJECT','contentTpl');
500                 }
501             };
502
503             paper.on('cell:pointerdown', function(cell) {
504                 if ( angular.isFunction(objClickAction[cell.model.attributes.objType]) ) {
505                     objClickAction[cell.model.attributes.objType](cell.model.attributes.objData);
506                 }
507             });
508
509             paper.on('cell:pointerdblclick', function(cell) {
510                 objDblClickAction[cell.model.attributes.objType](cell.model.attributes.objData);
511             });
512
513             var createSubjectLinks = function(subject, subjectItem, providerItems, consumerItems) {
514                 var providerLinkItems = subject.providers.map(function(p) {
515                         return JointGraphFactory.createLink(providerItems[p].id, subjectItem.id, 'green');
516                     });
517                     consumerLinkItems = subject.consumers.map(function(c) {
518                         return JointGraphFactory.createLink(subjectItem.id, consumerItems[c].id, 'blue');
519                     });
520
521                 JointGraphFactory.addItemList(paper.model, providerLinkItems);
522                 JointGraphFactory.addItemList(paper.model, consumerLinkItems);
523             };
524
525             var loadData = function() {
526                 if($scope.selectedTenant) {
527                     providerItems = {};
528                     consumerItems = {};
529                     subjectItems = {};
530
531                     var classifierInstances = $scope.selectedTenant['subject-feature-instances'] &&
532                                           $scope.selectedTenant['subject-feature-instances']['classifier-instance'] &&
533                                           $scope.selectedTenant['subject-feature-instances']['classifier-instance'].length > 0 ? $scope.selectedTenant['subject-feature-instances']['classifier-instance'] : [];
534
535                     var offsetObj = {
536                             ow: 100,
537                             oh: 100,
538                             w: 100,
539                             h: 100
540                         },
541                         marginObj = {
542                             w: 50,
543                             h: 80
544                         },
545                         offsetHobj = {
546                             pEpg: 0,
547                             cEpg: 0,
548                             subject: 0
549                         },
550                         itemsArray = {
551                             pEpg: [],
552                             cEpg: [],
553                             subject: []
554                         };
555
556                     JointGraphFactory.reloadGraph(paper.model);
557
558                     GBPGovernanceServices.getEPGsAndSubjects($scope.selectedTenant.id, classifierInstances, function(data){
559                         data.providers.forEach(function(p, i) {
560                             var relatedObj = GPBServices.getPropFromListByProp($scope.selectedTenant['endpoint-group'], 'id', p.id),
561                                 label = relatedObj.name || p.id,
562                                 width = JointGraphFactory.getLabelLength(label.length);
563
564                             relatedObj.rules = p.rules;
565                             var item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.provider, relatedObj, 'Click to see epg info, doubleclick to see Endpoint group detail', GBPConstants.colors.graph['pns'], 'Provider EPG');
566
567                             itemsArray.pEpg.push(item);
568
569                             JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width, paper.options.height), paper);
570                             JointGraphFactory.addItem(paper.model, item);
571                             providerItems[p.id] = item;
572                         });
573
574                         offsetHobj.pEpg = offsetObj.h;
575
576                         JointGraphOffsetFactory.resetOffsets(offsetObj, offsetObj.ow, 500);
577                         data.consumers.forEach(function(c, i) {
578                             var relatedObj = GPBServices.getPropFromListByProp($scope.selectedTenant['endpoint-group'], 'id', c.id),
579                                 label = relatedObj.name || c.id,
580                                 width = JointGraphFactory.getLabelLength(label.length);
581
582                             relatedObj.rules = c.rules;
583                             var item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.consumer, relatedObj, 'Click to see epg info, doubleclick to see Endpoint group detail', GBPConstants.colors.graph['cns'], 'Consumer EPG');
584
585                             itemsArray.cEpg.push(item);
586
587                             JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width, paper.options.height), paper);
588                             JointGraphFactory.addItem(paper.model, item);
589                             consumerItems[c.id] = item;
590                         });
591
592                         JointGraphOffsetFactory.resetOffsets(offsetObj, offsetObj.ow, offsetHobj.pEpg > 300 ? offsetHobj.pEpg : 300);
593                         data.subjects.forEach(function(s, i) {
594                             var label = s.name,
595                                 width = JointGraphFactory.getLabelLength(label.length),
596                                 item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.subject, s, 'Click to see subject info, doubleclick to see Subject detail', GBPConstants.colors.graph['subject'], 'Subject');
597
598                             itemsArray.subject.push(item);
599
600                             JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width, paper.options.height), paper);
601                             JointGraphFactory.addItem(paper.model, item);
602                             subjectItems[s.name] = item;
603                             createSubjectLinks(s, item, providerItems, consumerItems);
604                         });
605
606                         offsetHobj.pEpg = JointGraphOffsetFactory.getCurrentOffset(itemsArray.pEpg, 'y');
607                         JointGraphOffsetFactory.checkObjsHoffsets(itemsArray.subject ,offsetHobj.pEpg, paper);
608                         offsetHobj.subject = JointGraphOffsetFactory.getCurrentOffset(itemsArray.subject, 'y');
609                         JointGraphOffsetFactory.checkObjsHoffsets(itemsArray.cEpg ,offsetHobj.subject, paper);
610
611                     }, function(){});
612
613                 }
614
615
616                 // paper.scaleContentToFit();
617                 // paper.fitToContent();
618             };
619
620             $scope.getPaperObj = function(){
621                 return paper;
622             };
623
624
625             $scope.$on('GBP_TENANT_RELOAD',function(){
626                 if ($scope.selectedTenant) {
627                     loadData();
628                 }
629                 else {
630                     JointGraphFactory.reloadGraph(paper.model);
631                 }
632             });
633
634             loadData();
635     }]);
636
637     gbpOld.register.controller('subjectDetailCtrl', ['$scope', 'GPBServices', 'JointGraphFactory', 'GBPGovernanceServices', 'JointGraphOffsetFactory', 'GBPConstants',
638         function ($scope, GPBServices, JointGraphFactory, GBPGovernanceServices, JointGraphOffsetFactory, GBPConstants) {
639             $scope.selectedSubject = null;
640             $scope.subjectList = [];
641
642             var paper = JointGraphFactory.createGraph(),
643                 subjectItem = null,
644                 ruleItems = {},
645                 subjectItems = {};
646
647             var createSubjectLinks = function(subjectItem, ruleItem) {
648                 var linkItem = JointGraphFactory.createLink(subjectItem.id, ruleItem.id, 'blue');
649                 JointGraphFactory.addItem(paper.model, linkItem);
650             };
651
652             paper.on('cell:pointerdown', function(cell) {
653                 var objClickAction = {
654                     subject: function(data){
655                         $scope.setViewContent('subject-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
656                     },
657                     rule: function(data){
658                         $scope.setViewContent('rule-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
659                     }
660                 };
661
662                 // console.log('cell.model.attributes.objType', cell.model.attributes.objType, cell.model.attributes.objData);
663                 if ( angular.isFunction(objClickAction[cell.model.attributes.objType]) ) {
664                     objClickAction[cell.model.attributes.objType](cell.model.attributes.objData);
665                 }
666             });
667
668             var loadData = function() {
669                 if($scope.selectedSubject) {
670                     subjectItem = null;
671                     ruleItems = {};
672
673                     var offsetObj = {
674                             ow: 100,
675                             oh: 100,
676                             w: 100,
677                             h: 100
678                         },
679                         marginObj = {
680                             w: 50,
681                             h: 80
682                         };
683
684                     JointGraphFactory.reloadGraph(paper.model);
685
686                     var label = $scope.selectedSubject.name || $scope.selectedSubject.id,
687                         width = JointGraphFactory.getLabelLength(label.length);
688                         subjectItem = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.subject, $scope.selectedSubject, 'Click to see subject info', GBPConstants.colors.graph['subject'], 'Subject');
689
690                     JointGraphFactory.addItem(paper.model, subjectItem);
691
692                     JointGraphOffsetFactory.resetOffsets(offsetObj, offsetObj.ow, 300);
693                     $scope.selectedSubject.rules.forEach(function(r, i) {
694                         var label = r.name,
695                             width = JointGraphFactory.getLabelLength(label.length);
696                             item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, GBPConstants.objType.rule, r, 'Click to see rule info', GBPConstants.colors.graph['cns'], 'Rule');
697
698                         JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width), paper);
699                         JointGraphFactory.addItem(paper.model, item);
700                         ruleItems[r.name] = item;
701
702                         createSubjectLinks(subjectItem, item);
703                     });
704                 }
705             };
706
707             $scope.getPaperObj = function(){
708                 return paper;
709             };
710
711             $scope.$on('SET_SELECTED_SUBJECT', function(event, data){
712                 $scope.selectedSubject = data.subject;
713                 $scope.subjectList = data.subjList;
714                 loadData();
715             });
716
717             $scope.setSubject = function(subject) {
718                 $scope.selectedSubject = subject;
719                 loadData();
720             };
721
722             loadData();
723     }]);
724
725     gbpOld.register.controller('epgDetailCtrl', ['$scope', 'JointGraphFactory', 'TopologyDataLoaders', 'GBPEpgServices', 'JointGraphOffsetFactory', 'GBPConstants',
726         function ($scope, JointGraphFactory, TopologyDataLoaders, GBPEpgServices, JointGraphOffsetFactory, GBPConstants) {
727             var paper = JointGraphFactory.createGraph(),
728                 epgItem = {},
729                 epItems = {};
730
731             $scope.epgDisplayLabel = ['name', 'id'];
732             $scope.epgList = [];
733             $scope.selectedEpg = null;
734
735             $scope.$on('SET_SELECTED_EPG', function(event, epg){
736                 $scope.selectedEpg = epg.ep;
737                 $scope.epgList = epg.epList;
738                 loadData();
739             });
740
741             $scope.setEpg = function(epg){
742                 selectedEpg = epg;
743                 loadData();
744             };
745
746             paper.on('cell:pointerdown', function(cell) {
747                 var objClickAction = {
748                     ep: function(data){
749                         $scope.setViewContent('ep-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
750                     },
751                     epg: function(data){
752                         $scope.setViewContent('epg-content-static',data, 'SET_SEL_STA_OBJ', 'menuBox');
753                     },
754                 };
755
756                 if ( angular.isFunction(objClickAction[cell.model.attributes.objType]) ) {
757                     objClickAction[cell.model.attributes.objType](cell.model.attributes.objData);
758                 }
759             });
760
761             var loadData = function() {
762                 if($scope.selectedTenant && $scope.selectedEpg) {
763                     epgItem = {};
764                     epItems = {};
765                     links = [];
766
767                     JointGraphFactory.reloadGraph(paper.model);
768
769                     TopologyDataLoaders.getEndpointsFromEndpointGroup($scope.selectedTenant.id, $scope.selectedEpg.id, function(data){
770                        var offsetObj = {
771                             ow: 100,
772                             oh: 100,
773                             w: 100,
774                             h: 100
775                             },
776                             marginObj = {
777                                 w: 50,
778                                 h: 80
779                             };
780
781                         var label = $scope.selectedEpg.name || $scope.selectedEpg.id,
782                             width = JointGraphFactory.getLabelLength(label.length);
783                             epgItem = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, 'epg', $scope.selectedEpg, 'Click to see epg info', GBPConstants.colors.graph['subject'], 'EPG');
784
785                         JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width), paper);
786                         JointGraphFactory.addItem(paper.model, epgItem);
787
788                         JointGraphOffsetFactory.resetOffsets(offsetObj, offsetObj.ow, 500);
789                         if(data && data.output && data.output['ui-endpoint'] && data.output['ui-endpoint'].length){
790                             data.output['ui-endpoint'].forEach(function(ep, i){
791                                 var label = ep['mac-address'] + ':' + ep['l2-context'],
792                                     width = JointGraphFactory.getLabelLength(label.length);
793                                     item = JointGraphFactory.createElement(label, offsetObj.w, offsetObj.h, width, null, 'ep', ep, 'Click to see ep info', GBPConstants.colors.graph['pns'], 'Endpoint');
794
795                                 JointGraphOffsetFactory.updateOffsets(JointGraphOffsetFactory.createWHObj(width), offsetObj, marginObj, JointGraphOffsetFactory.createWHObj(paper.options.width), paper);
796                                 JointGraphFactory.addItem(paper.model, item);
797                                 epItems[label] = item;
798                                 links.push(JointGraphFactory.createLink(item.id, epgItem.id, 'green'));
799                             });
800
801                             JointGraphFactory.addItemList(paper.model, links);
802                         }
803                     }, function(){});
804                 }
805             };
806
807             $scope.getPaperObj = function(){
808                 return paper;
809             };
810
811             // init();
812     }]);
813
814     gbpOld.register.controller('policyRendererCtrl', ['$scope', '$http', '$timeout', 'PGNServices', 'TopoServices', 'GBPTenantServices', 'GBPConstants', 'JointGraphFactory','GBPJointGraphBuilder',
815         function ($scope, $http, $timeout, PGNServices, TopoServices, GBPTenantServices, GBPConstants, JointGraphFactory, GBPJointGraphBuilder) {
816
817             $scope.topologyData = { nodes: [], links: [] };
818             $scope.topologyType = null;
819             $scope.topologyArgs = {};
820             $scope.legend = {};
821             $scope.showLegend = false;
822
823             var paper = JointGraphFactory.createGraph();
824
825             var reloadShowLegend = function() {
826                 $scope.showLegend = !$.isEmptyObject($scope.legend);
827             };
828
829             $scope.settingsSigma = {
830                 defaultLabelColor: '#fff',
831                 doubleClickEnabled: false,
832                 labelThreshold: 8
833             };
834
835             $scope.settingsAtlas = {
836                 adjustSizes: true,
837                 gravity: 0.2
838             };
839
840             $scope.viewTopo = {
841                 box: false,
842                 button: false
843             };
844
845             paper.on('cell:pointerdown', function(cellView, evt) {
846                 if (cellView.model.isLink() && cellView.model.attributes.objData) {
847                     $scope.$broadcast('SET_LINK_DATA', cellView.model.attributes.objData);
848                 }
849             });
850
851             $scope.mandatoryProperties = [];
852             $scope.loadTopology = function(type, args) {
853                 if ($scope.selectedTenant) {
854                     $scope.topologyType = type;
855                     $scope.topologyArgs = args;
856                     GBPJointGraphBuilder.loadTopology(args, paper, type);
857                 }
858             };
859             $scope.toggleExpanded = function(expand, show) {
860                 $scope.setViewExpand('policyRendererView',expand, show, 'l2');
861
862                 if($scope.policyRendererView[expand] && $scope.selectedTenant) {
863                     $scope.topologyArgs.tenantId = $scope.selectedTenant.id;
864
865                     if((expand === 'epg' || expand === 'contracts' || expand === 'classifiers' || expand === 'actions' || expand === 'renderers') && ($scope.topologyType !== GBPConstants.strings.config)) {
866                         $scope.loadTopology(GBPConstants.strings.config, $scope.topologyArgs);
867                     } else if((expand === 'l2l3' || expand === 'registerEndpoint' || expand === 'registerL3PrefixEndpoint') && ($scope.topologyType !== GBPConstants.strings.l2l3)) {
868                         $scope.loadTopology(GBPConstants.strings.l2l3, $scope.topologyArgs);
869                     }
870                 }
871             };
872
873             $scope.reloadTopo = function() {
874                 if($scope.selectedTenant) {
875                     $scope.topologyArgs.tenantId = $scope.selectedTenant.id;
876                     GBPJointGraphBuilder.loadTopology($scope.topologyArgs, paper, $scope.topologyType);
877                 }
878             };
879
880             $scope.getDisplayLabelsFromCtrl = function(eventName, val) {
881                 $scope.$broadcast(eventName, val);
882             };
883
884             $scope.validateMandatory = function(newObj, mandatoryProps){
885                 var ret = true,
886                     notFilledProps = [];
887
888                 mandatoryProps.forEach(function(el){
889                     if(newObj[el] === '' || newObj[el] === null || newObj[el] === undefined){
890                         notFilledProps.push(el);
891                         ret = false;
892                     }
893                 });
894
895                 return {'status' : ret, 'notFilledProps' : notFilledProps};
896             };
897
898             $scope.validate = function(value, errors){
899                 errors.int32 = !(parseInt(value) >= -2147483648 && parseInt(value) <= 2147483647);
900             };
901
902
903
904             $scope.validateForm = function(form) {
905                 return form.$valid;
906             };
907
908             $scope.$on('GBP_TENANT_RELOAD', function(e, obj){
909                 $scope.selectedTenant = obj;
910             });
911
912     }]);
913
914     gbpOld.register.controller('linkDataCtrl',['$scope', function($scope){
915         $scope.showTable = false;
916
917         $scope.show = function(){
918             $scope.showTable = true;
919         };
920
921         $scope.close = function(){
922             $scope.showTable = false;
923         };
924
925         $scope.$on('SET_LINK_DATA', function(e, obj){
926            $scope.linkData = obj;
927            $scope.show();
928            $scope.$apply();
929         });
930     }]);
931
932     gbpOld.register.controller('crudCtrl',['$scope',  function($scope){
933         $scope.selectedObj = null;
934         $scope.label = '';
935         $scope.q = {};
936
937         $scope.add = function() {
938             $scope.selectedObj = null;
939             $scope.showForm();
940         };
941
942         $scope.modify = function() {
943             $scope.$emit('PGN_EDIT_ELEM');
944         };
945
946         $scope.init = function(label) {
947             $scope.label = label;
948         };
949
950
951         $scope.$on('EV_SET_SEL_CLASS', function(event, selObj){
952             $scope.selectedObj = selObj;
953         });
954     }]);
955
956     gbpOld.register.controller('contractCtrl', ['$scope','GBPContractServices', '$filter', function($scope, GBPContractServices, $filter){
957         $scope.list = [];
958         $scope.selectedContract = null;
959         $scope.newContractObj = GBPContractServices.createObj();
960         $scope.displayLabel = ['description','id'];
961         $scope.crudLabel = 'Contract list';
962
963         $scope.internalView = {
964             contract: false,
965             edit: "view"
966         };
967
968         var path = null,
969             mandatoryProperties = [],
970             clear = function(){
971                 $scope.list = [];
972                 $scope.internalView = {
973                     contract: false,
974                     edit: "view"
975                 };
976                 $scope.selectedContract = null;
977                 $scope.newContractObj = GBPContractServices.createObj();
978             };
979
980         $scope.init = function() {
981             if ( $scope.selectedTenant ) {
982                 $scope.selectedContract = null;
983                 path = GBPContractServices.createPathObj($scope.selectedTenant.id);
984
985                 GBPContractServices.load(path, function(data){
986                     $scope.list = data;
987                     // $scope.$broadcast('GBP_CONTRACT_RELOAD');
988                     $scope.sendReloadEventFromRoot('GBP_CONTRACT_RELOAD');
989                 }, function(){
990
991                 });
992             }else{
993                 clear();
994             }
995         };
996
997         $scope.save = function(){
998             var resp = $scope.validateMandatory($scope.newContractObj, mandatoryProperties);
999             if(resp.status){
1000                 path = GBPContractServices.createPathObj($scope.selectedTenant.id, $scope.newContractObj.id);
1001                 GBPContractServices.send(path, $scope.newContractObj, function(data){
1002                     $scope.init();
1003                     $scope.internalView.contract = false;
1004                     $scope.reloadNewObj();
1005                     $scope.internalView.edit = "view";
1006                 }, function(){
1007                     //TODO: error cbk
1008                 });
1009             }else{
1010                 alert($filter('translate')('GBP_MANDATORY_NOT_FILLED')+': '+resp.notFilledProps.join(', '));
1011             }
1012         };
1013
1014         $scope.delete = function() {
1015             if ( $scope.selectedContract ) {
1016                 path = GBPContractServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id);
1017                 GBPContractServices.delete(path, function(data){
1018                     $scope.init();
1019                     $scope.selectedContract = null;
1020                 }, function(){
1021                     //TODO: error cbk
1022                 });
1023             }
1024         };
1025
1026         $scope.reloadNewObj = function() {
1027             $scope.newContractObj = GBPContractServices.createObj();
1028         };
1029
1030         $scope.reload = function(selectedObj) {
1031             $scope.selectedContract = selectedObj;
1032             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1033             if(selectedObj){
1034                 $scope.internalView.contract = true;
1035             }else {
1036                 $scope.internalView.contract = false;
1037                 $scope.internalView.edit = "view";
1038             }
1039
1040             if($scope.internalView.contract) {
1041                 angular.copy(selectedObj, $scope.newContractObj);
1042             }
1043             $scope.sendReloadEventFromRoot('GBP_CONTRACT_RELOAD');
1044         };
1045
1046         $scope.showForm = function() {
1047             $scope.reloadNewObj();
1048             $scope.internalView.contract = true;
1049             $scope.selectedContract = null;
1050             $scope.internalView.edit = "add";
1051         };
1052
1053         $scope.close = function(){
1054             $scope.internalView.contract = false;
1055             $scope.internalView.edit = "view";
1056         };
1057
1058         $scope.$on('PGN_EDIT_ELEM', function(event){
1059             if(!event.defaultPrevented) {
1060                 if ( $scope.selectedContract ) {
1061                     $scope.internalView.contract = true;
1062                     $scope.internalView.edit = "edit";
1063                     angular.copy($scope.selectedContract, $scope.newContractObj);
1064                 }
1065                 event.defaultPrevented = true;
1066             }
1067         });
1068
1069         $scope.$on('GBP_TENANT_RELOAD',function(event){
1070             $scope.init();
1071         });
1072
1073         $scope.$on('GBP_CONTRACTS_LABEL', function(event, obj){
1074             obj.labels = $scope.displayLabel;
1075         });
1076     }]);
1077
1078     gbpOld.register.controller('clauseCtrl', ['$scope','GBPClauseServices', 'GBPSubjectServices',
1079         function($scope, GBPClauseServices, GBPSubjectServices){
1080         $scope.list = [];
1081         $scope.selectedClause = null;
1082         $scope.newClauseObj = GBPClauseServices.createObj();
1083         $scope.internalView = {
1084             clause: false,
1085             edit: "view"
1086         };
1087         $scope.displayLabel = 'name';
1088         $scope.crudLabel = 'Clause list';
1089
1090         $scope.subjects = {'options' : [], 'labels' : null};
1091         $scope.getDisplayLabelsFromCtrl('GBP_SUBJECTS_LABEL', $scope.subjects);
1092
1093         var path = null,
1094
1095             clear = function(){
1096                 $scope.list = [];
1097                 $scope.selectedClause = null;
1098                 $scope.newClauseObj = GBPClauseServices.createObj();
1099                 $scope.internalView = {
1100                     clause: false,
1101                     edit: "view"
1102                 };
1103             };
1104
1105         //move to separate ctrl \/
1106         $scope.addNewElem = function(templateObj) {
1107             if($scope.newClauseObj && $scope.newClauseObj['subject-refs']) {
1108                 var objToPush = templateObj || "";
1109                 $scope.newClauseObj['subject-refs'].push(objToPush);
1110             }
1111         };
1112
1113         $scope.deleteElemAt = function(index) {
1114             if($scope.newClauseObj && $scope.newClauseObj['subject-refs']) {
1115                 $scope.newClauseObj['subject-refs'].splice(index, 1);
1116             }
1117         };
1118
1119         $scope.updateAt = function(index, value) {
1120             if($scope.newClauseObj && $scope.newClauseObj['subject-refs'] && $scope.newClauseObj['subject-refs'].length >= index) {
1121                 $scope.newClauseObj['subject-refs'][index] = value;
1122             }
1123         };
1124         //move to separate ctrl /\
1125
1126         var loadSubjects = function() {
1127             $scope.getDisplayLabelsFromCtrl('GBP_SUBJECTS_LABEL', $scope.subjects);
1128
1129             GBPSubjectServices.load(path, function(data){
1130                 $scope.subjects.options = data;
1131             }, function(){
1132                 //TODO: error cbk
1133             });
1134         };
1135
1136         $scope.init = function() {
1137             if ( $scope.selectedContract ) {
1138                 path = GBPClauseServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id);
1139
1140                 GBPClauseServices.load(path, function(data){
1141                     $scope.list = data;
1142                 }, function(){
1143                     //TODO: error cbk
1144                 });
1145             }else{
1146                 clear();
1147             }
1148         };
1149
1150         $scope.save = function(){
1151             if($scope.validateForm($scope.clauseForm)){
1152                 path = GBPClauseServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.newClauseObj.name);
1153                 GBPClauseServices.send(path, $scope.newClauseObj, function(data){
1154                     $scope.init();
1155                     $scope.internalView.clause = false;
1156                     $scope.reloadNewObj();
1157                     $scope.internalView.clause = "view";
1158                 }, function(){
1159                     //TODO: error cbk
1160                 });
1161             }
1162         };
1163
1164         $scope.delete = function() {
1165             if ( $scope.selectedClause ) {
1166                 path = GBPClauseServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedClause.name);
1167                 GBPClauseServices.delete(path, function(data){
1168                     $scope.init();
1169                     $scope.selectedClause = null;
1170                 }, function(){
1171                     //TODO: error cbk
1172                 });
1173             }
1174         };
1175
1176         $scope.reloadNewObj = function() {
1177             $scope.newClauseObj = GBPClauseServices.createObj();
1178         };
1179
1180         $scope.reload = function(selectedObj) {
1181             $scope.selectedClause = selectedObj;
1182             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1183             if(selectedObj){
1184                 $scope.internalView.clause = true;
1185             }else {
1186                 $scope.internalView.clause = false;
1187                 $scope.internalView.edit = "view";
1188             }
1189
1190             if($scope.internalView.clause) {
1191                 angular.copy(selectedObj, $scope.newClauseObj);
1192             }
1193         };
1194
1195         $scope.showForm = function() {
1196             $scope.reloadNewObj();
1197             $scope.internalView.clause = true;
1198             $scope.internalView.edit = "add";
1199             $scope.selectedClause = null;
1200         };
1201
1202         $scope.close = function(){
1203             $scope.internalView.clause = false;
1204             $scope.internalView.edit = "view";
1205         };
1206
1207         $scope.$on('PGN_EDIT_ELEM', function(event){
1208             if (!event.defaultPrevented) {
1209                 if ( $scope.selectedClause ) {
1210                     $scope.internalView.clause = true;
1211                     $scope.internalView.edit = "edit";
1212                     angular.copy($scope.selectedClause, $scope.newClauseObj);
1213                 }
1214                 event.defaultPrevented = true;
1215             }
1216         });
1217
1218         $scope.$on('GBP_CONTRACT_RELOAD',function(){
1219             $scope.internalView.clause = false;
1220             $scope.init();
1221         });
1222
1223         $scope.$on('GBP_SUBJECT_RELOAD',function(){
1224             loadSubjects();
1225         });
1226     }]);
1227
1228     gbpOld.register.controller('subjectCtrl', ['$scope','GBPSubjectServices', '$filter', function($scope, GBPSubjectServices, $filter){
1229         $scope.list = [];
1230         $scope.selectedSubject = null;
1231         $scope.newSubjectObj = GBPSubjectServices.createObj();
1232         $scope.displayLabel = 'name';
1233         $scope.internalView = {
1234             subject : false,
1235             edit : "view"
1236         };
1237         $scope.crudLabel = 'Subject list';
1238         $scope.errors = {};
1239
1240         var path = null,
1241             mandatoryProperties = ['order'],
1242
1243             clear = function(){
1244                 $scope.list = [];
1245                 $scope.selectedSubject = null;
1246                 $scope.newSubjectObj = GBPSubjectServices.createObj();
1247                 $scope.internalView = {
1248                     subject : false,
1249                     edit : "view"
1250                 };
1251             };
1252
1253         $scope.init = function() {
1254             if ( $scope.selectedContract ) {
1255                 $scope.selectedSubject = null;
1256                 path = GBPSubjectServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id);
1257
1258                 GBPSubjectServices.load(path, function(data){
1259                     $scope.list = data;
1260                     $scope.sendReloadEventFromRoot('GBP_SUBJECT_RELOAD');
1261                 }, function(){
1262                     //TODO: error cbk
1263                 });
1264             }else{
1265                 clear();
1266             }
1267         };
1268
1269         $scope.save = function(){
1270             if($scope.validateForm($scope.subjectForm)){
1271                 path = GBPSubjectServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.newSubjectObj.name);
1272                 GBPSubjectServices.send(path, $scope.newSubjectObj, function(data){
1273                     $scope.init();
1274                     $scope.internalView.subject = false;
1275                     $scope.reloadNewObj();
1276                     $scope.internalView.edit = "view";
1277                 }, function(){
1278                     //TODO: error cbk
1279                 });
1280             }
1281         };
1282
1283         $scope.delete = function() {
1284             if ( $scope.selectedSubject ) {
1285                 path = GBPSubjectServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name);
1286                 GBPSubjectServices.delete(path, function(data){
1287                     $scope.init();
1288                     $scope.selectedSubject = null;
1289                 }, function(){
1290                     //TODO: error cbk
1291                 });
1292             }
1293         };
1294
1295         $scope.reloadNewObj = function() {
1296             $scope.newSubjectObj = GBPSubjectServices.createObj();
1297         };
1298
1299         $scope.reload = function(selectedObj) {
1300             $scope.selectedSubject = selectedObj;
1301             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1302             if(selectedObj){
1303                 $scope.internalView.subject = true;
1304             }else {
1305                 $scope.internalView.subject = false;
1306                 $scope.internalView.edit = "view";
1307             }
1308
1309             if($scope.internalView.subject) {
1310                 angular.copy(selectedObj, $scope.newSubjectObj);
1311             }
1312             $scope.sendReloadEventFromRoot('GBP_SUBJECT_RELOAD');
1313         };
1314
1315         $scope.showForm = function() {
1316             $scope.reloadNewObj();
1317             $scope.internalView.subject = true;
1318             $scope.internalView.edit = "add";
1319             $scope.selectedSubject = null;
1320         };
1321
1322         $scope.close = function(){
1323             $scope.internalView.subject = false;
1324             $scope.internalView.edit = "view";
1325         };
1326
1327         $scope.$on('PGN_EDIT_ELEM', function(event){
1328             if (!event.defaultPrevented) {
1329                 if ( $scope.selectedSubject ) {
1330                     $scope.internalView.subject = true;
1331                     $scope.internalView.edit = "edit";
1332                     angular.copy($scope.selectedSubject, $scope.newSubjectObj);
1333                 }
1334                 event.defaultPrevented = true;
1335             }
1336         });
1337
1338         $scope.$on('GBP_CONTRACT_RELOAD',function(){
1339             $scope.internalView.subject = false;
1340             $scope.init();
1341         });
1342
1343         $scope.$on('GBP_SUBJECTS_LABEL', function(event, obj){
1344             obj.labels = $scope.displayLabel;
1345         });
1346     }]);
1347
1348     gbpOld.register.controller('ruleCtrl', ['$scope','GBPRuleServices', '$filter', function($scope, GBPRuleServices, $filter){
1349         $scope.list = [];
1350         $scope.selectedRule = null;
1351         $scope.newRuleObj = GBPRuleServices.createObj();
1352         $scope.displayLabel = 'name';
1353         $scope.internalView = {
1354             rule : false,
1355             edit : "view"
1356         };
1357         $scope.crudLabel = 'Rule list';
1358         $scope.errors = {};
1359
1360         var path = null,
1361             mandatoryProperties = ['order'],
1362
1363             clear = function(){
1364                 $scope.list = [];
1365                 $scope.selectedRule = null;
1366                 $scope.newRuleObj = GBPRuleServices.createObj();
1367                 $scope.internalView = {
1368                     rule : false,
1369                     edit : "view"
1370                 };
1371             };
1372
1373         $scope.init = function() {
1374             if ( $scope.selectedSubject ) {
1375                 $scope.selectedRule = null;
1376                 path = GBPRuleServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name);
1377
1378                 GBPRuleServices.load(path, function(data){
1379                     $scope.list = data;
1380                 }, function(){
1381                     //TODO: error cbk
1382                 });
1383             }else{
1384                 clear();
1385             }
1386         };
1387
1388         $scope.save = function(){
1389             if($scope.validateForm($scope.rulesForm)){
1390                 path = GBPRuleServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.newRuleObj.name);
1391                 GBPRuleServices.send(path, $scope.newRuleObj, function(data){
1392                     $scope.init();
1393                     $scope.internalView.rule = false;
1394                     $scope.reloadNewObj();
1395                     $scope.internalView.edit = "view";
1396                 }, function(){
1397                     //TODO: error cbk
1398                 });
1399             }
1400         };
1401
1402         $scope.delete = function() {
1403             if ( $scope.selectedRule ) {
1404                 path = GBPRuleServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name);
1405                 GBPRuleServices.delete(path, function(data){
1406                     $scope.init();
1407                     $scope.selectedRule = null;
1408                 }, function(){
1409                     //TODO: error cbk
1410                 });
1411             }
1412         };
1413
1414         $scope.reloadNewObj = function() {
1415             $scope.newRuleObj = GBPRuleServices.createObj();
1416         };
1417
1418         $scope.reload = function(selectedObj) {
1419             $scope.selectedRule = selectedObj;
1420             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1421             if(selectedObj){
1422                 $scope.internalView.rule = true;
1423             }else {
1424                 $scope.internalView.rule = false;
1425                 $scope.internalView.edit = "view";
1426             }
1427
1428             if($scope.internalView.rule) {
1429                 angular.copy(selectedObj, $scope.newRuleObj);
1430             }
1431             $scope.$broadcast('GBP_RULE_RELOAD');
1432         };
1433
1434         $scope.showForm = function() {
1435             $scope.reloadNewObj();
1436             $scope.internalView.rule = true;
1437             $scope.internalView.edit = "add";
1438             $scope.selectedRule = null;
1439         };
1440
1441         $scope.close = function(){
1442             $scope.internalView.rule = false;
1443             $scope.internalView.edit = "view";
1444         };
1445
1446         $scope.$on('PGN_EDIT_ELEM', function(event){
1447             if (!event.defaultPrevented) {
1448                 if ( $scope.selectedRule ) {
1449                 $scope.internalView.rule = true;
1450                 $scope.internalView.edit = "edit";
1451                     angular.copy($scope.selectedRule, $scope.newRuleObj);
1452                 }
1453                 event.defaultPrevented = true;
1454             }
1455         });
1456
1457         $scope.$on('GBP_SUBJECT_RELOAD',function(){
1458             $scope.init();
1459         });
1460     }]);
1461
1462     gbpOld.register.controller('actionRefCtrl', ['$scope','GBPActionRefsServices', 'GBPActionInstanceServices', '$filter', function($scope, GBPActionRefsServices, GBPActionInstanceServices, $filter){
1463         $scope.list = [];
1464         $scope.selectedActionRef = null;
1465         $scope.newActionRefObj = GBPActionRefsServices.createObj();
1466         $scope.displayLabel = 'name';
1467         $scope.internalView = {
1468             actionRef : false,
1469             edit : "view"
1470         };
1471         $scope.crudLabel = 'Action ref list';
1472         $scope.errors = {};
1473
1474         $scope.actionInstanceNames = {'options' : [], 'labels' : $scope.displayLabel};
1475
1476         var path = null,
1477             mandatoryProperties = ['order'],
1478
1479             actionInstanceNamesLoad = function() {
1480                 var actionInstancePath = GBPActionInstanceServices.createPathObj($scope.selectedTenant.id);
1481                 GBPActionInstanceServices.load(actionInstancePath, function(data){
1482                     $scope.actionInstanceNames.options = data;
1483                 },function(){
1484                     //TODO: error cbk
1485                 });
1486             },
1487
1488             clear = function(){
1489                 $scope.list = [];
1490                 $scope.selectedActionRef = null;
1491                 $scope.newActionRefObj = GBPActionRefsServices.createObj();
1492                 $scope.internalView = {
1493                     actionRef : false,
1494                     edit : "view"
1495                 };
1496             };
1497
1498         $scope.init = function() {
1499             if ( $scope.selectedRule ) {
1500                 $scope.selectedActionRef = null;
1501                 path = GBPActionRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name);
1502
1503                 GBPActionRefsServices.load(path, function(data){
1504                     $scope.list = data;
1505                 }, function(){
1506                     //TODO: error cbk
1507                 });
1508
1509                 actionInstanceNamesLoad();
1510             }else{
1511                 clear();
1512             }
1513         };
1514
1515         $scope.save = function(){
1516             if($scope.validateForm($scope.actionRefForm)){
1517                 path = GBPActionRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name, $scope.newActionRefObj.name);
1518                 GBPActionRefsServices.send(path, $scope.newActionRefObj, function(data){
1519                     $scope.init();
1520                     $scope.internalView.actionRef = false;
1521                     $scope.reloadNewObj();
1522                     $scope.internalView.edit = "view";
1523                 }, function(){
1524                     //TODO: error cbk
1525                 });
1526             }
1527         };
1528
1529         $scope.delete = function() {
1530             if ( $scope.selectedActionRef ) {
1531                 path = GBPActionRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name, $scope.selectedActionRef.name);
1532                 GBPActionRefsServices.delete(path, function(data){
1533                     $scope.init();
1534                     $scope.selectedActionRef = null;
1535                 }, function(){
1536                     //TODO: error cbk
1537                 });
1538             }
1539         };
1540
1541         $scope.reloadNewObj = function() {
1542             $scope.newActionRefObj = GBPActionRefsServices.createObj();
1543         };
1544
1545         $scope.reload = function(selectedObj) {
1546             $scope.selectedActionRef = selectedObj;
1547             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1548             if(selectedObj){
1549                 $scope.internalView.actionRef = true;
1550             }else {
1551                 $scope.internalView.actionRef = false;
1552                 $scope.internalView.edit = "view";
1553             }
1554
1555             if($scope.internalView.actionRef) {
1556                 angular.copy(selectedObj, $scope.newActionRefObj);
1557             }
1558         };
1559
1560         $scope.showForm = function() {
1561             $scope.reloadNewObj();
1562             $scope.internalView.actionRef = true;
1563             $scope.internalView.edit = "add";
1564             $scope.selectedActionRef = null;
1565         };
1566
1567         $scope.close = function(){
1568             $scope.internalView.actionRef = false;
1569             $scope.internalView.edit = "view";
1570         };
1571
1572         $scope.$on('PGN_EDIT_ELEM', function(event){
1573             if (!event.defaultPrevented) {
1574                 if ( $scope.selectedActionRef ) {
1575                     $scope.internalView.actionRef = true;
1576                     $scope.internalView.edit = "edit";
1577                     angular.copy($scope.selectedActionRef, $scope.newActionRefObj);
1578                 }
1579                 event.defaultPrevented = true;
1580             }
1581         });
1582
1583         $scope.$on('GBP_RULE_RELOAD',function(){
1584             $scope.internalView.actionRef = false;
1585             $scope.init();
1586         });
1587
1588         $scope.$on('GBP_ACTION_INSTANCE_RELOAD',function(){
1589             actionInstanceNamesLoad();
1590         });
1591     }]);
1592
1593     gbpOld.register.controller('classifierRefCtrl', ['$scope','GBPClassifierRefsServices', 'GBPClassifierInstanceServices', '$filter', function($scope, GBPClassifierRefsServices, GBPClassifierInstanceServices, $filter){
1594         $scope.list = [];
1595         $scope.selectedClassifierRef = null;
1596         $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
1597         $scope.displayLabel = 'name';
1598         $scope.internalView = {
1599             classifierRef : false,
1600             edit : "view"
1601         };
1602
1603         $scope.instanceNames = {'options' : [], 'labels' : $scope.displayLabel};
1604
1605         $scope.formDirections = ['in', 'out', 'bidirectional'];
1606         $scope.formConnectionTracking = ['normal', 'reflexive'];
1607
1608         $scope.crudLabel = 'Classifier ref list';
1609
1610         var path = null,
1611
1612             instanceNamesLoad = function() {
1613                 var classifierInstancePath = GBPClassifierInstanceServices.createPathObj($scope.selectedTenant.id);
1614                 GBPClassifierInstanceServices.load(classifierInstancePath, function(data){
1615                     $scope.instanceNames.options = data;
1616                 },function(){
1617                     //TODO: error cbk
1618                 });
1619             },
1620
1621             clear = function(){
1622                 $scope.list = [];
1623                 $scope.selectedClassifierRef = null;
1624                 $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
1625                 $scope.internalView = {
1626                     classifierRef : false,
1627                     edit : "view"
1628                 };
1629             };
1630
1631         $scope.init = function() {
1632             if ( $scope.selectedRule ) {
1633                 $scope.selectedClassifierRef = null;
1634                 path = GBPClassifierRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name);
1635
1636
1637
1638                 GBPClassifierRefsServices.load(path, function(data){
1639                     $scope.list = data;
1640                 }, function(){
1641                     //TODO: error cbk
1642                 });
1643
1644                 instanceNamesLoad();
1645             }else{
1646                 clear();
1647             }
1648         };
1649
1650         $scope.save = function(){
1651             if($scope.validateForm($scope.classifierRefForm)){
1652                 path = GBPClassifierRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name, $scope.newClassifierRefObj.name);
1653                 GBPClassifierRefsServices.send(path, $scope.newClassifierRefObj, function(data){
1654                     $scope.init();
1655                     $scope.internalView.classifierRef = false;
1656                     $scope.reloadNewObj();
1657                     $scope.internalView.edit = "view";
1658                 }, function(){
1659                     //TODO: error cbk
1660                 });
1661             }
1662         };
1663
1664         $scope.delete = function() {
1665             if ( $scope.selectedClassifierRef ) {
1666                 path = GBPClassifierRefsServices.createPathObj($scope.selectedTenant.id, $scope.selectedContract.id, $scope.selectedSubject.name, $scope.selectedRule.name, $scope.selectedClassifierRef.name);
1667                 GBPClassifierRefsServices.delete(path, function(data){
1668                     $scope.init();
1669                     $scope.selectedClassifierRef = null;
1670                 }, function(){
1671                     //TODO: error cbk
1672                 });
1673             }
1674         };
1675
1676         $scope.reloadNewObj = function() {
1677             $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
1678         };
1679
1680         $scope.reload = function(selectedObj) {
1681             $scope.selectedClassifierRef = selectedObj;
1682             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1683             if(selectedObj){
1684                 $scope.internalView.classifierRef = true;
1685             }else {
1686                 $scope.internalView.classifierRef = false;
1687                 $scope.internalView.edit = "view";
1688             }
1689
1690             if($scope.internalView.classifierRef) {
1691                 angular.copy(selectedObj, $scope.newClassifierRefObj);
1692             }
1693         };
1694
1695         $scope.showForm = function() {
1696             $scope.reloadNewObj();
1697             $scope.internalView.classifierRef = true;
1698             $scope.internalView.edit = "add";
1699             $scope.selectedClassifierRef = null;
1700         };
1701
1702         $scope.close = function(){
1703             $scope.internalView.classifierRef = false;
1704             $scope.internalView.edit = "view";
1705         };
1706
1707         $scope.$on('PGN_EDIT_ELEM', function(event){
1708             if (!event.defaultPrevented) {
1709                 if ( $scope.selectedClassifierRef ) {
1710                     $scope.internalView.classifierRef = true;
1711                     $scope.internalView.edit = "edit";
1712                     angular.copy($scope.selectedClassifierRef, $scope.newClassifierRefObj);
1713                 }
1714                 event.defaultPrevented = true;
1715             }
1716         });
1717
1718         $scope.$on('GBP_RULE_RELOAD',function(){
1719             $scope.internalView.classifierRef = false;
1720             $scope.init();
1721         });
1722
1723         $scope.$on('GBP_CLASSIFIER_INSTANCE_RELOAD',function(){
1724             instanceNamesLoad();
1725         });
1726     }]);
1727
1728     gbpOld.register.controller('tenantCtrl', ['$scope', 'GBPTenantServices', '$filter', function($scope, GBPTenantServices, $filter){
1729         $scope.list = [];
1730         $scope.selectedTenantObj = null;
1731         $scope.newTenantObj = GBPTenantServices.createObj();
1732         $scope.displayLabel = ['name' , 'id'];
1733         $scope.crudLabel = 'Tenants list';
1734
1735         $scope.view = {
1736             tenant: false,
1737             edit: "view"
1738         };
1739
1740         $scope.init = function() {
1741             GBPTenantServices.load(
1742                 function(data) {
1743                     $scope.list = data;
1744                     $scope.newTenantObj = GBPTenantServices.createObj();
1745                     $scope.selectedTenantObj = null;
1746                 },
1747                 function(){
1748                     //TODO error
1749                 });
1750         };
1751
1752         $scope.save = function(){
1753             if($scope.validateForm($scope.tenantForm)){
1754                 path = GBPTenantServices.createPathObj($scope.newTenantObj.id);
1755                 GBPTenantServices.send(path, $scope.newTenantObj, function(data){
1756                     $scope.init();
1757                     $scope.view.tenant = false;
1758                     $scope.view.edit = "view";
1759                     $scope.$emit('GBP_GLOBAL_TENANT_RELOAD');
1760                 }, function(){
1761                     //TODO: error cbk
1762                 });
1763             }
1764         };
1765
1766          $scope.delete = function() {
1767             if($scope.selectedTenantObj) {
1768                 path = GBPTenantServices.createPathObj($scope.selectedTenantObj.id);
1769
1770                 GBPTenantServices.delete(path, function(data){
1771                     $scope.init();
1772                     $scope.view.tenant = false;
1773                     $scope.$emit('GBP_GLOBAL_TENANT_RELOAD');
1774                 }, function(){
1775                     //TODO: error cbk
1776                 });
1777             }
1778         };
1779
1780         $scope.reload = function(selectedObj) {
1781             $scope.selectedTenantObj = selectedObj;
1782
1783             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
1784             if(selectedObj){
1785                 $scope.view.tenant = true;
1786             }
1787             else {
1788                 $scope.view.tenant = false;
1789                 $scope.view.edit = "view";
1790             }
1791
1792             if ($scope.view.tenant) {
1793                 angular.copy(selectedObj, $scope.newTenantObj);
1794             }
1795         };
1796
1797         $scope.showForm = function() {
1798             $scope.newTenantObj = GBPTenantServices.createObj();
1799             $scope.selectedTenantObj = null;
1800             $scope.view.tenant = true;
1801             $scope.view.edit = "add";
1802         };
1803
1804         $scope.close = function(){
1805             $scope.view.tenant = false;
1806             $scope.view.edit = "view";
1807         };
1808
1809        $scope.$on('PGN_EDIT_ELEM', function(event){
1810             if (!event.defaultPrevented) {
1811                 if ( $scope.selectedTenantObj ) {
1812                     $scope.view.tenant = true;
1813                     $scope.view.edit = "edit";
1814                     angular.copy($scope.selectedTenantObj, $scope.newTenantObj);
1815                 }
1816                 event.defaultPrevented = true;
1817             }
1818         });
1819
1820         $scope.$on('GBP_GLOBAL_TENANT_RELOAD',function(){
1821             $scope.init();
1822         });
1823     }]);
1824
1825     gbpOld.register.controller('epgCtrl',['$scope', 'GBPEpgServices', 'GBPContractServices', '$filter',
1826         function($scope, GBPEpgServices, GBPContractServices, $filter){
1827         $scope.selectedEpg = null;
1828         $scope.newEpgObj = GBPEpgServices.createObj();
1829         $scope.displayLabel = ['name', 'id'];
1830         $scope.crudLabel = 'Group list';
1831
1832         $scope.igpOpts = ['allow', 'require-contract'];
1833
1834         $scope.contracts = {'options' : [], 'labels' : null};
1835         $scope.getDisplayLabelsFromCtrl('GBP_CONTRACTS_LABEL', $scope.contracts);
1836
1837         $scope.list = [];
1838
1839         $scope.internalView = {
1840             epg: false,
1841             edit: "view"
1842         };
1843
1844         var loadContracts = function() {
1845                 GBPContractServices.load(path, function(data){
1846                     $scope.contracts.options = data;
1847                 }, function(){
1848                     //TODO: error cbk
1849                 });
1850             },
1851
1852             mandatoryProperties = ['name'],
1853
1854             clear = function(){
1855                 $scope.list = [];
1856                 $scope.selectedEpg = null;
1857                 $scope.newEpgObj = GBPEpgServices.createObj();
1858                  $scope.internalView = {
1859                     epg: false,
1860                     edit: "view"
1861                 };
1862             };
1863
1864         $scope.init = function() {
1865             if ($scope.selectedTenant) {
1866                 path = GBPEpgServices.createPathObj($scope.selectedTenant.id);
1867
1868                 GBPEpgServices.load(path, function(data){
1869                     $scope.list = data;
1870                     // $scope.$broadcast('GBP_EPG_RELOAD');
1871                     $scope.sendReloadEventFromRoot('GBP_EPG_RELOAD');
1872                 }, function(){
1873                     //TODO: error cbk
1874                 });
1875
1876                 loadContracts();
1877             }else{
1878                 clear();
1879             }
1880         };
1881
1882         $scope.save = function(){
1883             if($scope.validateForm($scope.epgForm)){
1884                 path = GBPEpgServices.createPathObj($scope.selectedTenant.id, $scope.newEpgObj.id);
1885                 GBPEpgServices.send(path, $scope.newEpgObj, function(data){
1886                     $scope.init();
1887                     $scope.internalView.epg = false;
1888                     $scope.reloadNewObj();
1889                     $scope.internalView.edit = "view";
1890                     $scope.reloadTopo();
1891                 }, function(){
1892                     //TODO: error cbk
1893                 });
1894             }
1895         };
1896
1897         $scope.delete = function() {
1898             if($scope.selectedTenant && $scope.selectedEpg) {
1899                 path = GBPEpgServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id);
1900                 GBPEpgServices.delete(path, function(data){
1901                     $scope.init();
1902                     $scope.internalView.epg = false;
1903                     $scope.reloadTopo();
1904                 }, function(){
1905                     //TODO: error cbk
1906                 });
1907             }
1908         };
1909
1910         $scope.showForm = function() {
1911             $scope.internalView.epg = true;
1912             $scope.reloadNewObj();
1913             $scope.selectedEpg = null;
1914             $scope.internalView.edit = "add";
1915         };
1916
1917         $scope.reloadNewObj = function() {
1918             $scope.newEpgObj = GBPEpgServices.createObj();
1919         };
1920
1921         $scope.reload = function(selectedObj) {
1922             $scope.selectedEpg = selectedObj;
1923             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
1924             if(selectedObj){
1925                 $scope.internalView.epg = true;
1926             }else {
1927                 $scope.internalView.epg = false;
1928                 $scope.internalView.edit = "view";
1929             }
1930
1931             if($scope.internalView.epg) {
1932                 angular.copy(selectedObj, $scope.newEpgObj);
1933             }
1934             $scope.sendReloadEventFromRoot('GBP_EPG_RELOAD');
1935         };
1936
1937         $scope.close = function(){
1938             $scope.internalView.epg = false;
1939             $scope.internalView.edit = "view";
1940         };
1941         $scope.$on('PGN_EDIT_ELEM', function(event){
1942             if (!event.defaultPrevented) {
1943                 if ( $scope.selectedEpg ) {
1944                     $scope.internalView.epg = true;
1945                     $scope.internalView.edit = "edit";
1946                     angular.copy($scope.selectedEpg, $scope.newEpgObj);
1947                 }
1948                 event.defaultPrevented = true;
1949             }
1950         });
1951
1952         $scope.$on('GBP_TENANT_RELOAD',function(){
1953             $scope.init();
1954         });
1955
1956         $scope.$on('GBP_CONTRACT_RELOAD',function(){
1957             loadContracts();
1958         });
1959
1960         $scope.$on('GBP_EPG_LABEL', function(event, obj){
1961             obj.labels = $scope.displayLabel;
1962         });
1963     }]);
1964
1965     gbpOld.register.controller('cnsCtrl',['$scope', 'GBPConNamedSelServices', function($scope, GBPConNamedSelServices){
1966         $scope.list = [];
1967         $scope.selectedCNS = null;
1968         $scope.newCNSObj = GBPConNamedSelServices.createObj();
1969         $scope.internalView = {
1970             cns: false,
1971             edit: "view"
1972         };
1973         $scope.displayLabel = 'name';
1974         $scope.crudLabel = 'Consumer named selectors list';
1975
1976         var clear = function(){
1977                 $scope.list = [];
1978                 $scope.selectedCNS = null;
1979                 $scope.newCNSObj = GBPConNamedSelServices.createObj();
1980                 $scope.internalView = {
1981                     cns: false,
1982                     edit: "view"
1983                 };
1984             };
1985
1986         //move to separate ctrl \/
1987         $scope.addNewElem = function(templateObj) {
1988             if($scope.newCNSObj && $scope.newCNSObj.contract) {
1989                 var objToPush = templateObj || "";
1990                 $scope.newCNSObj.contract.push(objToPush);
1991             }
1992         };
1993
1994         $scope.deleteElemAt = function(index) {
1995             if($scope.newCNSObj && $scope.newCNSObj.contract) {
1996                 $scope.newCNSObj.contract.splice(index, 1);
1997             }
1998         };
1999
2000         $scope.updateAt = function(index, value) {
2001             if($scope.newCNSObj && $scope.newCNSObj.contract && $scope.newCNSObj.contract.length >= index) {
2002                 $scope.newCNSObj.contract[index] = value;
2003             }
2004         };
2005         //move to separate ctrl /\
2006
2007         $scope.init = function() {
2008             if ($scope.selectedTenant && $scope.selectedEpg) {
2009                 path = GBPConNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id);
2010
2011                 GBPConNamedSelServices.load(path, function(data){
2012                     $scope.list = data;
2013                 }, function(){
2014                     //TODO: error cbk
2015                 });
2016             }else{
2017                 clear();
2018             }
2019         };
2020
2021         $scope.save = function(){
2022             if($scope.validateForm($scope.cnsForm)){
2023                 path = GBPConNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id, $scope.newCNSObj.name);
2024                 GBPConNamedSelServices.send(path, $scope.newCNSObj, function(data){
2025                     $scope.init();
2026                     $scope.internalView.cns = false;
2027                     $scope.internalView.cns = "view";
2028                     $scope.reloadNewObj();
2029                     $scope.reloadTopo();
2030                 }, function(){
2031                     //TODO: error cbk
2032                 });
2033             }
2034         };
2035
2036         $scope.delete = function() {
2037             if($scope.selectedTenant && $scope.selectedEpg && $scope.selectedCNS) {
2038                 path = GBPConNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id, $scope.selectedCNS.name);
2039                 GBPConNamedSelServices.delete(path, function(data){
2040                     $scope.init();
2041                     $scope.reloadTopo();
2042                 }, function(){
2043                     //TODO: error cbk
2044                 });
2045             }
2046         };
2047
2048         $scope.showForm = function() {
2049             $scope.reloadNewObj();
2050             $scope.selectedCNS = null;
2051             $scope.internalView.cns = true;
2052             $scope.internalView.edit = "add";
2053         };
2054
2055         $scope.reloadNewObj = function() {
2056             $scope.newCNSObj = GBPConNamedSelServices.createObj();
2057         };
2058
2059         $scope.reload = function(selectedObj) {
2060             $scope.selectedCNS = selectedObj;
2061             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
2062             if(selectedObj){
2063                 $scope.internalView.cns = true;
2064             }else {
2065                 $scope.internalView.cns = false;
2066                 $scope.internalView.edit = "view";
2067             }
2068
2069             if($scope.internalView.cns) {
2070                 angular.copy(selectedObj, $scope.newCNSObj);
2071             }
2072         };
2073
2074         $scope.close = function(){
2075             $scope.internalView.cns = false;
2076             $scope.internalView.edit = "view";
2077         };
2078
2079         $scope.$on('PGN_EDIT_ELEM', function(event){
2080             if (!event.defaultPrevented) {
2081                 if ( $scope.selectedEpg ) {
2082                     $scope.internalView.cns = true;
2083                     $scope.internalView.edit = "add";
2084                     angular.copy($scope.selectedCNS, $scope.newCNSObj);
2085                 }
2086                 event.defaultPrevented = true;
2087             }
2088         });
2089
2090         $scope.$on('GBP_EPG_RELOAD',function(){
2091             $scope.init();
2092         });
2093     }]);
2094
2095     gbpOld.register.controller('pnsCtrl',['$scope', 'GBPProNamedSelServices', function($scope, GBPProNamedSelServices){
2096         $scope.list = [];
2097         $scope.selectedPNS = null;
2098         $scope.newPNSObj = GBPProNamedSelServices.createObj();
2099         $scope.displayLabel = 'name';
2100         $scope.crudLabel = 'Provider named selectors list';
2101         $scope.internalView = {
2102             pns: false,
2103             edit: "view"
2104         };
2105
2106         var clear = function(){
2107                 $scope.list = [];
2108                 $scope.selectedPNS = null;
2109                 $scope.newPNSObj = GBPProNamedSelServices.createObj();
2110                 $scope.internalView = {
2111                     pns: false,
2112                     edit: "view"
2113                 };
2114             };
2115
2116         //move to separate ctrl \/
2117         $scope.addNewElem = function(templateObj) {
2118             if($scope.newPNSObj && $scope.newPNSObj.contract) {
2119                 var objToPush = templateObj || "";
2120                 $scope.newPNSObj.contract.push(objToPush);
2121             }
2122         };
2123
2124         $scope.deleteElemAt = function(index) {
2125             if($scope.newPNSObj && $scope.newPNSObj.contract) {
2126                 $scope.newPNSObj.contract.splice(index, 1);
2127             }
2128         };
2129
2130         $scope.updateAt = function(index, value) {
2131             if($scope.newPNSObj && $scope.newPNSObj.contract && $scope.newPNSObj.contract.length >= index) {
2132                 $scope.newPNSObj.contract[index] = value;
2133             }
2134         };
2135         //move to separate ctrl /\
2136
2137         $scope.init = function() {
2138             if ($scope.selectedTenant && $scope.selectedEpg) {
2139                 path = GBPProNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id);
2140
2141                 GBPProNamedSelServices.load(path, function(data){
2142                     $scope.list = data;
2143                 }, function(){
2144                     //TODO: error cbk
2145                 });
2146             }else{
2147                 clear();
2148             }
2149         };
2150
2151         $scope.save = function(){
2152             if($scope.validateForm($scope.pnsForm)){
2153                 path = GBPProNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id, $scope.newPNSObj.name);
2154                 GBPProNamedSelServices.send(path, $scope.newPNSObj, function(data){
2155                     $scope.init();
2156                     $scope.internalView.pns = false;
2157                     $scope.reloadNewObj();
2158                     $scope.internalView.cns = "view";
2159                     $scope.reloadTopo();
2160                 }, function(){
2161                     //TODO: error cbk
2162                 });
2163             }
2164         };
2165
2166         $scope.delete = function() {
2167             if($scope.selectedTenant && $scope.selectedEpg && $scope.selectedPNS) {
2168                 path = GBPProNamedSelServices.createPathObj($scope.selectedTenant.id, $scope.selectedEpg.id, $scope.selectedPNS.name);
2169                 GBPProNamedSelServices.delete(path, function(data){
2170                     $scope.init();
2171                     $scope.reloadTopo();
2172                 }, function(){
2173                     //TODO: error cbk
2174                 });
2175             }
2176         };
2177
2178         $scope.showForm = function() {
2179             $scope.reloadNewObj();
2180             $scope.internalView.pns = true;
2181             $scope.internalView.edit = "add";
2182             $scope.selectedPNS = null;
2183         };
2184
2185         $scope.reloadNewObj = function() {
2186             $scope.newPNSObj = GBPProNamedSelServices.createObj();
2187         };
2188
2189         $scope.reload = function(selectedObj) {
2190             $scope.selectedPNS = selectedObj;
2191             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
2192             if(selectedObj){
2193                 $scope.internalView.pns = true;
2194             }else {
2195                 $scope.internalView.pns = false;
2196                 $scope.internalView.edit = "view";
2197             }
2198
2199             if($scope.internalView.pns) {
2200                 angular.copy(selectedObj, $scope.newPNSObj);
2201             }
2202         };
2203
2204         $scope.close = function(){
2205             $scope.internalView.pns = false;
2206             $scope.internalView.edit = "view";
2207         };
2208         $scope.$on('PGN_EDIT_ELEM', function(event){
2209             if (!event.defaultPrevented) {
2210                 if ( $scope.selectedEpg ) {
2211                     $scope.internalView.pns = true;
2212                     $scope.internalView.edit = "edit";
2213                     angular.copy($scope.selectedPNS, $scope.newPNSObj);
2214                 }
2215                 event.defaultPrevented = true;
2216             }
2217         });
2218
2219         $scope.$on('GBP_EPG_RELOAD',function(){
2220             $scope.init();
2221         });
2222     }]);
2223
2224     gbpOld.register.controller('l2FloodCtrl', ['$scope', 'GBPL2FloodDomainServices', 'GBPL2BridgeDomainServices', '$filter', function($scope, GBPL2FloodDomainServices, GBPL2BridgeDomainServices, $filter){
2225         $scope.list = [];
2226         $scope.selectedL2Flood = null;
2227         $scope.newL2FloodObj = GBPL2FloodDomainServices.createObj();
2228         $scope.displayLabel = ['name', 'id'];
2229         $scope.crudLabel = 'L2 Flood Domain list';
2230
2231         $scope.l2bridge = {'options' : [], 'labels' : null};
2232         $scope.getDisplayLabelsFromCtrl('GBP_L2BRIDGE_LABEL', $scope.l2bridge);
2233
2234         $scope.view = {
2235             l2flood: false,
2236             edit: "view"
2237         };
2238
2239         var path = null,
2240
2241             loadL2BridgeList = function() {
2242                 GBPL2BridgeDomainServices.load(GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id), function(data){
2243                     $scope.l2bridge.options = data;
2244                 }, function(){
2245
2246                 });
2247             },
2248
2249             clear = function(){
2250                 $scope.list = [];
2251                 $scope.selectedL2Flood = null;
2252                 $scope.newL2FloodObj = GBPL2FloodDomainServices.createObj();
2253                 $scope.view = {
2254                     l2flood: false,
2255                     edit: "view"
2256                 };
2257             };
2258
2259         $scope.init = function() {
2260             if ( $scope.selectedTenant ) {
2261                 path = GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id);
2262
2263                 GBPL2FloodDomainServices.load(path, function(data){
2264                     $scope.list = data;
2265                     // clear objects
2266                     $scope.newL2FloodObj = GBPL2FloodDomainServices.createObj();
2267                     $scope.selectedL2Flood = null;
2268                 }, function(){
2269
2270                 });
2271
2272                 loadL2BridgeList();
2273             }else{
2274                 clear();
2275             }
2276         };
2277
2278         $scope.save = function(){
2279             if($scope.validateForm($scope.l2FloodForm)){
2280                 path = GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id, $scope.newL2FloodObj.id);
2281                 GBPL2FloodDomainServices.send(path, $scope.newL2FloodObj, function(data){
2282                     $scope.init();
2283                     $scope.view.l2flood = false;
2284                     $scope.view.edit = "view";
2285                     $scope.sendReloadEventFromRoot('GBP_L2FLOOD_RELOAD');
2286
2287                     $scope.reloadTopo();
2288                 }, function(){
2289                     //TODO: error cbk
2290                 });
2291             }
2292         };
2293
2294         $scope.delete = function() {
2295             if($scope.selectedTenant && $scope.selectedL2Flood) {
2296                 path = GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id, $scope.selectedL2Flood.id);
2297                 GBPL2FloodDomainServices.delete(path, function(data){
2298                     $scope.init();
2299                     $scope.view.l2flood = false;
2300                     $scope.view.edit = "view";
2301                     $scope.sendReloadEventFromRoot('GBP_L2FLOOD_RELOAD');
2302
2303                     $scope.reloadTopo();
2304                 }, function(){
2305                     //TODO: error cbk
2306                 });
2307             }
2308         };
2309
2310         $scope.reload = function(selectedObj) {
2311             $scope.selectedL2Flood = selectedObj;
2312
2313             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
2314             if(selectedObj){
2315                 $scope.view.l2flood = true;
2316             }
2317             else {
2318                 $scope.view.l2flood = false;
2319                 $scope.view.edit = "view";
2320             }
2321
2322             if ($scope.view.l2flood) {
2323                 angular.copy(selectedObj, $scope.newL2FloodObj);
2324             }
2325
2326             $scope.sendReloadEventFromRoot('GBP_L2FLOOD_RELOAD');
2327         };
2328
2329         $scope.showForm = function() {
2330             $scope.newL2FloodObj = GBPL2FloodDomainServices.createObj();
2331             $scope.selectedL2Flood = null;
2332             $scope.view.l2flood = true;
2333             $scope.view.edit = "add";
2334         };
2335
2336         $scope.close = function(){
2337             $scope.view.l2flood = false;
2338         };
2339
2340         $scope.$on('PGN_EDIT_ELEM', function(event){
2341             if (!event.defaultPrevented) {
2342                 if ( $scope.selectedL2Flood ) {
2343                     $scope.view.l2flood = true;
2344                     $scope.view.edit = "edit";
2345                     angular.copy($scope.selectedL2Flood, $scope.newL2FloodObj);
2346                 }
2347                 event.defaultPrevented = true;
2348             }
2349         });
2350
2351         $scope.$on('GBP_TENANT_RELOAD',function(){
2352             $scope.init();
2353         });
2354
2355         $scope.$on('GBP_L2BRIDGE_RELOAD',function(){
2356             loadL2BridgeList();
2357         });
2358
2359         $scope.$on('GBP_L2FLOOD_LABEL', function(event, obj){
2360             obj.labels = $scope.displayLabel;
2361         });
2362     }]);
2363
2364     gbpOld.register.controller('l2BridgeCtrl', ['$scope', 'GBPL2BridgeDomainServices', 'GBPL3ContextServices', '$filter', function($scope, GBPL2BridgeDomainServices, GBPL3ContextServices, $filter){
2365         $scope.list = [];
2366         $scope.selectedL2Bridge = null;
2367         $scope.newL2BridgeObj = GBPL2BridgeDomainServices.createObj();
2368         $scope.displayLabel = ['name', 'id'];
2369         $scope.crudLabel = 'L2 Bridge Domain list';
2370
2371         $scope.l3context = {'options' : [], 'labels' : null};
2372         $scope.getDisplayLabelsFromCtrl('GBP_L3CONTEXT_LABEL', $scope.l3context);
2373
2374         $scope.view = {
2375             l2bridge: false,
2376             edit: "view"
2377         };
2378
2379         var path = null,
2380
2381             loadL3ContextList = function() {
2382                 GBPL3ContextServices.load(GBPL3ContextServices.createPathObj($scope.selectedTenant.id), function(data){
2383                     $scope.l3context.options = data;
2384                     //$scope.$broadcast('GBP_L2BRIDGE_RELOAD');
2385                 }, function(){
2386
2387                 });
2388             },
2389
2390             clear = function(){
2391                 $scope.list = [];
2392                 $scope.selectedL2Bridge = null;
2393                 $scope.newL2BridgeObj = GBPL2BridgeDomainServices.createObj();
2394                 $scope.view = {
2395                     l2bridge: false,
2396                     edit: "view"
2397                 };
2398             };
2399
2400         $scope.init = function() {
2401             if ( $scope.selectedTenant ) {
2402                 path = GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id);
2403
2404                 GBPL2BridgeDomainServices.load(path, function(data){
2405                     $scope.list = data;
2406                     $scope.newL2BridgeObj = GBPL2BridgeDomainServices.createObj();
2407                     $scope.selectedL2Bridge = null;
2408                     // $scope.$broadcast('GBP_L2BRIDGE_RELOAD');
2409                 }, function(){
2410
2411                 });
2412
2413                 loadL3ContextList();
2414             }else{
2415                 clear();
2416             }
2417         };
2418
2419
2420
2421         $scope.save = function(){
2422             if($scope.validateForm($scope.l2BridgeForm)){
2423                 path = GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id, $scope.newL2BridgeObj.id);
2424                 GBPL2BridgeDomainServices.send(path, $scope.newL2BridgeObj, function(data){
2425                     $scope.init();
2426                     $scope.view.l2bridge = false;
2427                     $scope.view.edit = "view";
2428                     $scope.sendReloadEventFromRoot('GBP_L2BRIDGE_RELOAD');
2429
2430                     $scope.reloadTopo();
2431                 }, function(){
2432                     //TODO: error cbk
2433                 });
2434             }
2435         };
2436
2437         $scope.delete = function() {
2438             if($scope.selectedTenant && $scope.selectedL2Bridge) {
2439                 path = GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id, $scope.selectedL2Bridge.id);
2440                 GBPL2BridgeDomainServices.delete(path, function(data){
2441                     $scope.init();
2442                     $scope.view.l2bridge = false;
2443                     $scope.view.edit = "view";
2444                     $scope.sendReloadEventFromRoot('GBP_L2BRIDGE_RELOAD');
2445
2446                     $scope.reloadTopo();
2447                 }, function(){
2448                     //TODO: error cbk
2449                 });
2450             }
2451         };
2452
2453         $scope.reload = function(selectedObj) {
2454             $scope.selectedL2Bridge = selectedObj;
2455
2456             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
2457             if(selectedObj){
2458                 $scope.view.l2bridge = true;
2459             }
2460             else {
2461                 $scope.view.l2bridge = false;
2462                 $scope.view.edit = "view";
2463             }
2464
2465             if ($scope.view.l2bridge) {
2466                 angular.copy(selectedObj, $scope.newL2BridgeObj);
2467             }
2468
2469             $scope.sendReloadEventFromRoot('GBP_L2BRIDGE_RELOAD');
2470         };
2471
2472         $scope.showForm = function() {
2473             $scope.newL2BridgeObj = GBPL2BridgeDomainServices.createObj();
2474             $scope.selectedL2Bridge = null;
2475             $scope.view.l2bridge = true;
2476             $scope.view.edit = "add";
2477         };
2478
2479         $scope.close = function(){
2480             $scope.view.l2bridge = false;
2481         };
2482
2483         $scope.$on('PGN_EDIT_ELEM', function(event){
2484             if (!event.defaultPrevented) {
2485                 if ( $scope.selectedL2Bridge ) {
2486                     $scope.view.l2bridge = true;
2487                     $scope.view.edit = "edit";
2488                     angular.copy($scope.selectedL2Bridge, $scope.newL2BridgeObj);
2489                 }
2490                 event.defaultPrevented = true;
2491             }
2492         });
2493
2494         $scope.$on('GBP_TENANT_RELOAD',function(){
2495             $scope.init();
2496         });
2497
2498         $scope.$on('GBP_L3CONTEXT_RELOAD',function(){
2499             loadL3ContextList();
2500         });
2501
2502         $scope.$on('GBP_L2BRIDGE_LABEL', function(event, obj){
2503             obj.labels = $scope.displayLabel;
2504         });
2505     }]);
2506
2507     gbpOld.register.controller('l3ContextCtrl', ['$scope', 'GBPL3ContextServices', '$filter', function($scope, GBPL3ContextServices, $filter){ //GBPContractServices
2508         $scope.list = [];
2509         $scope.selectedL3Context = null;
2510         $scope.newL3ContextObj = GBPL3ContextServices.createObj();
2511         $scope.displayLabel = ['name', 'id'];
2512         $scope.crudLabel = 'L3 Context list';
2513
2514         $scope.view = {
2515             l3context: false,
2516             edit: "view"
2517         };
2518
2519         var path = null,
2520
2521             clear = function(){
2522                 $scope.list = [];
2523                 $scope.view = {
2524                     l3context: false,
2525                     edit: "view"
2526                 };
2527                 $scope.selectedL3Context = null;
2528                 $scope.newL3ContextObj = GBPL3ContextServices.createObj();
2529             };
2530
2531         $scope.init = function() {
2532             if ( $scope.selectedTenant ) {
2533                 path = GBPL3ContextServices.createPathObj($scope.selectedTenant.id);
2534
2535                 GBPL3ContextServices.load(path, function(data){
2536                     $scope.list = data;
2537                     $scope.newL3ContextObj = GBPL3ContextServices.createObj();
2538                     $scope.selectedL3Context = null;
2539                 }, function(){
2540
2541                 });
2542             }else{
2543                 clear();
2544             }
2545         };
2546
2547         $scope.save = function(){
2548              if($scope.validateForm($scope.l3ContextForm)){
2549                 path = GBPL3ContextServices.createPathObj($scope.selectedTenant.id, $scope.newL3ContextObj.id);
2550                 GBPL3ContextServices.send(path, $scope.newL3ContextObj, function(data){
2551                     $scope.init();
2552                     $scope.view.l3context = false;
2553                     $scope.view.edit = "view";
2554                     $scope.sendReloadEventFromRoot('GBP_L3CONTEXT_RELOAD');
2555
2556                     $scope.reloadTopo();
2557                 }, function(){
2558                     //TODO: error cbk
2559                 });
2560             }
2561         };
2562
2563         $scope.delete = function() {
2564             if($scope.selectedTenant && $scope.selectedL3Context) {
2565                 path = GBPL3ContextServices.createPathObj($scope.selectedTenant.id, $scope.selectedL3Context.id);
2566                 GBPL3ContextServices.delete(path, function(data){
2567                     $scope.init();
2568                     $scope.view.l3context = false;
2569                     $scope.view.edit = "view";
2570                     $scope.sendReloadEventFromRoot('GBP_L3CONTEXT_RELOAD');
2571
2572                     $scope.reloadTopo();
2573                 }, function(){
2574                     //TODO: error cbk
2575                 });
2576             }
2577         };
2578
2579         $scope.reload = function(selectedObj) {
2580             $scope.selectedL3Context = selectedObj;
2581
2582             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
2583             if(selectedObj){
2584                 $scope.view.l3context = true;
2585             }
2586             else {
2587                 $scope.view.l3context = false;
2588                 $scope.view.edit = "view";
2589             }
2590
2591             if($scope.view.l3context) {
2592                 angular.copy(selectedObj, $scope.newL3ContextObj);
2593             }
2594
2595             $scope.sendReloadEventFromRoot('GBP_L3CONTEXT_RELOAD');
2596         };
2597
2598         $scope.showForm = function() {
2599             $scope.newL3ContextObj = GBPL3ContextServices.createObj();
2600             $scope.selectedL3Context = null;
2601             $scope.view.l3context = true;
2602             $scope.view.edit = "add";
2603         };
2604
2605         $scope.close = function(){
2606             $scope.view.l3context = false;
2607         };
2608
2609         $scope.$on('PGN_EDIT_ELEM', function(event){
2610             if (!event.defaultPrevented) {
2611                 if ( $scope.selectedL3Context ) {
2612                     $scope.view.l3context = true;
2613                     $scope.view.edit = "edit";
2614                     angular.copy($scope.selectedL3Context, $scope.newL3ContextObj);
2615                 }
2616                 event.defaultPrevented = true;
2617             }
2618         });
2619
2620         $scope.$on('GBP_TENANT_RELOAD',function(){
2621             $scope.init();
2622         });
2623
2624         $scope.$on('GBP_L3CONTEXT_LABEL', function(event, obj){
2625             obj.labels = $scope.displayLabel;
2626         });
2627     }]);
2628
2629     gbpOld.register.controller('subnetCtrl', ['$scope', 'GBPSubnetServices', 'GBPL2FloodDomainServices', 'GBPL2BridgeDomainServices', 'GBPL3ContextServices', '$filter', function($scope, GBPSubnetServices, GBPL2FloodDomainServices, GBPL2BridgeDomainServices, GBPL3ContextServices, $filter){
2630         $scope.list = [];
2631         $scope.selectedSubnet = null;
2632         $scope.newSubnetObj = GBPSubnetServices.createObj();
2633         $scope.displayLabel = ['name', 'id'];
2634         $scope.crudLabel = 'Subnet list';
2635
2636         $scope.l2L3List = {'options' : [], 'labels' : null};
2637         $scope.getDisplayLabelsFromCtrl('GBP_L2FLOOD_LABEL', $scope.l2L3List);
2638
2639         $scope.view = {
2640             subnet: false,
2641             edit: "view"
2642         };
2643
2644
2645         var path = null,
2646
2647             loadL2L3List = function() {
2648                 $scope.l2L3List.options = [];
2649
2650                 GBPL3ContextServices.load(GBPL3ContextServices.createPathObj($scope.selectedTenant.id), function(l3ContextData){
2651                     $scope.l2L3List.options = $scope.l2L3List.options.concat(l3ContextData);
2652                 }, function(){
2653
2654                 });
2655
2656                 GBPL2FloodDomainServices.load(GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id), function(l2FloodData){
2657                     $scope.l2L3List.options = $scope.l2L3List.options.concat(l2FloodData);
2658                 }, function(){
2659
2660                 });
2661
2662                 GBPL2BridgeDomainServices.load(GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id), function(l2BridgeData){
2663                     $scope.l2L3List.options = $scope.l2L3List.options.concat(l2BridgeData);
2664                 }, function(){
2665
2666                 });
2667             },
2668
2669             clear = function(){
2670                 $scope.list = [];
2671                 $scope.view = {
2672                     subnet: false,
2673                     edit: "view"
2674                 };
2675                 $scope.selectedSubnet = null;
2676                 $scope.newSubnetObj = GBPSubnetServices.createObj();
2677             };
2678
2679         $scope.init = function() {
2680             if ( $scope.selectedTenant ) {
2681                 path = GBPSubnetServices.createPathObj($scope.selectedTenant.id);
2682
2683                 GBPSubnetServices.load(path, function(data){
2684                     $scope.list = data;
2685                     $scope.newSubnetObj = GBPSubnetServices.createObj();
2686                     $scope.selectedSubnet = null;
2687
2688                     $scope.view.subnet = false;
2689                     $scope.view.edit = "view";
2690                     //$scope.sendReloadEventFromRoot('GBP_L2BRIDGE_RELOAD');
2691                 }, function(){
2692
2693                 });
2694
2695                 loadL2L3List();
2696             }else{
2697                 clear();
2698             }
2699         };
2700
2701         $scope.save = function(){
2702            if($scope.validateForm($scope.subnetForm)){
2703                 path = GBPSubnetServices.createPathObj($scope.selectedTenant.id, $scope.newSubnetObj.id);
2704                 GBPSubnetServices.send(path, $scope.newSubnetObj, function(data){
2705                     $scope.init();
2706                     $scope.view.subnet = false;
2707                     $scope.view.edit = "view";
2708
2709                     $scope.reloadTopo();
2710                 }, function(){
2711                     //TODO: error cbk
2712                 });
2713             }
2714         };
2715
2716         $scope.delete = function() {
2717             if($scope.selectedTenant && $scope.selectedSubnet) {
2718                 path = GBPSubnetServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id);
2719                 GBPSubnetServices.delete(path, function(data){
2720                     $scope.init();
2721                     $scope.view.subnet = false;
2722                     $scope.view.edit = "view";
2723
2724                     $scope.reloadTopo();
2725                 }, function(){
2726                     //TODO: error cbk
2727                 });
2728             }
2729         };
2730
2731         $scope.reload = function(selectedObj) {
2732             $scope.selectedSubnet = selectedObj;
2733
2734             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
2735             if(selectedObj){
2736                 $scope.view.subnet = true;
2737             }
2738             else {
2739                 $scope.view.subnet = false;
2740                 $scope.view.edit = "view";
2741             }
2742
2743             if($scope.view.subnet) {
2744                 angular.copy(selectedObj, $scope.newSubnetObj);
2745             }
2746
2747             $scope.sendReloadEventFromRoot('GBP_SUBNET_RELOAD');
2748         };
2749
2750         $scope.showForm = function() {
2751             $scope.newSubnetObj = GBPSubnetServices.createObj();
2752             $scope.selectedSubnet = null;
2753             $scope.view.subnet = true;
2754             $scope.view.edit = "add";
2755         };
2756
2757         $scope.close = function(){
2758             $scope.view.subnet = false;
2759         };
2760
2761         $scope.$on('PGN_EDIT_ELEM', function(event){
2762             if (!event.defaultPrevented) {
2763                 if ( $scope.selectedSubnet ) {
2764                     $scope.view.subnet = true;
2765                     $scope.view.edit = "edit";
2766                     angular.copy($scope.selectedSubnet, $scope.newSubnetObj);
2767                 }
2768                 event.defaultPrevented = true;
2769             }
2770         });
2771
2772         $scope.$on('GBP_TENANT_RELOAD',function(){
2773             $scope.init();
2774         });
2775
2776         $scope.$on('GBP_GATEWAY_RELOAD',function(){
2777             $scope.init();
2778         });
2779
2780         $scope.$on('GBP_L3CONTEXT_RELOAD',function(){
2781             loadL2L3List();
2782         });
2783
2784         $scope.$on('GBP_L2BRIDGE_RELOAD',function(){
2785             loadL2L3List();
2786         });
2787
2788         $scope.$on('GBP_L2FLOOD_RELOAD',function(){
2789             loadL2L3List();
2790         });
2791
2792         $scope.$on('GBP_PREFIX_RELOAD',function(){
2793             $scope.init();
2794         });
2795     }]);
2796
2797     gbpOld.register.controller('gatewayCtrl', ['$scope', 'GBPGatewayServices', function($scope, GBPGatewayServices){
2798         $scope.list = [];
2799         $scope.gatewayView = false;
2800         $scope.selectedGateway = null;
2801         $scope.newGatewayObj = GBPGatewayServices.createObj();
2802         $scope.displayLabel = 'gateway';
2803         $scope.crudLabel = 'Gateway list';
2804         $scope.internalView = {
2805             gateway: false,
2806             edit: "view"
2807         };
2808
2809         var path = null,
2810
2811             clear = function(){
2812                 $scope.list = [];
2813                 $scope.gatewayView = false;
2814                 $scope.selectedGateway = null;
2815                 $scope.newGatewayObj = GBPGatewayServices.createObj();
2816             };
2817
2818         $scope.init = function() {
2819             if ( $scope.selectedTenant && $scope.selectedSubnet ) {
2820                 path = GBPGatewayServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id);
2821
2822                 GBPGatewayServices.load(path, function(data){
2823                     $scope.list = data;
2824                     $scope.newGatewayObj = GBPGatewayServices.createObj();
2825                     $scope.internalView.gateway = false;
2826                     $scope.selectedGateway = null;
2827                 }, function(){
2828
2829                 });
2830             }else{
2831                 clear();
2832             }
2833         };
2834
2835         $scope.save = function(){
2836             if($scope.validateForm($scope.gatewayForm)){
2837                 path = GBPGatewayServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id, $scope.newGatewayObj.gateway);
2838                 GBPGatewayServices.send(path, $scope.newGatewayObj, function(data){
2839                     $scope.init();
2840                     $scope.internalView.gateway = false;
2841                     $scope.internalView.edit = "view";
2842                     $scope.sendReloadEventFromRoot('GBP_GATEWAY_RELOAD');
2843                 }, function(){
2844                     //TODO: error cbk
2845                 });
2846             }
2847         };
2848
2849         $scope.delete = function() {
2850             if($scope.selectedTenant && $scope.selectedSubnet && $scope.selectedGateway) {
2851                 path = GBPGatewayServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id, $scope.selectedGateway.gateway);
2852                 GBPGatewayServices.delete(path, function(data){
2853                     $scope.init();
2854                     $scope.internalView.gateway = false;
2855                     $scope.sendReloadEventFromRoot('GBP_GATEWAY_RELOAD');
2856                 }, function(){
2857                     //TODO: error cbk
2858                 });
2859             }
2860         };
2861
2862         $scope.reload = function(selectedObj) {
2863             $scope.selectedGateway = selectedObj;
2864             angular.copy(selectedObj, $scope.newGatewayObj);
2865             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
2866             if(selectedObj){
2867                 $scope.internalView.gateway = true;
2868             }else {
2869                 $scope.internalView.gateway = false;
2870                 $scope.internalView.edit = "view";
2871             }
2872
2873             $scope.sendReloadEventFromRoot('GBP_GATEWAY_SET');
2874         };
2875
2876         $scope.showForm = function() {
2877             $scope.newGatewayObj = GBPGatewayServices.createObj();
2878             $scope.internalView.gateway = true;
2879             $scope.internalView.edit = "add";
2880             $scope.selectedGateway = null;
2881         };
2882
2883         $scope.close = function(){
2884             $scope.internalView.gateway = false;
2885         };
2886
2887         $scope.$on('PGN_EDIT_ELEM', function(event){
2888             if (!event.defaultPrevented) {
2889                 if ( $scope.selectedGateway ) {
2890                     $scope.internalView.gateway = true;
2891                     $scope.internalView.edit = "edit";
2892                     angular.copy($scope.selectedGateway, $scope.newGatewayObj);
2893                 }
2894                 event.defaultPrevented = true;
2895             }
2896         });
2897
2898         $scope.$on('GBP_SUBNET_RELOAD',function(){
2899             $scope.init();
2900         });
2901
2902         $scope.$on('GBP_PREFIX_RELOAD',function(){
2903             $scope.init();
2904         });
2905     }]);
2906
2907     gbpOld.register.controller('prefixCtrl', ['$scope', 'GBPPrefixServices', function($scope, GBPPrefixServices){
2908         $scope.list = [];
2909         $scope.selectedPrefix = null;
2910         $scope.newPrefixObj = GBPPrefixServices.createObj();
2911         $scope.displayLabel = 'prefix';
2912         $scope.crudLabel = 'Prefix list';
2913         $scope.internalView = {
2914             prefix: false,
2915             edit: "view"
2916         };
2917
2918         var path = null,
2919
2920             clear = function(){
2921                 $scope.list = [];
2922                 $scope.selectedPrefix = null;
2923                 $scope.newPrefixObj = GBPPrefixServices.createObj();
2924                 $scope.internalView = {
2925                     prefix: false,
2926                     edit: "view"
2927                 };
2928             };
2929
2930         $scope.init = function() {
2931             if ( $scope.selectedTenant && $scope.selectedSubnet && $scope.selectedGateway) {
2932                 path = GBPPrefixServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id, $scope.selectedGateway.gateway);
2933
2934                 GBPPrefixServices.load(path, function(data){
2935                     $scope.list = data;
2936                     $scope.newPrefixObj = GBPPrefixServices.createObj();
2937                     $scope.internalView.prefix = false;
2938                     $scope.selectedPrefix = null;
2939                 }, function(){
2940
2941                 });
2942             }else{
2943                 clear();
2944             }
2945         };
2946
2947         $scope.save = function(){
2948             if($scope.validateForm($scope.prefixForm)){
2949                 path = GBPPrefixServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id, $scope.selectedGateway.gateway, $scope.newPrefixObj.prefix);
2950                 GBPPrefixServices.send(path, $scope.newPrefixObj, function(data){
2951                     $scope.init();
2952                     $scope.internalView.prefix = false;
2953                     $scope.internalView.edit = "view";
2954                     $scope.sendReloadEventFromRoot('GBP_PREFIX_RELOAD');
2955                 }, function(){
2956                     //TODO: error cbk
2957                 });
2958             }
2959         };
2960
2961         $scope.delete = function() {
2962             path = GBPPrefixServices.createPathObj($scope.selectedTenant.id, $scope.selectedSubnet.id, $scope.selectedGateway.gateway, $scope.selectedPrefix.prefix);
2963             GBPPrefixServices.delete(path, function(data){
2964                 $scope.init();
2965                 $scope.internalView.prefix = false;
2966                 $scope.sendReloadEventFromRoot('GBP_PREFIX_RELOAD');
2967             }, function(){
2968                 //TODO: error cbk
2969             });
2970         };
2971
2972         $scope.reload = function(selectedObj) {
2973             $scope.selectedPrefix = selectedObj;
2974             $scope.internalView.edit = $scope.internalView.edit == "edit" ? $scope.internalView.edit : "view";
2975             if(selectedObj){
2976                 $scope.internalView.prefix = true;
2977             }else {
2978                 $scope.internalView.prefix = false;
2979                 $scope.internalView.edit = "view";
2980             }
2981
2982             angular.copy(selectedObj, $scope.newPrefixObj);
2983         };
2984
2985         $scope.showForm = function() {
2986             $scope.newPrefixObj = GBPPrefixServices.createObj();
2987             $scope.internalView.prefix = true;
2988             $scope.internalView.edit = "add";
2989             $scope.selectedPrefix = null;
2990         };
2991
2992         $scope.close = function(){
2993             $scope.internalView.prefix = false;
2994         };
2995
2996         $scope.$on('PGN_EDIT_ELEM', function(event){
2997             if (!event.defaultPrevented) {
2998                 if ( $scope.selectedPrefix ) {
2999                     $scope.internalView.prefix = true;
3000                     $scope.internalView.edit = "edit";
3001                     angular.copy($scope.selectedPrefix, $scope.newPrefixObj);
3002                 }
3003                 event.defaultPrevented = true;
3004             }
3005         });
3006
3007         $scope.$on('GBP_GATEWAY_SET',function(){
3008             $scope.init();
3009         });
3010     }]);
3011
3012     gbpOld.register.controller('renderersCtrl', ['$scope', 'GPBServices', function($scope, GPBServices){ //GBPContractServices
3013         $scope.classifierDefinitions = {'options' : [], 'labels' : null};
3014         $scope.actionDefinitions = {'options' : [], 'labels' : null};
3015
3016         //reload on event?
3017
3018         var loadDefinitions = function() {
3019             GPBServices.getDefinitions(function(classifierDefs, actionDefs) {
3020                 $scope.classifierDefinitions.options = classifierDefs;
3021                 $scope.getDisplayLabelsFromCtrl('GBP_CLASSIFIERS_LABEL', $scope.classifierDefinitions);
3022
3023                 $scope.actionDefinitions.options = actionDefs;
3024                 $scope.getDisplayLabelsFromCtrl('GBP_ACTIONS_LABEL', $scope.actionDefinitions);
3025             });
3026         };
3027
3028         loadDefinitions();
3029     }]);
3030
3031     gbpOld.register.controller('paramCtrl', ['$scope', 'GPBServices', function($scope, GPBServices){
3032         $scope.value = null;
3033
3034         $scope.init = function(param, paramValues) {
3035             $scope.parameter = param;
3036
3037             if(paramValues) {
3038                 paramValues.forEach(function(p) {
3039                     if($scope.parameter.name === p.name) {
3040                         $scope.value = GPBServices.getInstanceParamValue(p);
3041                     }
3042                 });
3043             }
3044         };
3045
3046         $scope.$on('GBP_SAVE_PARAM', function(event){
3047             if($scope.value !== '' && $scope.value !== null) {
3048                 $scope.addParam($scope.parameter.name, $scope.parameter.type, $scope.value);
3049             }
3050         });
3051
3052         $scope.$on('GBP_SET_PARAM_VALUE', function(event, name, intVal, strVal) {
3053             //console.info($scope.parameter, ' got GBP_SET_PARAM_VALUE', name, intVal, strVal, event);
3054
3055         });
3056
3057         $scope.$on('GBP_RESET_PARAM', function(event){
3058             $scope.value = null;
3059         });
3060     }]);
3061
3062     gbpOld.register.controller('classifiersCtrl', ['$scope', 'GBPClassifierInstanceServices', 'GPBServices', '$filter',
3063         function($scope, GBPClassifierInstanceServices, GPBServices, $filter){
3064         $scope.list = [];
3065         $scope.classifiersView = false;
3066         $scope.displayLabel = 'name';
3067         $scope.selectedClassifier = null;
3068         $scope.crudLabel = 'Classifiers';
3069         $scope.newClassifierObj = GBPClassifierInstanceServices.createObj();
3070         $scope.edit = "view";
3071
3072         var mandatoryProperties = ['name'],
3073
3074             clear = function(){
3075                 $scope.list = [];
3076                 $scope.classifiersView = false;
3077                 $scope.selectedClassifier = null;
3078                 $scope.newClassifierObj = GBPClassifierInstanceServices.createObj();
3079                 $scope.edit = "view";
3080             };
3081
3082         $scope.getDefinitionObjParams = function(id){
3083             return GPBServices.getDefinitionObjParams($scope.classifierDefinitions.options, id);
3084         };
3085
3086         $scope.reloadDefs = function(){
3087             $scope.defs = angular.copy($scope.getDefinitionObjParams($scope.newClassifierObj['classifier-definition-id']));
3088         };
3089
3090         $scope.addParam = function(name, type, value) {
3091             $scope.newClassifierObj['parameter-value'].push(GPBServices.createParamObj(name, type, value));
3092         };
3093
3094         var saveParams = function() {
3095             $scope.newClassifierObj['parameter-value'] = [];
3096             $scope.$broadcast('GBP_SAVE_PARAM');
3097         };
3098
3099
3100         $scope.init = function() {
3101             if ( $scope.selectedTenant ) {
3102                 path = GBPClassifierInstanceServices.createPathObj($scope.selectedTenant.id);
3103                 GBPClassifierInstanceServices.load(path, function(data){
3104                     $scope.list = data;
3105                     $scope.reloadDefs();
3106                 }, function(){
3107                     //TODO: error cbk
3108                 });
3109             }else{
3110                 clear();
3111             }
3112         };
3113
3114         $scope.save = function(){
3115             if($scope.validateForm($scope.classifierForm)){
3116                 path = GBPClassifierInstanceServices.createPathObj($scope.selectedTenant.id, $scope.newClassifierObj.name);
3117                 saveParams();
3118                 GBPClassifierInstanceServices.send(path, $scope.newClassifierObj, function(data){
3119                     $scope.init();
3120                     $scope.classifiersView = false;
3121                     $scope.edit = "view";
3122                 $scope.sendReloadEventFromRoot('GBP_CLASSIFIER_INSTANCE_RELOAD');
3123                 }, function(){
3124                     //TODO: error cbk
3125                 });
3126             }
3127         };
3128
3129         $scope.showForm = function() {
3130             $scope.newClassifierObj = GBPClassifierInstanceServices.createObj();
3131             $scope.selectedClassifier = null;
3132             $scope.classifiersView = true;
3133             $scope.edit = "add";
3134             $scope.reloadDefs();
3135         };
3136
3137         $scope.reload = function(selectedObj){
3138             $scope.selectedClassifier = selectedObj;
3139             $scope.sendReloadEventFromRoot('GBP_CLASSIFIER_INSTANCE_RELOAD');
3140
3141             $scope.edit = $scope.edit == "edit" ? $scope.edit : "view";
3142             if(selectedObj){
3143                 $scope.classifiersView = true;
3144             }
3145             else {
3146                 $scope.classifiersView = false;
3147                 $scope.edit = "view";
3148             }
3149
3150             if($scope.classifiersView) {
3151                 angular.copy(selectedObj, $scope.newClassifierObj);
3152             }
3153
3154             $scope.reloadDefs();
3155         };
3156
3157         $scope.close = function(){
3158             $scope.classifiersView = false;
3159             $scope.edit = "view";
3160         };
3161
3162         $scope.$on('PGN_EDIT_ELEM', function(event){
3163             if (!event.defaultPrevented) {
3164                 if ( $scope.selectedClassifier ) {
3165                     $scope.classifiersView = true;
3166                     angular.copy($scope.selectedClassifier, $scope.newClassifierObj);
3167                     $scope.edit = "edit";
3168                     $scope.reloadDefs();
3169                 }
3170                 event.defaultPrevented = true;
3171             }
3172         });
3173
3174         $scope.delete = function(){
3175             path = GBPClassifierInstanceServices.createPathObj($scope.selectedTenant.id, $scope.selectedClassifier.name);
3176             GBPClassifierInstanceServices.delete(path, function(data){
3177                 $scope.init();
3178                 $scope.classifiersView = false;
3179                 $scope.sendReloadEventFromRoot('GBP_CLASSIFIER_INSTANCE_RELOAD');
3180             }, function(){
3181                 //TODO: error cbk
3182             });
3183         };
3184
3185         $scope.$on('GBP_TENANT_RELOAD',function(){
3186             $scope.init();
3187         });
3188
3189         $scope.$on('GBP_CLASSIFIERS_LABEL', function(event, obj){
3190             obj.labels = $scope.displayLabel;
3191         });
3192     }]);
3193
3194     gbpOld.register.controller('actionsCtrl', ['$scope', 'GBPActionInstanceServices', 'GPBServices', '$filter',
3195         function($scope, GBPActionInstanceServices, GPBServices, $filter){
3196         $scope.list = [];
3197         $scope.actionsView = false;
3198         $scope.displayLabel = 'name';
3199         $scope.selectedAction = null;
3200         $scope.crudLabel = 'Actions';
3201         $scope.newActionObj = GBPActionInstanceServices.createObj();
3202         $scope.edit = "view";
3203
3204         var mandatoryProperties = ['name'],
3205
3206             clear = function(){
3207                 $scope.list = [];
3208                 $scope.actionsView = false;
3209                 $scope.selectedAction = null;
3210                 $scope.newActionObj = GBPActionInstanceServices.createObj();
3211                 $scope.edit = "view";
3212             };
3213
3214         $scope.getDefinitionObjParams = function(id){
3215             return GPBServices.getDefinitionObjParams($scope.actionDefinitions.options, id);
3216         };
3217
3218         $scope.reloadDefs = function(){
3219             $scope.defs = angular.copy($scope.getDefinitionObjParams($scope.newActionObj['action-definition-id']));
3220         };
3221
3222         $scope.addParam = function(name, type, value) {
3223             $scope.newActionObj['parameter-value'].push(GPBServices.createParamObj(name, type, value));
3224         };
3225
3226         var saveParams = function() {
3227             $scope.newActionObj['parameter-value'] = [];
3228             $scope.$broadcast('GBP_SAVE_PARAM');
3229         };
3230
3231
3232         $scope.init = function() {
3233             if ( $scope.selectedTenant ) {
3234                 path = GBPActionInstanceServices.createPathObj($scope.selectedTenant.id);
3235                 GBPActionInstanceServices.load(path, function(data){
3236                     $scope.list = data;
3237                     $scope.reloadDefs();
3238                 }, function(){
3239                     //TODO: error cbk
3240                 });
3241             }else{
3242                 clear();
3243             }
3244         };
3245
3246         $scope.save = function(){
3247             if($scope.validateForm($scope.actionsForm)){
3248                 path = GBPActionInstanceServices.createPathObj($scope.selectedTenant.id, $scope.newActionObj.name);
3249                 saveParams();
3250
3251                 GBPActionInstanceServices.send(path, $scope.newActionObj, function(data){
3252                     $scope.init();
3253                     $scope.actionsView = false;
3254                     $scope.edit = "view";
3255                 $scope.sendReloadEventFromRoot('GBP_ACTION_INSTANCE_RELOAD');
3256                 }, function(){
3257                     //TODO: error cbk
3258                 });
3259             }
3260         };
3261
3262         $scope.showForm = function() {
3263             $scope.newActionObj = GBPActionInstanceServices.createObj();
3264             $scope.selectedAction = null;
3265             $scope.actionsView = true;
3266             $scope.edit = "add";
3267             $scope.reloadDefs();
3268         };
3269
3270         $scope.reload = function(selectedObj){
3271             $scope.selectedAction = selectedObj;
3272             $scope.sendReloadEventFromRoot('GBP_ACTION_INSTANCE_RELOAD');
3273
3274             $scope.edit = $scope.edit == "edit" ? $scope.edit : "view";
3275             if(selectedObj){
3276                 $scope.actionsView = true;
3277             }
3278             else {
3279                 $scope.actionsView = false;
3280                 $scope.edit = "view";
3281             }
3282
3283             if($scope.actionsView) {
3284                 angular.copy(selectedObj, $scope.newActionObj);
3285             }
3286
3287             $scope.reloadDefs();
3288         };
3289
3290         $scope.close = function(){
3291             $scope.actionsView = false;
3292             $scope.edit = "view";
3293         };
3294
3295         $scope.$on('PGN_EDIT_ELEM', function(event){
3296             if (!event.defaultPrevented) {
3297                 if ( $scope.selectedAction ) {
3298                     $scope.actionsView = true;
3299                     angular.copy($scope.selectedAction, $scope.newActionObj);
3300                     $scope.edit = "edit";
3301                     $scope.reloadDefs();
3302                 }
3303                 event.defaultPrevented = true;
3304             }
3305         });
3306
3307         $scope.delete = function(){
3308             path = GBPActionInstanceServices.createPathObj($scope.selectedTenant.id, $scope.selectedAction.name);
3309             GBPActionInstanceServices.delete(path, function(data){
3310                 $scope.init();
3311                 $scope.actionsView = false;
3312                 $scope.sendReloadEventFromRoot('GBP_ACTION_INSTANCE_RELOAD');
3313             }, function(){
3314                 //TODO: error cbk
3315             });
3316         };
3317
3318         $scope.$on('GBP_TENANT_RELOAD',function(){
3319             $scope.init();
3320         });
3321
3322         $scope.$on('GBP_ACTIONS_LABEL', function(event, obj){
3323             obj.labels = $scope.displayLabel;
3324         });
3325     }]);
3326
3327     gbpOld.register.controller('endpointCtrl', ['$scope', 'GBPEndpointServices', 'GPBServices', 'GBPL2FloodDomainServices', 'GBPL2BridgeDomainServices', 'GBPL3ContextServices', 'GBPEpgServices', '$filter', 'GBPSubnetServices',
3328         function($scope, GBPEndpointServices, GPBServices, GBPL2FloodDomainServices, GBPL2BridgeDomainServices, GBPL3ContextServices, GBPEpgServices, $filter, GBPSubnetServices){
3329         $scope.list = [];
3330         $scope.selectedEndpoint = null;
3331         $scope.newEndpointObj = GBPEndpointServices.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3332         $scope.displayLabel = function(obj) {
3333             return obj['mac-address'] + ':' + obj['l2-context'];
3334         };
3335         $scope.crudLabel = 'Endpoint list';
3336
3337         $scope.l2context = {'options' : [], 'labels' : null};
3338         $scope.getDisplayLabelsFromCtrl('GBP_L2FLOOD_LABEL', $scope.l2context);
3339
3340         $scope.l3context = {'options' : [], 'labels' : null};
3341         $scope.getDisplayLabelsFromCtrl('GBP_L3CONTEXT_LABEL', $scope.l3context);
3342
3343         $scope.subnet = {'options' : [], 'labels' : null};
3344         $scope.getDisplayLabelsFromCtrl('GBP_SUBNET_LABEL', $scope.subnet);
3345
3346         $scope.epg = {'options' : [], 'labels' : null};
3347         $scope.getDisplayLabelsFromCtrl('GBP_EPG_LABEL', $scope.epg);
3348
3349         $scope.networkContainment = {'options' : [], 'labels' : null};
3350         $scope.getDisplayLabelsFromCtrl('GBP_L2FLOOD_LABEL', $scope.networkContainment);
3351
3352         $scope.view = {
3353             endpoint: false,
3354             edit: "view"
3355         };
3356
3357         var path = null,
3358             mandatoryProperties = [],
3359
3360             loadEpgOptions = function() {
3361                 $scope.epg.options = [];
3362
3363                 path = GBPEpgServices.createPathObj($scope.selectedTenant.id);
3364                 GBPEpgServices.load(path, function(data){
3365                     $scope.epg.options = data;
3366                 }, function(){
3367                     //TODO: error cbk
3368                 });
3369             },
3370
3371             loadL2ContextOptions = function() {
3372                 removeL2ContextOptions($scope.networkContainment.options, $scope.l2context.options);
3373                 $scope.l2context.options = [];
3374
3375                 path = GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id);
3376
3377                 GBPL2FloodDomainServices.load(path, function(data){
3378                     $scope.l2context.options = $scope.l2context.options.concat(data);
3379                     $scope.networkContainment.options = $scope.networkContainment.options.concat(data);
3380                 }, function(){
3381
3382                 });
3383
3384                 path = GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id);
3385                 GBPL2BridgeDomainServices.load(path, function(data){
3386                     $scope.l2context.options = $scope.l2context.options.concat(data);
3387                     $scope.networkContainment.options = $scope.networkContainment.options.concat(data);
3388                 }, function(){
3389
3390                 });
3391             },
3392
3393             loadL3ContextOptions = function(){
3394                 removeL2ContextOptions($scope.networkContainment.options, $scope.l3context.options);
3395                 $scope.l3context.options = [];
3396
3397                 GBPL3ContextServices.load(GBPL3ContextServices.createPathObj($scope.selectedTenant.id), function(data){
3398                     $scope.l3context.options = data;
3399                     $scope.networkContainment.options = $scope.networkContainment.options.concat(data);
3400                 }, function(){
3401
3402                 });
3403             },
3404
3405             loadSubnetOptions = function(){
3406                 $scope.subnet.options = [];
3407
3408                 GBPSubnetServices.load(GBPSubnetServices.createPathObj($scope.selectedTenant.id), function(data){
3409                     $scope.subnet.options = data;
3410                     $scope.networkContainment.options = $scope.networkContainment.options.concat(data);
3411                 }, function(){
3412
3413                 });
3414             },
3415
3416             loadNetworkCotnaninemnt = function(){
3417                 $scope.networkContainment.options = [];
3418
3419                 loadL2ContextOptions();
3420                 loadL3ContextOptions();
3421                 loadSubnetOptions();
3422             },
3423
3424             clear = function(){
3425                 $scope.list = [];
3426                 $scope.selectedEndpoint = null;
3427                 $scope.newEndpointObj = GBPEndpointServices.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3428                 $scope.view = {
3429                     endpoint: false,
3430                     edit: "view"
3431                 };
3432             },
3433             removeL2ContextOptions = function(arr1, arr2) {
3434                 arr1 = arr1.filter( function( el ) {
3435                   return arr2.indexOf( el ) < 0;
3436                 });
3437             };
3438
3439         $scope.init = function() {
3440             if ($scope.selectedTenant) {
3441
3442                 GBPEndpointServices.load(path, function(data){
3443                     $scope.list = data;
3444                 }, function(){
3445                     //TODO: error cbk
3446                 });
3447
3448                 loadEpgOptions();
3449                 /*loadL2ContextOptions();
3450                 loadL3ContextOptions();
3451                 loadSubnetOptions();*/
3452                 loadNetworkCotnaninemnt();
3453             }else{
3454                 clear();
3455             }
3456         };
3457
3458         $scope.addNewL3address = function() {
3459             if($scope.newEndpointObj) {
3460                 if(!$scope.newEndpointObj['l3-address']){
3461                     $scope.newEndpointObj['l3-address'] = [];
3462                 }
3463                 var objToPush = {'l3-context' : '', 'ip-address' : ''};
3464                 $scope.newEndpointObj['l3-address'].push(objToPush);
3465             }
3466         };
3467
3468         $scope.deleteNewL3address = function(index){
3469             if($scope.newEndpointObj) {
3470                 $scope.newEndpointObj['l3-address'].splice(index, 1);
3471             }
3472         };
3473
3474         $scope.addNewLeafListEl = function(prop) {
3475             if($scope.newEndpointObj) {
3476                 if(!$scope.newEndpointObj[prop]){
3477                     $scope.newEndpointObj[prop] = [];
3478                 }
3479                 var objToPush = "";
3480                 $scope.newEndpointObj[prop].push(objToPush);
3481             }
3482         };
3483
3484         $scope.updateLeafListEl = function(index, value, prop) {
3485             if($scope.newEndpointObj && $scope.newEndpointObj[prop] && $scope.newEndpointObj[prop].length >= index) {
3486                 $scope.newEndpointObj[prop][index] = value;
3487             }
3488         };
3489
3490         $scope.deleteNewLeafListEl = function(index, prop){
3491             if($scope.newEndpointObj) {
3492                 $scope.newEndpointObj[prop].splice(index, 1);
3493             }
3494         };
3495
3496         $scope.save = function(){
3497             if($scope.validateForm($scope.endpointForm)){
3498                 GBPEndpointServices.send(path, $scope.newEndpointObj, function(data){
3499                     $scope.init();
3500                     $scope.view.endpoint = false;
3501                     $scope.reloadNewObj();
3502                     $scope.view.edit = "view";
3503                 }, function(){
3504                     //TODO: error cbk
3505                 });
3506             }
3507         };
3508
3509         $scope.delete = function() {
3510             if($scope.selectedTenant && $scope.selectedEndpoint) {
3511                 GBPEndpointServices.delete(path, $scope.selectedEndpoint, function(data){
3512                     $scope.init();
3513                     $scope.view.endpoint = false;
3514                 }, function(){
3515                     //TODO: error cbk
3516                 });
3517             }
3518         };
3519
3520         $scope.showForm = function() {
3521             $scope.view.endpoint = true;
3522             $scope.reloadNewObj();
3523             $scope.selectedEndpoint = null;
3524
3525             $scope.view.edit = "add";
3526         };
3527
3528         $scope.reloadNewObj = function() {
3529             $scope.newEndpointObj = GBPEndpointServices.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3530         };
3531
3532         $scope.reload = function(selectedObj) {
3533             $scope.selectedEndpoint = selectedObj;
3534             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
3535             if(selectedObj){
3536                 $scope.view.endpoint = true;
3537             }
3538             else {
3539                 $scope.view.endpoint = false;
3540                 $scope.view.edit = "view";
3541             }
3542
3543             if($scope.view.endpoint) {
3544                 angular.copy(selectedObj, $scope.newEndpointObj);
3545             }
3546         };
3547
3548         $scope.close = function(){
3549             $scope.view.endpoint = false;
3550             $scope.view.edit = "view";
3551         };
3552
3553         $scope.$on('PGN_EDIT_ELEM', function(event){
3554             if (!event.defaultPrevented) {
3555                 if ( $scope.selectedEndpoint ) {
3556                     $scope.view.endpoint = true;
3557                     $scope.view.edit = "edit";
3558                     angular.copy($scope.selectedEndpoint, $scope.newEndpointObj);
3559                 }
3560                 event.defaultPrevented = true;
3561             }
3562         });
3563
3564         $scope.$on('GBP_TENANT_RELOAD',function(){
3565             $scope.init();
3566         });
3567
3568         $scope.$on('GBP_EPG_RELOAD',function(){
3569             loadEpgOptions();
3570         });
3571
3572         $scope.$on('GBP_L2BRIDGE_RELOAD',function(){
3573             //loadL2ContextOptions();
3574             loadNetworkCotnaninemnt();
3575         });
3576
3577         $scope.$on('GBP_L2FLOOD_RELOAD',function(){
3578             //loadL2ContextOptions();
3579             loadNetworkCotnaninemnt();
3580         });
3581
3582         $scope.$on('GBP_L3CONTEXT_RELOAD',function(){
3583             //loadL3ContextOptions();
3584             loadNetworkCotnaninemnt();
3585         });
3586
3587         $scope.$on('GBP_SUBNET_RELOAD',function(){
3588             //loadSubnetOptions();
3589             loadNetworkCotnaninemnt();
3590         });
3591     }]);
3592
3593     gbpOld.register.controller('l3EndpointCtrl', ['$scope', 'GBPEndpointL3Services', 'GPBServices', 'GBPEpgServices', 'GBPL3ContextServices', 'GBPL2FloodDomainServices', 'GBPL2BridgeDomainServices', '$filter',
3594         function($scope, GBPEndpointL3Services, GPBServices, GBPEpgServices, GBPL3ContextServices, GBPL2FloodDomainServices, GBPL2BridgeDomainServices, $filter){
3595         $scope.list = [];
3596         $scope.selectedEndpoint = null;
3597         $scope.newEndpointObj = GBPEndpointL3Services.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3598         $scope.displayLabel = function(obj) {
3599             return obj['ip-prefix'] + ':' + obj['l3-context'];
3600         };
3601         $scope.crudLabel = 'L3 Prefix endpoint list';
3602
3603         $scope.l2context = {'options' : [], 'labels' : null};
3604         $scope.getDisplayLabelsFromCtrl('GBP_L2FLOOD_LABEL', $scope.l2context);
3605
3606         $scope.l3context = {'options' : [], 'labels' : null};
3607         $scope.getDisplayLabelsFromCtrl('GBP_L3CONTEXT_LABEL', $scope.l3context);
3608
3609         $scope.epg = {'options' : [], 'labels' : null};
3610         $scope.getDisplayLabelsFromCtrl('GBP_EPG_LABEL', $scope.epg);
3611
3612         $scope.view = {
3613             endpoint: false,
3614             edit: "view"
3615         };
3616
3617         var path = null,
3618             mandatoryProperties = [],
3619
3620             loadEpgOptions = function() {
3621                 $scope.epg.options = [];
3622
3623                 path = GBPEpgServices.createPathObj($scope.selectedTenant.id);
3624                 GBPEpgServices.load(path, function(data){
3625                     $scope.epg.options = data;
3626                 }, function(){
3627                     //TODO: error cbk
3628                 });
3629             },
3630
3631             loadL2ContextOptions = function() {
3632                 $scope.l2context.options = [];
3633
3634                 path = GBPL2FloodDomainServices.createPathObj($scope.selectedTenant.id);
3635
3636                 GBPL2FloodDomainServices.load(path, function(data){
3637                     $scope.l2context.options = $scope.l2context.options.concat(data);
3638                 }, function(){
3639
3640                 });
3641
3642                 path = GBPL2BridgeDomainServices.createPathObj($scope.selectedTenant.id);
3643                 GBPL2BridgeDomainServices.load(path, function(data){
3644                     $scope.l2context.options = $scope.l2context.options.concat(data);
3645                 }, function(){
3646
3647                 });
3648             },
3649
3650             loadL3ContextOptions = function(){
3651                 $scope.l3context.options = [];
3652
3653                 GBPL3ContextServices.load(GBPL3ContextServices.createPathObj($scope.selectedTenant.id), function(data){
3654                     $scope.l3context.options = data;
3655                 }, function(){
3656
3657                 });
3658             },
3659
3660             clear = function(){
3661                 $scope.list = [];
3662                 $scope.selectedEndpoint = null;
3663                 $scope.newEndpointObj = GBPEndpointL3Services.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3664                 $scope.view = {
3665                     endpoint: false,
3666                     edit: "view"
3667                 };
3668             };
3669
3670         $scope.init = function() {
3671             if ($scope.selectedTenant) {
3672
3673                 GBPEndpointL3Services.load(path, function(data){
3674                     $scope.list = data;
3675                 }, function(){
3676                     //TODO: error cbk
3677                 });
3678
3679                 loadEpgOptions();
3680                 loadL2ContextOptions();
3681                 loadL3ContextOptions();
3682             }else{
3683                 clear();
3684             }
3685         };
3686
3687         $scope.addNewL2gateways = function() {
3688             if($scope.newEndpointObj) {
3689                 if(!$scope.newEndpointObj['endpoint-l2-gateways']){
3690                     $scope.newEndpointObj['endpoint-l2-gateways'] = [];
3691                 }
3692                 var objToPush = {'l2-context' : '', 'mac-address' : ''};
3693                 $scope.newEndpointObj['endpoint-l2-gateways'].push(objToPush);
3694             }
3695         };
3696
3697         $scope.deleteNewL2gateways = function(index){
3698             if($scope.newEndpointObj) {
3699                 $scope.newEndpointObj['endpoint-l2-gateways'].splice(index, 1);
3700             }
3701         };
3702
3703         $scope.addNewL3gateways = function() {
3704             if($scope.newEndpointObj) {
3705                 if(!$scope.newEndpointObj['endpoint-l3-gateways']){
3706                     $scope.newEndpointObj['endpoint-l3-gateways'] = [];
3707                 }
3708                 var objToPush = {'l3-context' : '', 'ip-address' : ''};
3709                 $scope.newEndpointObj['endpoint-l3-gateways'].push(objToPush);
3710             }
3711         };
3712
3713         $scope.deleteNewL3gateways = function(index){
3714             if($scope.newEndpointObj) {
3715                 $scope.newEndpointObj['endpoint-l3-gateways'].splice(index, 1);
3716             }
3717         };
3718
3719         $scope.addNewLeafListEl = function(prop) {
3720             if($scope.newEndpointObj) {
3721                 if(!$scope.newEndpointObj[prop]){
3722                     $scope.newEndpointObj[prop] = [];
3723                 }
3724                 var objToPush = "";
3725                 $scope.newEndpointObj[prop].push(objToPush);
3726             }
3727         };
3728
3729         $scope.updateLeafListEl = function(index, value, prop) {
3730             if($scope.newEndpointObj && $scope.newEndpointObj[prop] && $scope.newEndpointObj[prop].length >= index) {
3731                 $scope.newEndpointObj[prop][index] = value;
3732             }
3733         };
3734
3735         $scope.deleteNewLeafListEl = function(index, prop){
3736             if($scope.newEndpointObj) {
3737                 $scope.newEndpointObj[prop].splice(index, 1);
3738             }
3739         };
3740
3741         $scope.save = function(){
3742             if($scope.validateForm($scope.l3EndpointForm)){
3743                 GBPEndpointL3Services.send(path, $scope.newEndpointObj, function(data){
3744                     $scope.init();
3745                     $scope.view.endpoint = false;
3746                     $scope.reloadNewObj();
3747                     $scope.view.edit = "view";
3748                 }, function(){
3749                     //TODO: error cbk
3750                 });
3751             }
3752         };
3753
3754         $scope.delete = function() {
3755             if($scope.selectedTenant && $scope.selectedEndpoint) {
3756                 GBPEndpointL3Services.delete(path, $scope.selectedEndpoint, function(data){
3757                     $scope.init();
3758                 }, function(){
3759                     //TODO: error cbk
3760                 });
3761             }
3762         };
3763
3764         $scope.showForm = function() {
3765             $scope.view.endpoint = true;
3766             $scope.reloadNewObj();
3767             $scope.selectedEndpoint = null;
3768             $scope.view.edit = "add";
3769         };
3770
3771         $scope.reloadNewObj = function() {
3772             $scope.newEndpointObj = GBPEndpointL3Services.createObj($scope.selectedTenant ? $scope.selectedTenant.id : null);
3773         };
3774
3775         $scope.reload = function(selectedObj) {
3776             $scope.selectedEndpoint = selectedObj;
3777             angular.copy(selectedObj, $scope.newEndpointObj);
3778             $scope.view.edit = $scope.view.edit == "edit" ? $scope.view.edit : "view";
3779             if(selectedObj){
3780                 $scope.view.endpoint = true;
3781             }
3782             else {
3783                 $scope.view.endpoint = false;
3784                 $scope.view.edit = "view";
3785             }
3786         };
3787
3788         $scope.close = function(){
3789             $scope.view.endpoint = false;
3790             $scope.view.edit = "view";
3791         };
3792
3793         $scope.$on('PGN_EDIT_ELEM', function(event){
3794             if (!event.defaultPrevented) {
3795                 if ( $scope.selectedEndpoint ) {
3796                     $scope.view.endpoint = true;
3797                     $scope.view.edit = "edit";
3798                     angular.copy($scope.selectedEndpoint, $scope.newEndpointObj);
3799                 }
3800                 event.defaultPrevented = true;
3801             }
3802         });
3803
3804         $scope.$on('GBP_TENANT_RELOAD',function(){
3805             $scope.init();
3806         });
3807
3808         $scope.$on('GBP_EPG_RELOAD',function(){
3809             loadEpgOptions();
3810         });
3811
3812         $scope.$on('GBP_L2BRIDGE_RELOAD',function(){
3813             loadL2ContextOptions();
3814         });
3815
3816         $scope.$on('GBP_L2FLOOD_RELOAD',function(){
3817             loadL2ContextOptions();
3818         });
3819
3820         $scope.$on('GBP_L3CONTEXT_RELOAD',function(){
3821             loadL3ContextOptions();
3822         });
3823     }]);
3824
3825     gbpOld.register.controller('accessModelWizardCtrl', ['$scope', '$filter', 'GBPTenantServices', 'GBPEpgServices', 'GBPContractServices', 'GPBServices', function($scope, $filter, GBPTenantServices, GBPEpgServices, GBPContractServices, GPBServices){
3826         $scope.wizardPage = null;
3827
3828         $scope.selectedTenant = null;
3829         $scope.tenant = null;
3830         //$scope.epgList = [];
3831         $scope.newContractObj = null;
3832
3833         $scope.init = function() {
3834             $scope.setPage('tenants');
3835         };
3836
3837         $scope.setPage = function(pageName, object) {
3838             $scope.wizardPage = pageName;
3839
3840             switch(pageName) {
3841                 case 'contracts':
3842                     if(object) {
3843                         $scope.tenant = object;
3844                     }
3845
3846                     break;
3847
3848                 case 'summary':
3849                     $scope.tenant['endpoint-group'] = $scope.tenant['endpoint-group'] ? $scope.tenant['endpoint-group'] : [];
3850
3851                     if(object) {
3852                         object.forEach(function(o) {
3853                             $scope.tenant['endpoint-group'].push(GPBServices.stripNullValues(o));
3854                         });
3855                     }
3856
3857                     break;
3858
3859                  case 'epgs':
3860                     $scope.tenant['contract'] = $scope.tenant['contract'] ? $scope.tenant['contract'] : [];
3861
3862                     if(object) {
3863                         object.forEach(function(o) {
3864                             $scope.tenant['contract'].push(GPBServices.stripNullValues(o));
3865                         });
3866                     }
3867
3868                     break;
3869             }
3870         };
3871
3872         $scope.submit = function(object) {
3873             $scope.tenant['endpoint-group'] = $scope.tenant['endpoint-group'] ? $scope.tenant['endpoint-group'] : [];
3874
3875             if(object) {
3876                 object.forEach(function(o) {
3877                     $scope.tenant['endpoint-group'].push(GPBServices.stripNullValues(o));
3878                 });
3879             }
3880
3881
3882             path = GBPTenantServices.createPathObj($scope.tenant.id);
3883             GBPTenantServices.send(path, $scope.tenant, function(data){
3884                 $scope.wizards.accessModelWizard = false;
3885                 $scope.sendReloadEventFromRoot('GBP_GLOBAL_TENANT_RELOAD');
3886                 $scope.reloadTopo();
3887             }, function(){
3888                 //TODO: error cbk
3889             });
3890         };
3891
3892         // $scope.updateList = function(list, object, key) {
3893         //     var elementPos = list.map(function(x) {return x[key]; }).indexOf(object[key]);
3894
3895         //     if(elementPos < 0) {
3896         //         list.push(object);
3897         //     }
3898         //     else {
3899         //         list[elementPos] = object;
3900         //     }
3901         // };
3902     }]);
3903
3904     gbpOld.register.controller('wizardTenantCtrl', ['$scope', '$filter', 'GBPTenantServices', function($scope, $filter, GBPTenantServices){
3905         // $scope.tenantList = [];
3906         $scope.newTenantObj = GBPTenantServices.createObj();
3907         $scope.displayLabel = ['name' , 'id'];
3908
3909         $scope.view = {
3910             tenantEdit: false
3911         };
3912
3913         // $scope.init = function() {
3914         //     $scope.getTenants();
3915         // };
3916
3917         // $scope.getTenants = function() {
3918         //     GBPTenantServices.load(
3919         //         function(data) {
3920         //             $scope.tenantList = data;
3921         //             $scope.newTenantObj = GBPTenantServices.createObj();
3922         //         },
3923         //         function(){
3924         //             //TODO error
3925         //         }
3926         //     );
3927         // };
3928
3929         $scope.reloadTenants = function(selectedObject) {
3930             if(!selectedObject) {
3931                 selectedObject = GBPTenantServices.createObj();
3932                  $scope.view.tenantEdit = false;
3933             }
3934             else {
3935                 $scope.view.tenantEdit = true;
3936             }
3937
3938             $scope.selectedTenant = selectedObject;
3939             $scope.newTenantObj = selectedObject;
3940         };
3941
3942         $scope.getNewTenantObject = function() {
3943             return GBPTenantServices.createObj();
3944         };
3945     }]);
3946
3947     gbpOld.register.controller('wizardEpgCtrl', ['$scope', '$filter', 'GBPEpgServices', function($scope, $filter, GBPEpgServices){
3948         $scope.list = [];
3949         $scope.newEpgObj = GBPEpgServices.createObj();
3950         $scope.selectedEpg = null;
3951         $scope.epgFormView = true;
3952
3953         $scope.displayLabel = ['name', 'id'];
3954         $scope.crudLabel = 'Group list';
3955
3956         $scope.igpOpts = ['allow', 'require-contract'];
3957
3958         $scope.init = function() {
3959
3960         };
3961
3962         $scope.showForm = function() {
3963             $scope.epgFormView = true;
3964             $scope.newEpgObj = GBPEpgServices.createObj();
3965         };
3966
3967         $scope.save = function() {
3968             $scope.updateList($scope.list, $scope.newEpgObj, "id");
3969             $scope.reload($scope.newEpgObj);
3970             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newEpgObj);
3971         };
3972
3973         $scope.delete = function() {
3974             if($scope.selectedEpg) {
3975                 var index = $scope.list.indexOf($scope.selectedEpg);
3976                 $scope.list.splice(index, 1);
3977                 $scope.epgFormView = false;
3978             }
3979             //$scope.newEpgObj = GBPEpgServices.createObj();
3980         };
3981
3982         $scope.reload = function(selectedObj) {
3983             $scope.selectedEpg = selectedObj;
3984             $scope.newEpgObj = selectedObj;
3985             $scope.epgFormView = true;
3986             $scope.$broadcast('WIZARD_EPG_RELOAD');
3987         };
3988
3989         $scope.close = function() {
3990             $scope.epgFormView = false;
3991             $scope.newEpgObj = GBPEpgServices.createObj();
3992             $scope.selectedEpg = null;
3993         };
3994
3995         $scope.$on('PGN_EDIT_ELEM', function(event){
3996             if (!event.defaultPrevented) {
3997                 if ( $scope.selectedEpg ) {
3998                     $scope.epgFormView = true;
3999                     angular.copy($scope.selectedEpg, $scope.newEpgObj);
4000                 }
4001                 event.defaultPrevented = true;
4002             }
4003         });
4004
4005         $scope.$on("WIZARD_CNS_RELOAD", function(event, args){
4006             //$scope.selectedEpg['consumer-named-selector'] = args;
4007             $scope.newEpgObj['consumer-named-selector'] = args;
4008             $scope.updateList($scope.list, $scope.newEpgObj, "id");
4009         });
4010
4011         $scope.$on("WIZARD_PNS_RELOAD", function(event, args){
4012             //$scope.selectedEpg['provider-named-selector'] = args;
4013             $scope.newEpgObj['provider-named-selector'] = args;
4014             $scope.updateList($scope.list, $scope.newEpgObj, "id");
4015         });
4016     }]);
4017
4018     gbpOld.register.controller('wizardContractCtrl', ['$scope', '$filter', 'GBPContractServices', function($scope, $filter, GBPContractServices){
4019         $scope.list = [];
4020         $scope.newContractObj = GBPContractServices.createObj();
4021         $scope.selectedContract = null;
4022
4023         $scope.displayLabel = ['description', 'id'];
4024         $scope.crudLabel = 'Contract list';
4025
4026         $scope.contractFormView = true;
4027
4028         $scope.init = function() {
4029
4030         };
4031
4032         $scope.showForm = function() {
4033             $scope.contractFormView = true;
4034             $scope.newContractObj = GBPContractServices.createObj();
4035         };
4036
4037         $scope.save = function() {
4038             $scope.updateList($scope.list, $scope.newContractObj, "id");
4039             $scope.reload($scope.newContractObj);
4040             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newContractObj);
4041         };
4042
4043         $scope.delete = function() {
4044             if($scope.selectedContract) {
4045                 var index = $scope.list.indexOf($scope.selectedContract);
4046                 $scope.list.splice(index, 1);
4047                 $scope.contractFormView = false;
4048                 $scope.newContractObj = GBPContractServices.createObj();
4049                 $scope.selectedContract = null;
4050             }
4051         };
4052
4053         $scope.reload = function(selectedObj) {
4054             $scope.selectedContract = selectedObj;
4055             $scope.newContractObj = selectedObj;
4056             $scope.contractFormView = true;
4057         };
4058
4059         $scope.close = function() {
4060             $scope.contractFormView = false;
4061             //$scope.newContractObj = GBPContractServices.createObj();
4062             //$scope.selectedContract = null;
4063         };
4064
4065         $scope.$on('PGN_EDIT_ELEM', function(event){
4066             if (!event.defaultPrevented) {
4067                 if ( $scope.selectedContract ) {
4068                     $scope.contractFormView = true;
4069                     angular.copy($scope.selectedContract, $scope.newContractObj);
4070                 }
4071                 event.defaultPrevented = true;
4072             }
4073         });
4074
4075         $scope.$on("WIZARD_SUBJECT_RELOAD", function(event, args){
4076             //$scope.selectedEpg['consumer-named-selector'] = args;
4077             $scope.newContractObj['subject'] = args;
4078             $scope.updateList($scope.list, $scope.newContractObj, "id");
4079         });
4080
4081         $scope.$on("WIZARD_CLAUSE_RELOAD", function(event, args){
4082             //$scope.selectedEpg['consumer-named-selector'] = args;
4083             $scope.newContractObj['clause'] = args;
4084             $scope.updateList($scope.list, $scope.newContractObj, "id");
4085         });
4086     }]);
4087
4088     gbpOld.register.controller('wizardCnsCtrl',['$scope', 'GBPConNamedSelServices', function($scope, GBPConNamedSelServices){
4089         $scope.list = [];
4090         $scope.selectedCNS = null;
4091         $scope.newCNSObj = GBPConNamedSelServices.createObj();
4092         $scope.internalView = {
4093             cns: false,
4094             edit: "view"
4095         };
4096         $scope.displayLabel = 'name';
4097         $scope.crudLabel = 'Consumer named selectors list';
4098
4099         $scope.contractList = {'options' : [], 'labels' : null};
4100         $scope.getDisplayLabelsFromCtrl('GBP_CONTRACTS_LABEL', $scope.contractList);
4101
4102         var clear = function(){
4103                 $scope.list = [];
4104                 $scope.selectedCNS = null;
4105                 $scope.newCNSObj = GBPConNamedSelServices.createObj();
4106                 $scope.internalView = {
4107                     cns: false,
4108                     edit: "add"
4109                 };
4110             };
4111
4112         //move to separate ctrl \/
4113         $scope.addNewElem = function(templateObj) {
4114             if($scope.newCNSObj && $scope.newCNSObj.contract) {
4115                 var objToPush = templateObj || "";
4116                 $scope.newCNSObj.contract.push(objToPush);
4117             }
4118         };
4119
4120         $scope.deleteElemAt = function(index) {
4121             if($scope.newCNSObj && $scope.newCNSObj.contract) {
4122                 $scope.newCNSObj.contract.splice(index, 1);
4123             }
4124         };
4125
4126         $scope.updateAt = function(index, value) {
4127             if($scope.newCNSObj && $scope.newCNSObj.contract && $scope.newCNSObj.contract.length >= index) {
4128                 $scope.newCNSObj.contract[index] = value;
4129             }
4130         };
4131         //move to separate ctrl /\
4132
4133         $scope.init = function() {
4134             clear();
4135
4136             if($scope.tenant && $scope.tenant['contract'].length>0) {
4137                 $scope.contractList.options = $scope.tenant['contract'];
4138             }
4139
4140             if($scope.selectedEpg && $scope.selectedEpg['consumer-named-selector']) {
4141                 $scope.list = $scope.selectedEpg['consumer-named-selector'];
4142             }
4143         };
4144
4145         $scope.save = function(){
4146             $scope.updateList($scope.list, $scope.newCNSObj, "name");
4147             $scope.reload($scope.newCNSObj);
4148             $scope.$emit('WIZARD_CNS_RELOAD', $scope.list);
4149             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newCNSObj);
4150         };
4151
4152         $scope.delete = function() {
4153             if($scope.selectedCNS) {
4154                 var index = $scope.list.indexOf($scope.selectedCNS);
4155                 $scope.list.splice(index, 1);
4156                 $scope.internalView = {
4157                     cns: false,
4158                     edit: "add"
4159                 };
4160                 $scope.$emit('WIZARD_CNS_RELOAD', $scope.list);
4161             }
4162         };
4163
4164         $scope.showForm = function() {
4165             $scope.reloadNewObj();
4166             $scope.selectedCNS = null;
4167             $scope.internalView.cns = true;
4168             $scope.internalView.edit = "add";
4169         };
4170
4171         $scope.reloadNewObj = function() {
4172             $scope.newCNSObj = GBPConNamedSelServices.createObj();
4173         };
4174
4175         $scope.reload = function(selectedObj) {
4176             $scope.selectedCNS = selectedObj;
4177             $scope.newCNSObj = selectedObj;
4178             $scope.internalView.cns = true;
4179         };
4180
4181         $scope.close = function(){
4182             $scope.internalView.cns = false;
4183             //$scope.internalView.edit = "view";
4184         };
4185
4186         $scope.$on('PGN_EDIT_ELEM', function(event){
4187             if (!event.defaultPrevented) {
4188                 if ( $scope.selectedEpg ) {
4189                     $scope.internalView.cns = true;
4190                     $scope.internalView.edit = "add";
4191                     angular.copy($scope.selectedCNS, $scope.newCNSObj);
4192                 }
4193                 event.defaultPrevented = true;
4194             }
4195         });
4196
4197         $scope.$on('WIZARD_EPG_RELOAD',function(){
4198             $scope.init();
4199         });
4200     }]);
4201
4202     gbpOld.register.controller('wizardPnsCtrl',['$scope', 'GBPProNamedSelServices', function($scope, GBPProNamedSelServices){
4203         $scope.list = [];
4204         $scope.selectedPNS = null;
4205         $scope.newPNSObj = GBPProNamedSelServices.createObj();
4206         $scope.displayLabel = 'name';
4207         $scope.crudLabel = 'Provider named selectors list';
4208         $scope.internalView = {
4209             pns: false,
4210             edit: "view"
4211         };
4212
4213         $scope.contractList = {'options' : [], 'labels' : null};
4214         $scope.getDisplayLabelsFromCtrl('GBP_CONTRACTS_LABEL', $scope.contractList);
4215
4216         var clear = function(){
4217                 $scope.list = [];
4218                 $scope.selectedPNS = null;
4219                 $scope.newPNSObj = GBPProNamedSelServices.createObj();
4220                 $scope.internalView = {
4221                     pns: false,
4222                     edit: "view"
4223                 };
4224             };
4225
4226         //move to separate ctrl \/
4227         $scope.addNewElem = function(templateObj) {
4228             if($scope.newPNSObj && $scope.newPNSObj.contract) {
4229                 var objToPush = templateObj || "";
4230                 $scope.newPNSObj.contract.push(objToPush);
4231             }
4232         };
4233
4234         $scope.deleteElemAt = function(index) {
4235             if($scope.newPNSObj && $scope.newPNSObj.contract) {
4236                 $scope.newPNSObj.contract.splice(index, 1);
4237             }
4238         };
4239
4240         $scope.updateAt = function(index, value) {
4241             if($scope.newPNSObj && $scope.newPNSObj.contract && $scope.newPNSObj.contract.length >= index) {
4242                 $scope.newPNSObj.contract[index] = value;
4243             }
4244         };
4245         //move to separate ctrl /\
4246
4247         $scope.init = function() {
4248             clear();
4249
4250             if($scope.tenant && $scope.tenant['contract'].length>0) {
4251                 $scope.contractList.options = $scope.tenant['contract'];
4252             }
4253
4254             if($scope.selectedEpg && $scope.selectedEpg['provider-named-selector']) {
4255                 $scope.list = $scope.selectedEpg['provider-named-selector'];
4256             }
4257         };
4258
4259         $scope.save = function(){
4260             $scope.updateList($scope.list, $scope.newPNSObj, "name");
4261             $scope.reload($scope.newPNSObj);
4262             $scope.$emit('WIZARD_PNS_RELOAD', $scope.list);
4263             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newPNSObj);
4264         };
4265
4266         $scope.delete = function() {
4267             if($scope.selectedPNS) {
4268                 var index = $scope.list.indexOf($scope.selectedPNS);
4269                 $scope.list.splice(index, 1);
4270                 $scope.internalView = {
4271                     pns: false,
4272                     edit: "add"
4273                 };
4274                 $scope.$emit('WIZARD_PNS_RELOAD', $scope.list);
4275             }
4276         };
4277
4278         $scope.showForm = function() {
4279             $scope.reloadNewObj();
4280             $scope.selectedPNS = null;
4281             $scope.internalView.pns = true;
4282             $scope.internalView.edit = "add";
4283         };
4284
4285         $scope.reloadNewObj = function() {
4286             $scope.newPNSObj = GBPProNamedSelServices.createObj();
4287         };
4288
4289         $scope.reload = function(selectedObj) {
4290             $scope.selectedPNS = selectedObj;
4291             $scope.newPNSObj = selectedObj;
4292             $scope.internalView.pns = true;
4293         };
4294
4295         $scope.close = function(){
4296             $scope.internalView.pns = false;
4297             $scope.internalView.edit = "view";
4298         };
4299         $scope.$on('PGN_EDIT_ELEM', function(event){
4300             if (!event.defaultPrevented) {
4301                 if ( $scope.selectedEpg ) {
4302                     $scope.internalView.pns = true;
4303                     $scope.internalView.edit = "edit";
4304                     angular.copy($scope.selectedPNS, $scope.newPNSObj);
4305                 }
4306                 event.defaultPrevented = true;
4307             }
4308         });
4309
4310         $scope.$on('WIZARD_EPG_RELOAD',function(){
4311             $scope.init();
4312         });
4313     }]);
4314
4315     gbpOld.register.controller('wizardSubjectCtrl', ['$scope','GBPSubjectServices', '$filter', function($scope, GBPSubjectServices, $filter){
4316         $scope.list = [];
4317         $scope.selectedSubject = null;
4318         $scope.newSubjectObj = GBPSubjectServices.createObj();
4319         $scope.displayLabel = 'name';
4320         $scope.internalView = {
4321             subject : false,
4322             edit : "view"
4323         };
4324         $scope.crudLabel = 'Subject list';
4325         $scope.errors = {};
4326
4327
4328         var path = null,
4329             mandatoryProperties = ['order'],
4330
4331             clear = function(){
4332                 $scope.list = [];
4333                 $scope.selectedSubject = null;
4334                 $scope.newSubjectObj = GBPSubjectServices.createObj();
4335                 $scope.internalView = {
4336                     subject : false,
4337                     edit : "view"
4338                 };
4339             };
4340
4341         $scope.init = function() {
4342
4343         };
4344
4345         $scope.save = function(){
4346             $scope.updateList($scope.list, $scope.newSubjectObj, "name");
4347             $scope.reload($scope.newSubjectObj);
4348             $scope.$emit('WIZARD_SUBJECT_RELOAD', $scope.list);
4349             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newSubjectObj);
4350         };
4351
4352         $scope.delete = function() {
4353             if($scope.selectedSubject) {
4354                 var index = $scope.list.indexOf($scope.selectedSubject);
4355                 $scope.list.splice(index, 1);
4356                 $scope.internalView = {
4357                     subject: false,
4358                     edit: "add"
4359                 };
4360                 $scope.reloadNewObj();
4361                 $scope.$emit('WIZARD_SUBJECT_RELOAD', $scope.list);
4362             }
4363         };
4364
4365         $scope.reloadNewObj = function() {
4366             $scope.newSubjectObj = GBPSubjectServices.createObj();
4367         };
4368
4369         $scope.reload = function(selectedObj) {
4370             $scope.selectedSubject = selectedObj;
4371             $scope.newSubjectObj = selectedObj;
4372             $scope.internalView.subject = true;
4373         };
4374
4375         $scope.showForm = function() {
4376             $scope.reloadNewObj();
4377             $scope.internalView.subject = true;
4378             $scope.internalView.edit = "add";
4379             $scope.selectedSubject = null;
4380         };
4381
4382         $scope.close = function(){
4383             $scope.internalView.subject = false;
4384             $scope.internalView.edit = "view";
4385         };
4386
4387         $scope.$on('PGN_EDIT_ELEM', function(event){
4388             if (!event.defaultPrevented) {
4389                 if ( $scope.selectedSubject ) {
4390                     $scope.internalView.subject = true;
4391                     $scope.internalView.edit = "edit";
4392                     angular.copy($scope.selectedSubject, $scope.newSubjectObj);
4393                 }
4394                 event.defaultPrevented = true;
4395             }
4396         });
4397
4398         $scope.$on('GBP_CONTRACT_RELOAD',function(){
4399             $scope.init();
4400         });
4401
4402         $scope.$on('GBP_SUBJECTS_LABEL', function(event, obj){
4403             obj.labels = $scope.displayLabel;
4404         });
4405
4406         $scope.$on("WIZARD_RULE_RELOAD", function(event, args){
4407             //$scope.selectedEpg['consumer-named-selector'] = args;
4408             $scope.newSubjectObj['rule'] = args;
4409             $scope.updateList($scope.list, $scope.newSubjectObj, "id");
4410             $scope.$emit('WIZARD_SUBJECT_RELOAD', $scope.list);
4411         });
4412     }]);
4413
4414     gbpOld.register.controller('wizardRuleCtrl', ['$scope','GBPRuleServices', '$filter', function($scope, GBPRuleServices, $filter){
4415         $scope.list = [];
4416         $scope.selectedRule = null;
4417         $scope.newRuleObj = GBPRuleServices.createObj();
4418         $scope.displayLabel = 'name';
4419         $scope.internalView = {
4420             rule : false,
4421             edit : "view"
4422         };
4423         $scope.crudLabel = 'Rule list';
4424         $scope.errors = {};
4425
4426         var path = null,
4427             mandatoryProperties = ['order'],
4428
4429             clear = function(){
4430                 $scope.list = [];
4431                 $scope.selectedRule = null;
4432                 $scope.newRuleObj = GBPRuleServices.createObj();
4433                 $scope.internalView = {
4434                     rule : false,
4435                     edit : "view"
4436                 };
4437             };
4438
4439         $scope.init = function() {
4440
4441         };
4442
4443         $scope.save = function(){
4444             $scope.updateList($scope.list, $scope.newRuleObj, "name");
4445             $scope.reload($scope.newRuleObj);
4446             $scope.$emit('WIZARD_RULE_RELOAD', $scope.list);
4447             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newRuleObj);
4448         };
4449
4450         $scope.delete = function() {
4451             if($scope.selectedRule) {
4452                 var index = $scope.list.indexOf($scope.selectedRule);
4453                 $scope.list.splice(index, 1);
4454                 $scope.internalView = {
4455                     rule: false,
4456                     edit: "add"
4457                 };
4458                 $scope.reloadNewObj();
4459                 $scope.$emit('WIZARD_RULE_RELOAD', $scope.list);
4460             }
4461         };
4462
4463         $scope.reloadNewObj = function() {
4464             $scope.newRuleObj = GBPRuleServices.createObj();
4465         };
4466
4467         $scope.reload = function(selectedObj) {
4468             $scope.selectedRule = selectedObj;
4469             $scope.newRuleObj = selectedObj;
4470             $scope.internalView.rule = true;
4471             $scope.$broadcast('WIZARD_RULE_RELOAD');
4472         };
4473
4474         $scope.showForm = function() {
4475             $scope.reloadNewObj();
4476             $scope.internalView.rule = true;
4477             $scope.internalView.edit = "add";
4478             $scope.selectedRule = null;
4479         };
4480
4481         $scope.close = function(){
4482             $scope.internalView.rule = false;
4483             $scope.internalView.edit = "view";
4484         };
4485
4486         $scope.$on('PGN_EDIT_ELEM', function(event){
4487             if (!event.defaultPrevented) {
4488                 if ( $scope.selectedRule ) {
4489                 $scope.internalView.rule = true;
4490                 $scope.internalView.edit = "edit";
4491                     angular.copy($scope.selectedRule, $scope.newRuleObj);
4492                 }
4493                 event.defaultPrevented = true;
4494             }
4495         });
4496
4497         $scope.$on('GBP_SUBJECT_RELOAD',function(){
4498             $scope.init();
4499         });
4500
4501         $scope.$on("WIZARD_CLASREF_RELOAD", function(event, args){
4502             $scope.newRuleObj['classifier-ref'] = args;
4503             $scope.updateList($scope.list, $scope.newRuleObj, "name");
4504             $scope.$emit('WIZARD_RULE_RELOAD', $scope.list);
4505         });
4506
4507         $scope.$on("WIZARD_ACTIONREF_RELOAD", function(event, args){
4508             $scope.newRuleObj['action-ref'] = args;
4509             $scope.updateList($scope.list, $scope.newRuleObj, "name");
4510             $scope.$emit('WIZARD_RULE_RELOAD', $scope.list);
4511         });
4512     }]);
4513
4514     gbpOld.register.controller('wizardClauseCtrl', ['$scope','GBPClauseServices', 'GBPSubjectServices',
4515         function($scope, GBPClauseServices, GBPSubjectServices){
4516         $scope.list = [];
4517         $scope.selectedClause = null;
4518         $scope.newClauseObj = GBPClauseServices.createObj();
4519         $scope.internalView = {
4520             clause: false,
4521             edit: "view"
4522         };
4523         $scope.displayLabel = 'name';
4524         $scope.crudLabel = 'Clause list';
4525
4526         $scope.subjects = {'options' : [], 'labels' : null};
4527         $scope.getDisplayLabelsFromCtrl('GBP_SUBJECTS_LABEL', $scope.subjects);
4528
4529         var path = null,
4530
4531             clear = function(){
4532                 $scope.list = [];
4533                 $scope.selectedClause = null;
4534                 $scope.newClauseObj = GBPClauseServices.createObj();
4535                 $scope.internalView = {
4536                     clause: false,
4537                     edit: "view"
4538                 };
4539             };
4540
4541         //move to separate ctrl \/
4542         $scope.addNewElem = function(templateObj) {
4543             if($scope.newClauseObj && $scope.newClauseObj['subject-refs']) {
4544                 $scope.init();
4545                 var objToPush = templateObj || "";
4546                 $scope.newClauseObj['subject-refs'].push(objToPush);
4547             }
4548         };
4549
4550         $scope.deleteElemAt = function(index) {
4551             if($scope.newClauseObj && $scope.newClauseObj['subject-refs']) {
4552                 $scope.newClauseObj['subject-refs'].splice(index, 1);
4553             }
4554         };
4555
4556         $scope.updateAt = function(index, value) {
4557             if($scope.newClauseObj && $scope.newClauseObj['subject-refs'] && $scope.newClauseObj['subject-refs'].length >= index) {
4558                 $scope.newClauseObj['subject-refs'][index] = value;
4559             }
4560         };
4561         //move to separate ctrl /\
4562
4563         $scope.init = function() {
4564             if($scope.selectedContract && $scope.selectedContract['subject'].length>0) {
4565                 $scope.subjects.options = $scope.selectedContract['subject'];
4566             }
4567         };
4568
4569         $scope.save = function(){
4570             $scope.updateList($scope.list, $scope.newClauseObj, "name");
4571             $scope.reload($scope.newClauseObj);
4572             $scope.$emit('WIZARD_CLAUSE_RELOAD', $scope.list);
4573             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newClauseObj);
4574         };
4575
4576         $scope.delete = function() {
4577             if($scope.selectedClause) {
4578                 var index = $scope.list.indexOf($scope.selectedClause);
4579                 $scope.list.splice(index, 1);
4580                 $scope.internalView = {
4581                     clause: false,
4582                     edit: "add"
4583                 };
4584                 $scope.$emit('WIZARD_CLAUSE_RELOAD', $scope.list);
4585             }
4586         };
4587
4588         $scope.reloadNewObj = function() {
4589             $scope.newClauseObj = GBPClauseServices.createObj();
4590         };
4591
4592         $scope.reload = function(selectedObj) {
4593             $scope.selectedClause = selectedObj;
4594             $scope.newClauseObj = selectedObj;
4595             $scope.internalView.clause = true;
4596         };
4597
4598         $scope.showForm = function() {
4599             $scope.reloadNewObj();
4600             $scope.internalView.clause = true;
4601             $scope.internalView.edit = "add";
4602             $scope.selectedClause = null;
4603         };
4604
4605         $scope.close = function(){
4606             $scope.internalView.clause = false;
4607             $scope.internalView.edit = "view";
4608         };
4609
4610         $scope.$on('PGN_EDIT_ELEM', function(event){
4611             if (!event.defaultPrevented) {
4612                 if ( $scope.selectedClause ) {
4613                     $scope.internalView.clause = true;
4614                     $scope.internalView.edit = "edit";
4615                     angular.copy($scope.selectedClause, $scope.newClauseObj);
4616                 }
4617                 event.defaultPrevented = true;
4618             }
4619         });
4620
4621         $scope.$on('WIZARD_SUBJECT_RELOAD',function(){
4622             $scope.init();
4623         });
4624     }]);
4625
4626     gbpOld.register.controller('wizardActionRefCtrl', ['$scope','GBPActionRefsServices', 'GBPActionInstanceServices', '$filter', function($scope, GBPActionRefsServices, GBPActionInstanceServices, $filter){
4627         $scope.list = [];
4628         $scope.selectedActionRef = null;
4629         $scope.newActionRefObj = GBPActionRefsServices.createObj();
4630         $scope.displayLabel = 'name';
4631         $scope.internalView = {
4632             actionRef : false,
4633             edit : "view"
4634         };
4635         $scope.crudLabel = 'Action ref list';
4636
4637         $scope.actionInstanceNames = {'options' : [], 'labels' : $scope.displayLabel};
4638
4639         var path = null,
4640             mandatoryProperties = ['order'],
4641
4642             actionInstanceNamesLoad = function() {
4643                 if($scope.tenant) {
4644                     var actionInstancePath = GBPActionInstanceServices.createPathObj($scope.tenant.id);
4645                     GBPActionInstanceServices.load(actionInstancePath, function(data){
4646                         $scope.actionInstanceNames.options = data;
4647                     },function(){
4648                         //TODO: error cbk
4649                     });
4650                 }
4651             },
4652
4653             clear = function(){
4654                 $scope.list = [];
4655                 $scope.selectedActionRef = null;
4656                 $scope.newActionRefObj = GBPActionRefsServices.createObj();
4657                 $scope.internalView = {
4658                     actionRef : false,
4659                     edit : "view"
4660                 };
4661             };
4662
4663         $scope.init = function() {
4664             actionInstanceNamesLoad();
4665         };
4666
4667         $scope.save = function(){
4668             $scope.updateList($scope.list, $scope.newActionRefObj, "name");
4669             $scope.reload($scope.newActionRefObj);
4670             $scope.$emit('WIZARD_ACTIONREF_RELOAD', $scope.list);
4671             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newActionRefObj);
4672         };
4673
4674         $scope.delete = function() {
4675             if($scope.selectedActionRef) {
4676                 var index = $scope.list.indexOf($scope.selectedActionRef);
4677                 $scope.list.splice(index, 1);
4678                 $scope.internalView = {
4679                     actionRef: false,
4680                     edit: "add"
4681                 };
4682                 $scope.$emit('WIZARD_ACTIONREF_RELOAD', $scope.list);
4683             }
4684         };
4685
4686         $scope.reloadNewObj = function() {
4687             $scope.newActionRefObj = GBPActionRefsServices.createObj();
4688         };
4689
4690         $scope.reload = function(selectedObj) {
4691             $scope.selectedActionRef = selectedObj;
4692             $scope.newActionRefObj = selectedObj;
4693             $scope.internalView.actionRef = true;
4694         };
4695
4696         $scope.showForm = function() {
4697             $scope.reloadNewObj();
4698             $scope.internalView.actionRef = true;
4699             $scope.internalView.edit = "add";
4700             $scope.selectedActionRef = null;
4701         };
4702
4703         $scope.close = function(){
4704             $scope.internalView.actionRef = false;
4705             $scope.internalView.edit = "view";
4706         };
4707
4708         $scope.$on('PGN_EDIT_ELEM', function(event){
4709             if (!event.defaultPrevented) {
4710                 if ( $scope.selectedActionRef ) {
4711                     $scope.internalView.actionRef = true;
4712                     $scope.internalView.edit = "edit";
4713                     angular.copy($scope.selectedActionRef, $scope.newActionRefObj);
4714                 }
4715                 event.defaultPrevented = true;
4716             }
4717         });
4718
4719         $scope.$on('WIZARD_RULE_RELOAD',function(){
4720             $scope.init();
4721         });
4722     }]);
4723
4724     gbpOld.register.controller('wizardClassifierRefCtrl', ['$scope','GBPClassifierRefsServices', 'GBPClassifierInstanceServices', '$filter', function($scope, GBPClassifierRefsServices, GBPClassifierInstanceServices, $filter){
4725         $scope.list = [];
4726         $scope.selectedClassifierRef = null;
4727         $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
4728         $scope.displayLabel = 'name';
4729         $scope.internalView = {
4730             classifierRef : false,
4731             edit : "view"
4732         };
4733
4734         $scope.instanceNames = {'options' : [], 'labels' : $scope.displayLabel};
4735
4736         $scope.formDirections = ['in', 'out', 'bidirectional'];
4737         $scope.formConnectionTracking = ['normal', 'reflexive'];
4738
4739         $scope.crudLabel = 'Classifier ref list';
4740
4741         var path = null,
4742
4743             instanceNamesLoad = function() {
4744                 if($scope.tenant) {
4745                     var classifierInstancePath = GBPClassifierInstanceServices.createPathObj($scope.tenant.id);
4746                     GBPClassifierInstanceServices.load(classifierInstancePath, function(data){
4747                         $scope.instanceNames.options = data;
4748                     },function(){
4749                         //TODO: error cbk
4750                     });
4751                 }
4752             },
4753
4754             clear = function(){
4755                 $scope.list = [];
4756                 $scope.selectedClassifierRef = null;
4757                 $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
4758                 $scope.internalView = {
4759                     classifierRef : false,
4760                     edit : "view"
4761                 };
4762             };
4763
4764         $scope.init = function() {
4765             instanceNamesLoad();
4766         };
4767
4768         $scope.save = function(){
4769             $scope.updateList($scope.list, $scope.newClassifierRefObj, "name");
4770             $scope.reload($scope.newClassifierRefObj);
4771             $scope.$emit('WIZARD_CLASREF_RELOAD', $scope.list);
4772             $scope.$broadcast('EV_SET_SEL_CLASS', $scope.newClassifierRefObj);
4773         };
4774
4775         $scope.delete = function() {
4776             if($scope.selectedClassifierRef) {
4777                 var index = $scope.list.indexOf($scope.selectedClassifierRef);
4778                 $scope.list.splice(index, 1);
4779                 $scope.internalView = {
4780                     classifierRef: false,
4781                     edit: "add"
4782                 };
4783                 $scope.$emit('WIZARD_CLASREF_RELOAD', $scope.list);
4784             }
4785         };
4786
4787         $scope.reloadNewObj = function() {
4788             $scope.newClassifierRefObj = GBPClassifierRefsServices.createObj();
4789         };
4790
4791         $scope.reload = function(selectedObj) {
4792             $scope.selectedClassifierRef = selectedObj;
4793             $scope.newClassifierRefObj = selectedObj;
4794             $scope.internalView.classifierRef = true;
4795         };
4796
4797         $scope.showForm = function() {
4798             $scope.reloadNewObj();
4799             $scope.internalView.classifierRef = true;
4800             $scope.internalView.edit = "add";
4801             $scope.selectedClassifierRef = null;
4802         };
4803
4804         $scope.close = function(){
4805             $scope.internalView.classifierRef = false;
4806             $scope.internalView.edit = "view";
4807         };
4808
4809         $scope.$on('PGN_EDIT_ELEM', function(event){
4810             if (!event.defaultPrevented) {
4811                 if ( $scope.selectedClassifierRef ) {
4812                     $scope.internalView.classifierRef = true;
4813                     $scope.internalView.edit = "edit";
4814                     angular.copy($scope.selectedClassifierRef, $scope.newClassifierRefObj);
4815                 }
4816                 event.defaultPrevented = true;
4817             }
4818         });
4819
4820         $scope.$on('WIZARD_RULE_RELOAD',function(){
4821             $scope.init();
4822         });
4823     }]);
4824
4825     gbpOld.register.controller('rendererStateCtrl', ['$scope', 'GPBServices', function($scope, GPBServices){
4826         $scope.data = {'subject-feature-definitions' : {}};
4827         $scope.view_path = 'src/app/gbp-old/views/governance';
4828
4829         var init = function(){
4830             GPBServices.getDefinitions(function(classifiersDefs, actionsDefs){
4831                 $scope.data['subject-feature-definitions']['classifier-definition'] = classifiersDefs;
4832                 $scope.data['subject-feature-definitions']['action-definition'] = actionsDefs;
4833             }, function(){
4834                 //error
4835             });
4836         };
4837
4838         init();
4839     }]);
4840
4841     gbpOld.register.controller('layerCtrl', ['$scope', function($scope){
4842
4843         var moveOffset = 1;
4844         $scope.currentDisplayIndex = 1;
4845         $scope.displayOffsets = [-1, 0, 1];
4846         $scope.expanded = true;
4847
4848         $scope.init = function(key, value){
4849             $scope.data = value;
4850             if($scope.checkData(value, 'Array')){
4851                 $scope.setActData($scope.data[$scope.data.length - 1]);
4852             }
4853         };
4854
4855         $scope.toggleExpanded = function(){
4856             $scope.expanded = !$scope.expanded;
4857         };
4858
4859         $scope.shiftDisplayNext = function() {
4860             $scope.currentDisplayIndex = Math.min($scope.currentDisplayIndex + moveOffset, $scope.data.length - 2);
4861         };
4862
4863         $scope.shiftDisplayPrev = function() {
4864             $scope.currentDisplayIndex = Math.max($scope.currentDisplayIndex - moveOffset, 1);
4865         };
4866
4867         $scope.showPrevButton = function() {
4868             return $scope.currentDisplayIndex > 1;
4869         };
4870
4871         $scope.showNextButton = function() {
4872             return $scope.data && $scope.currentDisplayIndex < $scope.data.length - 2;
4873         };
4874
4875         $scope.setActData = function(data) {
4876             $scope.actSelected = data;
4877         };
4878
4879         $scope.checkData = function(data, type){
4880             var result = {'Array' : data instanceof Array,
4881                         'Object' : data instanceof Object};
4882
4883             return result[type];
4884         };
4885     }]);
4886
4887     gbpOld.register.controller('actionReferenceWizardCtrl', ['$scope', '$filter', 'GBPRuleServices', 'GBPActionInstanceServices', function($scope, $filter, GBPRuleServices, GBPActionInstanceServices){
4888         $scope.wizardPage = null;
4889         $scope.path = {};
4890         $scope.rule = {};
4891
4892         $scope.actionInstanceNames = {'options' : [], 'labels' : "name"};
4893
4894         var actionInstanceNamesLoad = function() {
4895             var actionInstancePath = GBPActionInstanceServices.createPathObj($scope.selectedTenant.id);
4896             GBPActionInstanceServices.load(actionInstancePath, function(data){
4897                 $scope.actionInstanceNames.options = data;
4898             },function(){
4899                 //TODO: error cbk
4900             });
4901         };
4902
4903         $scope.init = function() {
4904             $scope.setPage('reference');
4905         };
4906
4907         $scope.setPage = function(pageName, object) {
4908             $scope.wizardPage = pageName;
4909         };
4910
4911         $scope.submit = function() {
4912             //if($scope.validateForm($scope.actionsForm)){
4913                 $scope.actionInstanceNames.options.forEach(function(i) {
4914                     path = GBPActionInstanceServices.createPathObj($scope.path.tenantId, i.name);
4915                 //saveParams();
4916
4917                     GBPActionInstanceServices.send(path, i, function(data){
4918                     $scope.sendReloadEventFromRoot('GBP_ACTION_INSTANCE_RELOAD');
4919                     }, function(){
4920                         //TODO: error cbk
4921                     });
4922                 });
4923
4924             //}
4925
4926             //if($scope.validateForm($scope.rulesForm)){
4927                 path = GBPRuleServices.createPathObj($scope.path.tenantId, $scope.path.contractId, $scope.path.subjectId, $scope.path.ruleId);
4928                 GBPRuleServices.send(path, $scope.rule, function(data){
4929
4930                     $scope.wizards.actionReferenceWizard = false;
4931
4932                     //$scope.sendReloadEventFromRoot('GBP_TENANT_RELOAD');
4933                 }, function(){
4934                     //TODO: error cbk
4935                 });
4936             //}
4937             //$scope.
4938         };
4939
4940         $scope.$on('ACTION_RULE_WIZARD_LOAD', function(event, data){
4941             $scope.rule = angular.copy(data.data);
4942             $scope.path = data.path;
4943         });
4944
4945         $scope.$on('WIZARD_ACTIONREF_ADD', function(event, data){
4946             if(!$scope.rule['action-ref']) {
4947                 $scope.rule['action-ref'] = [];
4948             }
4949             $scope.updateList($scope.rule['action-ref'], data, "name");
4950         });
4951
4952         $scope.$on('WIZARD_ACTIONREF_DELETE', function(event, data){
4953             $scope.rule['action-ref'].splice(data, 1);
4954         });
4955
4956         $scope.$on('WIZARD_ACTIONINSTANCE_ADD', function(event, data){
4957             $scope.updateList($scope.actionInstanceNames.options, data, "name");
4958
4959             $scope.setPage('reference');
4960         });
4961
4962         $scope.$on('GBP_TENANT_RELOAD',function(){
4963             actionInstanceNamesLoad();
4964         });
4965
4966     }]);
4967
4968     gbpOld.register.controller('actionsRefListCtrl', ['$scope', '$filter', function($scope, $filter){
4969
4970         $scope.actionReferenceForm = false;
4971
4972         $scope.showForm = function(object) {
4973             $scope.actionReferenceForm = true;
4974             $scope.newActionRefObj = object || null;
4975         };
4976
4977         $scope.closeForm = function() {
4978             $scope.actionReferenceForm = false;
4979         };
4980
4981         $scope.save = function(){
4982             $scope.$emit('WIZARD_ACTIONREF_ADD', $scope.newActionRefObj);
4983             $scope.resetObject();
4984         };
4985
4986         $scope.deleteElemAt = function(index) {
4987             $scope.$emit('WIZARD_ACTIONREF_DELETE', index);
4988             $scope.resetObject();
4989         };
4990
4991         $scope.resetObject = function() {
4992             $scope.newActionRefObj = null;
4993         };
4994
4995
4996
4997     }]);
4998
4999     gbpOld.register.controller('actionInstanceWizardCtrl', ['$scope', '$filter', 'GPBServices', 'GBPActionInstanceServices', function($scope, $filter, GPBServices, GBPActionInstanceServices){
5000         $scope.actionDefinitions = {'options' : [], 'labels' : "name"};
5001         $scope.newActionObj = GBPActionInstanceServices.createObj();
5002
5003         var loadDefinitions = function() {
5004             GPBServices.getDefinitions(function(classifierDefs, actionDefs) {
5005                 $scope.actionDefinitions.options = actionDefs;
5006                 //$scope.getDisplayLabelsFromCtrl('GBP_ACTIONS_LABEL', $scope.actionDefinitions);
5007             });
5008         };
5009
5010         $scope.reloadDefs = function(){
5011             $scope.defs = angular.copy($scope.getDefinitionObjParams($scope.newActionObj['action-definition-id']));
5012
5013             //TODO: rework
5014             if($scope.defs.length && $scope.defs[0].name === 'sfc-chain-name') {
5015                 GPBServices.getServiceFunctionChains(function(data) {
5016                     $scope.serviceFunctionChains = data;
5017                 });
5018             }
5019         };
5020
5021         $scope.getDefinitionObjParams = function(id){
5022             return GPBServices.getDefinitionObjParams($scope.actionDefinitions.options, id);
5023         };
5024
5025         $scope.save = function(){
5026             $scope.newActionObj['parameter-value'] = [];
5027             $scope.$broadcast('GBP_SAVE_PARAM');
5028             $scope.$emit('WIZARD_ACTIONINSTANCE_ADD', $scope.newActionObj);
5029             $scope.resetObject();
5030         };
5031
5032         $scope.resetObject = function() {
5033             $scope.newActionObj = GBPActionInstanceServices.createObj();
5034         };
5035
5036         $scope.saveParam = function() {
5037
5038         };
5039
5040         $scope.addParam = function(name, type, value) {
5041             $scope.newActionObj['parameter-value'].push(GPBServices.createParamObj(name, type, value));
5042         };
5043
5044         loadDefinitions();
5045
5046     }]);
5047
5048 });
5049
5050