2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 angular.module('abs').controller('dcaeMicroServiceController', function ($scope, $window, $compile, PapUrlService, PolicyDictionaryService, modalService, $modal, Notification) {
26 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
28 PapUrlService.getPapUrl().then(function(data) {
30 papUrl = config.PAP_URL;
33 PolicyDictionaryService.getEcompDictionaryData(papUrl).then(function (data) {
35 $scope.data = JSON.parse(j.data);
36 console.log($scope.data);
37 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
38 console.log($scope.ecompNameDictionaryDatas);
40 console.log("failed");
43 PolicyDictionaryService.getPriorityValueData().then(function (data) {
45 $scope.data = JSON.parse(j.data);
46 console.log($scope.data);
47 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
48 console.log($scope.priorityDatas);
50 console.log("failed");
53 PolicyDictionaryService.getPolicyScopeData(papUrl).then(function (data) {
55 $scope.data = JSON.parse(j.data);
56 console.log($scope.data);
57 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
58 console.log($scope.groupPolicyScopeListDatas);
60 console.log("failed");
63 PolicyDictionaryService.getMSConfigDataByName(papUrl).then(function (data) {
65 $scope.data = JSON.parse(j.data);
66 console.log($scope.data);
67 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
68 console.log($scope.microServiceCongigNameDictionaryDatas);
70 console.log("failed");
73 PolicyDictionaryService.getMSLocationDataByName(papUrl).then(function (data) {
75 $scope.data = JSON.parse(j.data);
76 console.log($scope.data);
77 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
78 console.log($scope.microServiceLocationDictionaryDatas);
80 console.log("failed");
83 PolicyDictionaryService.getMSServiceModelsDataByName(papUrl).then(function (data) {
85 $scope.data = JSON.parse(j.data);
86 console.log($scope.data);
87 $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
88 console.log($scope.microServiceModelsDictionaryDatas);
90 console.log("failed");
93 PolicyDictionaryService.getDCAEuuidDataByName(papUrl).then(function (data) {
95 $scope.data = JSON.parse(j.data);
96 console.log($scope.data);
97 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
98 console.log($scope.dcaeUUIDDictionaryDatas);
100 console.log("failed");
103 PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
105 $scope.data = JSON.parse(j.data);
106 console.log($scope.data);
107 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
108 console.log($scope.riskTypeDictionaryDatas);
109 }, function (error) {
110 console.log("failed");
113 PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
115 $scope.data = JSON.parse(j.data);
116 console.log($scope.data);
117 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
118 console.log($scope.riskLevelDatas);
119 }, function (error) {
120 console.log("failed");
123 PolicyDictionaryService.getGuardValueData().then(function (data) {
125 $scope.data = JSON.parse(j.data);
126 console.log($scope.data);
127 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
128 console.log($scope.guardDatas);
129 }, function (error) {
130 console.log("failed");
135 $scope.attributeDatas = [{"attributes" : $scope.choices}];
137 $scope.addNewChoice = function(value) {
139 if(value != undefined){
140 var parentElement = document.getElementById("div."+value);
141 var div = document.getElementById(value+"@0");
143 var clone = div.cloneNode(true);
144 var addElement = parentElement.childElementCount + 1;
145 clone.id = ''+value+'@'+addElement;
147 document.getElementById("div."+value).appendChild(clone);
148 plainAttributeKeys.push(''+value+'@'+addElement);
150 div = document.getElementById("div."+value+"@0");
151 var childElement = parentElement.firstElementChild;
152 var countParent = parentElement.childElementCount;
153 var childElementString = childElement.innerHTML;
154 var find = value+"@0";
155 var re = new RegExp(find, 'g');
156 childElementString = childElementString.replace(re,value+'@' + countParent);
157 var clone = childElement.cloneNode(true);
158 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
159 var childId = parentElement.childNodes[ii].id;
160 if(ii = parentElement.childNodes.length){
161 var childnewId = childId.slice(0, -1);
162 var count = childId.slice(-1);
165 var countvalue = parseInt(count) + 1;
166 clone.id = childnewId+countvalue;
168 clone.innerHTML=childElementString;
169 document.getElementById("div."+value).appendChild(clone);
170 var inputs = clone.getElementsByTagName("input");
171 for(var i=0; i<inputs.length; i++){
172 if($scope.temp.policy.ruleData != null){
173 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
175 plainAttributeKeys.push(inputs[i].id);
177 var ele = angular.element(document.getElementById("div."+value));
178 $compile(ele.contents())($scope);
184 $scope.removeChoice = function(value) {
186 if(value != undefined){
187 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
192 var splitEqual = '=';
193 var splitComma = ',';
194 var splitcolon = ':';
195 var plainAttributeKeys = [];
196 $scope.addDataToFields = function(serviceName){
197 if(serviceName != null){
198 var myNode = document.getElementById("DynamicTemplate");
199 myNode.innerHTML = '';
200 var uuu = "policyController/getDCAEMSTemplateData.htm";
201 var postData={policyData: serviceName};
206 contentType: 'application/json',
207 data: JSON.stringify(postData),
208 success : function(data){
209 $scope.$apply(function(){
210 $scope.addNewChoice();
211 var plainAttributeKeys = [];
212 $scope.dcaeModelData = data[0].dcaeModelData;
213 var attributes = $scope.dcaeModelData.attributes;
214 var refAttributes = $scope.dcaeModelData.ref_attributes;
215 var subAttributes = $scope.dcaeModelData.sub_attributes;
217 $scope.temp.policy.ruleGridData = [];
218 if(attributes != null && attributes.length>0){
219 if(attributes.indexOf(splitComma) >= 0){
220 var attributesAfterCommaSplit = attributes.split(splitComma);
221 for(i = 0; i < attributesAfterCommaSplit.length; i++){
222 if(attributesAfterCommaSplit[i].indexOf(splitcolon) > 0){
223 var splitAttribute = attributesAfterCommaSplit[i].split(splitcolon);
224 $scope.attributeLayout(splitAttribute);
228 //Implementation for single Attribute
229 var attributesAfterCommaSplit = attributes;
230 var splitAttribute = attributesAfterCommaSplit.split(splitcolon);
231 $scope.attributeLayout(splitAttribute);
235 if(refAttributes != null){
236 if(refAttributes.indexOf(splitComma) >= 0){
237 var refattributesAfterCommaSplit = refAttributes.split(splitComma);
238 for(j = 0; j < refattributesAfterCommaSplit.length; j++){
239 if(refattributesAfterCommaSplit[j].indexOf(splitcolon) > 0){
240 var splitRefAttribute = refattributesAfterCommaSplit[j].split(splitcolon);
241 $scope.refAttributeLayout(splitRefAttribute, subAttributes);
245 //Implementation for single RefAttribute
246 if(refAttributes != ""){
247 var refattributesAfterCommaSplit = refAttributes;
248 var splitRefAttribute = refattributesAfterCommaSplit.split(splitcolon);
249 $scope.refAttributeLayout(splitRefAttribute, subAttributes);
254 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
257 if($scope.temp.policy.ruleData != null){
258 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
259 propNames.forEach(function(name) {
262 for(a = 0; a < data.length; a++){
263 var splitPlainAttributeKey1 = data[a].split(".");
264 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
265 var key = splitPlainAttributeKey1[0];
269 var unique = checkData.filter(onlyUnique);
270 for(i =0; i < unique.length; i++){
271 if(unique[i].indexOf("@0") == -1){
272 var finalkey = unique[i].split("@")[0];
273 $scope.addNewChoice(finalkey);
278 var ele = angular.element(document.getElementById("DynamicTemplate"));
279 $compile(ele.contents())($scope);
282 error : function(data){
283 alert("Error While Retriving the Template Layout Pattren.");
289 function onlyUnique(value, index, self) {
290 return self.indexOf(value) === index;
293 $scope.attributeLayout = function(splitAttribute){
294 var attributeValue = splitAttribute[0];
295 var splitAttributeValue = attributeValue.split(splitEqual);
296 var attibuteKey = splitAttributeValue[0].trim();
297 var attributeType = splitAttributeValue[1];
298 var attributedefaultValue = splitAttribute[1];
299 var attributeRequiredValue = splitAttribute[2];
300 var attributeManyValue = splitAttribute[3];
301 var splitAttributeMany = attributeManyValue.split(splitDash);
302 var attributeManyKey = splitAttributeMany[1];
303 $scope.temp.policy.ruleGridData.push(attibuteKey);
304 var br = document.createElement("BR");
305 var label = document.createElement("Label");
306 var labeltext = document.createTextNode(attibuteKey);
307 label.appendChild(labeltext);
308 var element = document.getElementById("DynamicTemplate");
309 var textField = document.createElement("INPUT");
310 textField.setAttribute("class" , "form-control");
311 textField.setAttribute("type" , "text");
312 textField.setAttribute("style" , "width:300px;");
313 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
315 if(attributeManyKey == 'true'){
316 checkKey = attibuteKey+'@0';
317 textField.setAttribute("id" , ''+attibuteKey+'@0'+'');
318 var divTag = document.createElement("div");
319 divTag.setAttribute("id", "div."+attibuteKey);
320 var addButton = document.createElement("BUTTON");
321 var buttonaddLabel = document.createTextNode("+");
322 addButton.appendChild(buttonaddLabel);
323 addButton.setAttribute("id", attibuteKey);
324 addButton.setAttribute("class", "btn btn-default");
325 addButton.setAttribute("ng-click" , 'addNewChoice("'+attibuteKey+'");');
326 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
327 var removeButton = document.createElement("BUTTON");
328 var buttonremoveLabel = document.createTextNode("-");
329 removeButton.appendChild(buttonremoveLabel);
330 removeButton.setAttribute("class", "btn btn-default");
331 removeButton.setAttribute("ng-click" , 'removeChoice("'+attibuteKey+'");');
332 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
333 document.getElementById("DynamicTemplate").appendChild(addButton);
334 document.getElementById("DynamicTemplate").appendChild(removeButton);
335 document.getElementById("DynamicTemplate").appendChild(label);
336 document.getElementById("DynamicTemplate").appendChild(textField);
337 document.getElementById("DynamicTemplate").appendChild(divTag);
338 document.getElementById("DynamicTemplate").appendChild(br);
340 checkKey = attibuteKey;
341 textField.setAttribute("id" , ''+attibuteKey+'');
342 document.getElementById("DynamicTemplate").appendChild(label);
343 document.getElementById("DynamicTemplate").appendChild(textField);
344 document.getElementById("DynamicTemplate").appendChild(br);
346 if($scope.temp.policy.ruleData != null){
347 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
349 plainAttributeKeys.push(attibuteKey+'*'+attributeManyKey);
352 $scope.firstlayer = null;
353 $scope.secondlayer = null;
354 $scope.refAttributeLayout = function(splitRefAttribute, subAttributes){
355 var attibuteKey = splitRefAttribute[0];
356 var splitRefAttributeValue = attibuteKey.split(splitEqual);
357 var refattributeLabel = splitRefAttributeValue[0].trim();
358 var refattributeValue = splitRefAttributeValue[1].trim();
360 var refattributeManyValue = splitRefAttribute[1];
361 var splitRefAttributeMany = refattributeManyValue.split(splitDash);
362 var refattributeManyKey = splitRefAttributeMany[1];
363 var subAttributeJSON = JSON.parse(subAttributes);
364 var resultValue = subAttributeJSON[refattributeValue];
365 var br = document.createElement("BR");
366 var label = document.createElement("Label");
367 var labeltext = document.createTextNode(refattributeLabel);
368 label.appendChild(labeltext);
370 if(refattributeManyKey == 'true'){
372 var divTag = document.createElement("div");
373 divTag.setAttribute("id", "div."+refattributeLabel);
374 var addButton = document.createElement("BUTTON");
375 var buttonLabel = document.createTextNode("+");
376 addButton.appendChild(buttonLabel);
377 addButton.setAttribute("id", refattributeLabel);
378 addButton.setAttribute("class", "btn btn-default");
379 addButton.setAttribute("ng-click" , 'addNewChoice("'+refattributeLabel+'");');
380 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
381 var removeButton = document.createElement("BUTTON");
382 var buttonremoveLabel = document.createTextNode("-");
383 removeButton.appendChild(buttonremoveLabel);
384 removeButton.setAttribute("class", "btn btn-default");
385 removeButton.setAttribute("ng-click" , 'removeChoice("'+refattributeLabel+'");');
386 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
387 document.getElementById("DynamicTemplate").appendChild(addButton);
388 document.getElementById("DynamicTemplate").appendChild(removeButton);
389 document.getElementById("DynamicTemplate").appendChild(label);
390 document.getElementById("DynamicTemplate").appendChild(br);
391 document.getElementById("DynamicTemplate").appendChild(divTag);
392 var divTag = document.createElement("div");
393 divTag.setAttribute("id", "div."+refattributeLabel+"@0");
394 document.getElementById("div."+refattributeLabel).appendChild(divTag);
395 $scope.firstlayer = refattributeLabel+"@0";
396 $scope.subAttributeLayout(resultValue, subAttributes, refattributeLabel);
397 document.getElementById("DynamicTemplate").appendChild(br);
399 document.getElementById("DynamicTemplate").appendChild(label);
400 document.getElementById("DynamicTemplate").appendChild(br);
401 $scope.firstlayer = refattributeLabel;
402 $scope.subAttributeLayout(resultValue, subAttributes, refattributeLabel);
406 $scope.subAttributeLayout = function(resultValue, subAttributes, refattributeLabel){
407 for(var key in resultValue){
409 if(key == 'logicalConnector'){
410 $scope.secondlayer = null;
412 var splitSubAttribute = resultValue[key].split(splitcolon);
413 var br = document.createElement("BR");
414 var label = document.createElement("Label");
415 var labeltext = document.createTextNode(key);
416 label.appendChild(labeltext);
417 var textField = document.createElement("INPUT");
418 textField.setAttribute("class" , "form-control");
419 textField.setAttribute("type" , "text");
420 textField.setAttribute("style" , "width:300px;");
421 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
423 if(splitSubAttribute.length >= 3){
424 var subattributeType = splitSubAttribute[0];
425 var subattributedefaultValue = splitSubAttribute[1];
426 var subattributeRequiredValue = splitSubAttribute[2];
427 var subattributeManyValue = splitSubAttribute[3];
428 var splitSubAttributeMany = subattributeManyValue.split(splitDash);
429 var subattributeManyKey = splitSubAttributeMany[1];
430 if(subattributeManyKey == 'true'){
431 if($scope.firstlayer == null && $scope.secondlayer == null){
432 textField.setAttribute("id" , ''+key+'@0'+'');
434 if($scope.firstlayer != null && $scope.secondlayer == null){
435 textField.setAttribute("id" , ''+$scope.firstlayer+'.'+key+'@0'+'');
437 if($scope.firstlayer != null && $scope.secondlayer != null){
438 textField.setAttribute("id" , ''+$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0'+'');
440 var divTag = document.createElement("div");
441 var addButton = document.createElement("BUTTON");
442 var buttonLabel = document.createTextNode("+");
443 addButton.appendChild(buttonLabel);
444 addButton.setAttribute("class", "btn btn-default");
445 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
446 var removeButton = document.createElement("BUTTON");
447 var buttonremoveLabel = document.createTextNode("-");
448 removeButton.appendChild(buttonremoveLabel);
449 removeButton.setAttribute("class", "btn btn-default");
450 if($scope.secondlayer == null){
451 addButton.setAttribute("ng-click" , 'addNewChoice("'+$scope.firstlayer+'.'+key+'");');
452 removeButton.setAttribute("ng-click" , 'removeChoice("'+$scope.firstlayer+'.'+key+'");');
453 divTag.setAttribute("id", "div."+$scope.firstlayer+'.'+key);
455 addButton.setAttribute("ng-click" , 'addNewChoice("'+$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'");');
456 removeButton.setAttribute("ng-click" , 'removeChoice("'+$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'");');
457 divTag.setAttribute("id", "div."+$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key);
460 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
461 if(!refattributeLabel.startsWith('div.')){
462 refattributeLabel = 'div.'+refattributeLabel+"@0";
464 document.getElementById(refattributeLabel).appendChild(addButton);
465 document.getElementById(refattributeLabel).appendChild(removeButton);
466 document.getElementById(refattributeLabel).appendChild(label);
467 document.getElementById(refattributeLabel).appendChild(textField);
468 document.getElementById(refattributeLabel).appendChild(divTag);
469 document.getElementById(refattributeLabel).appendChild(br);
471 if($scope.firstlayer == null && $scope.secondlayer == null){
472 textField.setAttribute("id" , ''+key+'');
474 if($scope.firstlayer != null && $scope.secondlayer == null){
475 textField.setAttribute("id" , ''+$scope.firstlayer+'.'+key+'');
477 if($scope.firstlayer != null && $scope.secondlayer != null){
478 textField.setAttribute("id" , ''+$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'');
480 if(!refattributeLabel.startsWith('div.')){
481 refattributeLabel = 'div.'+refattributeLabel+"@0";
483 document.getElementById(refattributeLabel).appendChild(label);
484 document.getElementById(refattributeLabel).appendChild(textField);
485 document.getElementById(refattributeLabel).appendChild(br);
487 if($scope.secondlayer == null){
488 plainAttributeKeys.push($scope.firstlayer+'.'+key+'*'+subattributeManyKey);
489 if($scope.temp.policy.ruleData != null){
490 if(document.getElementById($scope.firstlayer+'.'+key) != null){
491 document.getElementById($scope.firstlayer+'.'+key).value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+key];
493 document.getElementById($scope.firstlayer+'.'+key+'@0').value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+key+'@0'];
496 var newValue = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+key+'@'+i];
500 $scope.addNewChoice($scope.firstlayer+'.'+key);
501 document.getElementById($scope.firstlayer+'.'+key+'@'+i).value = newValue;
509 plainAttributeKeys.push($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'*'+subattributeManyKey);
510 if($scope.temp.policy.ruleData != null){
511 if(document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key) != null){
512 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key).value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key];
514 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0').value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0'];
517 var newValue = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@'+i];
521 $scope.addNewChoice($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key);
522 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@'+i).value = newValue;
531 //Add Recursive Function
532 var saveResultValue = resultValue;
533 var subAttributeJSON = JSON.parse(subAttributes);
534 var recursiveKey = splitSubAttribute[0].trim();
535 var resultValue = subAttributeJSON[recursiveKey];
536 var recursiveMany = splitSubAttribute[1];
537 var br = document.createElement("BR");
538 var label = document.createElement("Label");
539 var labeltext = document.createTextNode(key);
540 label.appendChild(labeltext);
542 if(recursiveMany == 'MANY-true'){
543 var addButton = document.createElement("BUTTON");
544 var buttonLabel = document.createTextNode("+");
545 addButton.appendChild(buttonLabel);
546 addButton.setAttribute("class", "btn btn-default");
547 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
548 var removeButton = document.createElement("BUTTON");
549 var buttonremoveLabel = document.createTextNode("-");
550 removeButton.appendChild(buttonremoveLabel);
551 removeButton.setAttribute("class", "btn btn-default");
552 addButton.setAttribute("ng-click" , 'addNewChoice("'+$scope.firstlayer+'.'+key+'");');
553 removeButton.setAttribute("ng-click" , 'removeChoice("'+$scope.firstlayer+'.'+key+'");');
554 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
555 var idf = "div."+$scope.firstlayer;
556 document.getElementById(idf).appendChild(addButton);
557 document.getElementById(idf).appendChild(removeButton);
558 document.getElementById(idf).appendChild(label);
559 document.getElementById(idf).appendChild(br);
560 var id = "div."+$scope.firstlayer+'.'+key;
561 var divTag = document.createElement("div");
562 divTag.setAttribute("id",id);
563 document.getElementById("div."+$scope.firstlayer).appendChild(divTag);
564 $scope.secondlayer = key;
565 var idc = "div."+$scope.firstlayer+key+'@0';
566 var divTag = document.createElement("div");
567 divTag.setAttribute("id", idc);
568 document.getElementById(id).appendChild(divTag);
569 $scope.subAttributeLayout(resultValue, subAttributes, idc);
570 document.getElementById(id).appendChild(br);
572 var id = "div."+$scope.firstlayer+'.'+key;
573 var divTag = document.createElement("div");
574 divTag.setAttribute("id",id);
575 document.getElementById("div."+$scope.firstlayer).appendChild(divTag);
576 document.getElementById(id).appendChild(br);
577 document.getElementById(id).appendChild(label);
578 document.getElementById(id).appendChild(br);
579 $scope.secondlayer = key;
580 $scope.subAttributeLayout(resultValue, subAttributes, id);
582 resultValue = saveResultValue;
583 //$scope.secondlayer == null;
584 if($scope.secondlayer == null){
585 plainAttributeKeys.push($scope.firstlayer+'.'+key+'*'+recursiveMany);
586 if($scope.temp.policy.ruleData != null){
587 if(document.getElementById($scope.firstlayer+'.'+key) != null){
588 document.getElementById($scope.firstlayer+'.'+key).value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+key];
590 document.getElementById($scope.firstlayer+'.'+key+'@0').value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+key+'@0'];
594 plainAttributeKeys.push($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'*'+recursiveMany);
595 if($scope.temp.policy.ruleData != null){
596 if(document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key) != null){
597 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key).value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key];
599 if(document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0') != null){
600 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0').value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0'];
601 }else if(document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key) != null){
602 document.getElementById($scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key).value = $scope.temp.policy.ruleData[$scope.firstlayer+'.'+$scope.secondlayer+'@0.'+key+'@0'];
611 $scope.savePolicy = function(policy){
615 if(plainAttributeKeys != null){
616 for(a = 0; a < plainAttributeKeys.length; a++){
617 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
618 console.log(splitPlainAttributeKey[1]);
619 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
620 var key = splitPlainAttributeKey[0];
621 if(searchElement == null){
622 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
623 key = splitPlainAttributeKey[0]+'@0';
625 if(searchElement != null){
626 if(searchElement.value != null){
627 jsonPolicy[key]= searchElement.value;
632 var uuu = "policyController/save_DCAEMSPolicy.htm";
633 var postData={policyData: policy, policyJSON : jsonPolicy};
638 contentType: 'application/json',
639 data: JSON.stringify(postData),
640 success : function(data){
641 $scope.$apply(function(){
642 $scope.data=data.data;
643 $scope.temp.policy.readOnly = 'true';
644 Notification.success("Policy Saved Successfully.");
646 console.log($scope.data);
647 $modalInstance.close();
650 error : function(data){
651 Notification.error("Error Occured while saving Policy.");
656 $scope.validatePolicy = function(policy){
657 var uuu = "policyController/validate_policy.htm";
658 var postData={policyData: policy};
663 contentType: 'application/json',
664 data: JSON.stringify(postData),
665 success : function(data){
666 $scope.$apply(function(){
667 $scope.data=data.data.substring(1,8);
668 var size = data.data.length;
669 if($scope.data == 'success'){
670 Notification.success("Validation Success.");
672 var displayWarning = data.data.substring(19,size);
673 window.alert(displayWarning);
676 Notification.error("Validation Failed.");
680 console.log($scope.data);
682 error : function(data){
683 Notification.error("Validation Failed.");
688 function extend(obj, src) {
689 for (var key in src) {
690 if (src.hasOwnProperty(key)) obj[key] = src[key];