2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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=========================================================
21 angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
24 $scope.policyNavigator;
25 $scope.isCheck = false;
26 $scope.savebutton = true;
27 $scope.refreshCheck = false;
31 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
32 $scope.temp.policy = {
33 policyType : "Config",
34 configPolicyType : "Micro Service"
38 $scope.refresh = function(){
39 if($scope.refreshCheck){
40 $scope.policyNavigator.refresh();
42 $scope.modal('createNewPolicy', true);
43 $scope.temp.policy = "";
46 $scope.modal = function(id, hide) {
47 return $('#' + id).modal(hide ? 'hide' : 'show');
50 $('#ttlDate').datepicker({
51 dateFormat: 'dd/mm/yy',
54 onSelect: function(date) {
55 angular.element($('#ttlDate')).triggerHandler('input');
59 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
60 if ($scope.temp.policy.configName == undefined){
61 $scope.isCheck = false;
63 $scope.isCheck = true;
66 $scope.isCheck = false;
69 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
74 console.log($scope.onapNameDictionaryDatas);
76 console.log("failed");
79 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
84 console.log($scope.priorityDatas);
86 console.log("failed");
89 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
94 console.log($scope.groupPolicyScopeListDatas);
96 console.log("failed");
99 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
101 $scope.data = JSON.parse(j.data);
102 console.log($scope.data);
103 console.log("$scope.data.microServiceConfigNameDictionaryDatas : " + $scope.data.microServiceConfigNameDictionaryDatas);
104 if($scope.data.microServiceConfigNameDictionaryDatas){
105 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceConfigNameDictionaryDatas);
107 console.log($scope.microServiceCongigNameDictionaryDatas);
108 }, function (error) {
109 console.log("failed");
112 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
114 $scope.data = JSON.parse(j.data);
115 console.log($scope.data);
116 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
117 console.log($scope.microServiceLocationDictionaryDatas);
118 }, function (error) {
119 console.log("failed");
122 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
124 $scope.data = JSON.parse(j.data);
125 console.log($scope.data);
126 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
129 for(var i = 0; i < inputModelList.length; i++){
130 if(typeof unique[inputModelList[i]] == "undefined"){
131 unique[inputModelList[i]] = "";
132 uniqueList.push(inputModelList[i]);
135 $scope.microServiceModelsDictionaryDatas = uniqueList;
136 console.log($scope.microServiceModelsDictionaryDatas);
137 }, function (error) {
138 console.log("failed");
141 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
143 $scope.data = JSON.parse(j.data);
144 console.log($scope.data);
145 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
146 console.log($scope.dcaeUUIDDictionaryDatas);
147 }, function (error) {
148 console.log("failed");
151 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
153 $scope.data = JSON.parse(j.data);
154 console.log($scope.data);
155 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
156 console.log($scope.riskTypeDictionaryDatas);
157 }, function (error) {
158 console.log("failed");
161 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
163 $scope.data = JSON.parse(j.data);
164 console.log($scope.data);
165 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
166 console.log($scope.microServiceAttributeDictionaryDatas);
167 }, function (error) {
168 console.log("failed");
173 $scope.attributeDatas = [{"attributes" : $scope.choices}];
174 addNewChoice = function(value) {
175 console.log("input key : " + value);
176 var isFoundInRuleData = false;
177 if(value != undefined){
178 if (value.startsWith('div.')){
179 value = value.replace('div.','');
182 console.log(" document.getElementById : div."+value);
183 var parentElement = document.getElementById("div."+value);
184 console.log("parentElement : " + parentElement);
185 var div = document.getElementById(value+"@0");
187 var clone = div.cloneNode(true);
188 var addElement = parentElement.childElementCount;
189 clone.id = ''+value+'@'+addElement;
191 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ //if it's view or edit
192 if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){ // Only append child if its value found in ruleData or edit mode
193 if($scope.temp.policy.ruleData[clone.id]){
194 clone.value = $scope.temp.policy.ruleData[clone.id];
195 isFoundInRuleData = true;
197 console.log(" clone.value :" + clone.value);
198 console.log(" clone.id :" + clone.id);
199 if(!isFoundInRuleData && isInitViewEdit){
202 if(!clone.className.includes("child_single")){
203 clone.className += ' child_single'; //here cloned is single element
205 document.getElementById("div."+value).appendChild(clone);
206 plainAttributeKeys.push(''+value+'@'+addElement);
208 }else{ //not view or edit
209 if(!clone.className.includes("child_single")){
210 clone.className += ' child_single'; //here cloned is single element
212 document.getElementById("div."+value).appendChild(clone);
213 plainAttributeKeys.push(''+value+'@'+addElement);
217 if(parentElement == null){
220 div = document.getElementById("div."+value+"@0");
223 if(!div.className.includes('children_group border')){
228 div.className += ' children_group border' + layer; //here is div with a group of children.
231 var childElement = parentElement.firstElementChild;
232 var countParent = parentElement.childElementCount;
233 var childElementString = childElement.innerHTML;
234 var find = value+"@0";
235 var re = new RegExp(find, 'g');
236 childElementString = childElementString.replace(re,value+'@' + countParent);
237 var clone = childElement.cloneNode(true);
238 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
239 var childId = parentElement.childNodes[ii].id;
240 if(ii = parentElement.childNodes.length){
241 var childnewId = childId.slice(0, -1);
242 var count = childId.slice(-1);
245 var countvalue = parseInt(count) + 1;
246 clone.id = childnewId+countvalue;
248 clone.innerHTML=childElementString;
249 document.getElementById("div."+value).appendChild(clone);
250 var selects = clone.getElementsByTagName("select");
251 var inputs = clone.getElementsByTagName("input");
252 var removeValues = [];
253 for(var i=0; i<inputs.length; i++){
254 if ($scope.temp.policy.ruleData!=undefined){
255 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
256 console.log(" checkValue.value :" + checkValue);
257 console.log(" inputs["+i+"].id :" + inputs[i].id);
258 if (checkValue!=undefined && checkValue != "undefined"){
259 document.getElementById(inputs[i].id).value = checkValue;
260 plainAttributeKeys.push(inputs[i].id);
262 plainAttributeKeys.push(inputs[i].id);
265 plainAttributeKeys.push(inputs[i].id);
269 for(var i=0; i<selects.length; i++){
270 if ($scope.temp.policy.ruleData!=undefined){
271 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
272 if (checkValue!=undefined && checkValue!="undefined"){
273 if($scope.temp.policy.ruleData != null){
274 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
275 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
276 plainAttributeKeys.push(selects[i].id);
279 plainAttributeKeys.push(selects[i].id);
282 plainAttributeKeys.push(selects[i].id);
286 for (var k=0; k<removeValues.length; k++){
287 var elem = document.getElementById(removeValues[k]);
288 elem.parentNode.removeChild(elem);
290 var ele = angular.element(document.getElementById("div."+value));
291 $compile(ele.contents())($scope)
297 removeChoice = function(value) {
299 if(value != undefined){
300 var c = document.getElementById("div."+value).childElementCount;
303 Notification.error("The original one is not removable.");
306 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
310 function findVal(object, key) {
312 Object.keys(object).some(function(k) {
317 if (object[k] && typeof object[k] === 'object') {
318 value = findVal(object[k], key);
319 return value !== undefined;
325 $scope.pullVersion = function(serviceName) {
326 console.log(serviceName);
327 if(serviceName != undefined){
328 var uuu = "policyController/getModelServiceVersioneData.htm";
329 var postData={policyData: serviceName};
334 contentType: 'application/json',
335 data: JSON.stringify(postData),
336 success : function(data){
337 $scope.$apply(function(){
338 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
341 error : function(data){
342 alert("Error While Retriving the Template Layout Pattren.");
349 var splitEqual = '=';
350 var splitComma = ',';
351 var splitcolon = ':';
352 var splitsemicolon = ";";
353 var splitEnum = "],";
354 var plainAttributeKeys = [];
356 var enumKeyList = [];
357 var dictionaryList = [];
358 var dictionaryNameList = [];
359 var isInitViewEdit = false;
360 $scope.addDataToFields = function(serviceName, version){
361 if(serviceName != null && version !=null){
362 var service=serviceName+"-v"+version;
363 var myNode = document.getElementById("DynamicTemplate");
364 myNode.innerHTML = '';
365 var uuu = "policyController/getDCAEMSTemplateData.htm";
366 var postData={policyData: service};
368 console.log("service: " +service);
370 var dataOrderInfo = "";
372 booleanTrueElements = [];
374 document.getElementById("msPolicyloader").style.visibility = "visible";
380 contentType: 'application/json',
381 data: JSON.stringify(postData),
382 success : function(data){
384 document.getElementById("msPolicyloader").style.visibility = "hidden";
386 $scope.$apply(function(){
387 var plainAttributeKeys = [];
388 $scope.dcaeModelData = data[0].dcaeModelData;
389 $scope.dcaeJsonDate = data[0].jsonValue;
390 $scope.dataOrderInfo = null;
391 $scope.dataOrderInfo = data[0].dataOrderInfo;
392 console.log("data[0].dataOrderInfo: " + data[0].dataOrderInfo);
393 console.log("$scope.dataOrderInfo: " + $scope.dataOrderInfo);
395 if(data[0].allManyTrueKeys){
396 console.log("$scope.allManyTrueKeys: " + $scope.allManyTrueKeys);
398 console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
399 var attributes = $scope.dcaeModelData.attributes;
400 console.log("attributes: " +attributes);
401 var refAttributes = $scope.dcaeModelData.ref_attributes;
402 var subAttributes = $scope.dcaeModelData.sub_attributes;
403 console.log("subAttributes: " + subAttributes);
404 console.log("refAttributes: " + refAttributes);
405 var headDefautlsData = data[0].headDefautlsData;
406 if(headDefautlsData != null){
407 $scope.temp.policy.onapName = headDefautlsData.onapName;
408 $scope.temp.policy.guard = headDefautlsData.guard;
409 $scope.temp.policy.riskType = headDefautlsData.riskType;
410 $scope.temp.policy.riskLevel = headDefautlsData.riskLevel;
411 $scope.temp.policy.priority = headDefautlsData.priority;
414 var enumAttributes = $scope.dcaeModelData.enumValues;
415 var annotation = $scope.dcaeModelData.annotation;
416 var dictionary = $scope.microServiceAttributeDictionaryDatas;
418 if (annotation == null || annotation.length<1){
419 $scope.isCheck = true;
421 $scope.isCheck = false;
422 var annoationList = annotation.split(splitComma);
423 for (k = 0; k < annoationList.length; k++){
424 var splitAnnotation = annoationList[k].split(splitEqual);
425 if (splitAnnotation[1].includes("matching-true")){
426 matching.push(splitAnnotation[0].trim());
432 if (dictionary!= null && dictionary.length>1){
433 for (m=0; m < dictionary.length; m += 1){
434 var keyCompare = dictionary[m].name;
435 var valueCompare = dictionary[m].value;
436 var valueModel = dictionary[m].modelName;
437 var conpairService = serviceName;
438 if (valueModel.includes('-v')){
439 conpairService = service;
441 if(valueModel.localeCompare(conpairService) == 0){
442 console.log(valueCompare);
443 dictionaryList.push(dictionary[m]);
444 if (!dictionaryNameList.includes(dictionary[m].name)){
445 dictionaryNameList.push(dictionary[m].name)
451 $scope.temp.policy.ruleGridData = [];
453 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
454 dataOrderInfo = $scope.dataOrderInfo;
457 $scope.jsonLayout($scope.dcaeJsonDate);
461 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ // If it's veiw or edit
462 isInitViewEdit = true;
465 // If ruleData contains extra elements created by clicked add button
466 console.log("$scope.temp.policy.ruleData:" + $scope.temp.policy.ruleData);
467 if($scope.temp.policy.ruleData != null){
468 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
469 propNames.forEach(function(name) {
473 var extraElements = data;
475 if(plainAttributeKeys != null){
476 for(var b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
477 var newValue = plainAttributeKeys[b].split("*");
478 for(var a = 0; a < data.length; a++){
479 if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
480 extraElements.splice(a, 1);
485 //--- Populate these extra elements created by clicked add button
486 for(var a = 0; a < extraElements.length; a++){
487 if(extraElements[a].includes("@")){
488 var index = extraElements[a].lastIndexOf("@");
490 // Get the number after @
491 var n = getNumOfDigits(extraElements[a], index+1);
493 var key = extraElements[a].substring(0, index+n+1); //include @x in key also by n+2 since x can be 1,12, etc
494 console.log("key: " + key);
499 var unique = checkData.filter(onlyUnique);
500 var parentLevelElements = [];
502 //--- get all root level exta elments first (only contains one "@")
503 for(var i =0; i < unique.length; i++){
504 var firstIndex = unique[i].indexOf("@");
505 var lastIndex = unique[i].lastIndexOf("@");
506 if(firstIndex == lastIndex){
507 var newKey = unique[i].substring(0, firstIndex);
508 console.log("root element: " + newKey);
509 parentLevelElements.push(newKey);
510 unique[i] = "*processed*";
516 for (var i = 0; i < $scope.labelManyKeys.length; i++) {
517 var label = $scope.labelManyKeys[i];
518 if(parentLevelElements){
519 for (var k = 0; k < parentLevelElements.length; k++){
520 if(label == parentLevelElements[k]){
527 //if no layout order info, keep the process as before
529 for(var i =0; i < unique.length; i++){
530 if(unique[i] != "*processed*"){
531 var index = unique[i].lastIndexOf("@");
532 var newKey = unique[i].substring(0, index);
533 console.log("newKey: " + newKey);
535 var newElement = document.getElementById("div."+unique[j]);
536 //check weather it has been created already
537 if(newElement != null){
540 newElement = document.getElementById(unique[j]);
541 if(newElement != null){
547 addNewChoice(newKey);
552 //---reset to default
554 $scope.labelManyKeys = [];
556 //---process none labels
557 for (var j = 0; j < unique.length; j++){
558 if(unique[j] != "*processed*"){
559 // if not created yet
560 if(!document.getElementById(unique[j])){
561 var index = unique[j].lastIndexOf("@");
562 var newKey = unique[j].substring(0, index);
564 var newElement = document.getElementById("div."+unique[j]);
566 //check weather it has been created already
567 if(newElement != null){
570 newElement = document.getElementById(unique[j]);
571 if(newElement != null){
575 //if not created yet, then create it.
576 addNewChoice(newKey);
586 var ele = angular.element(document.getElementById("DynamicTemplate"));
587 $compile(ele.contents())($scope);
589 isInitViewEdit = false;
592 error : function(data){
593 alert("Error While Retriving the Template Layout Pattren.");
600 function getNumOfDigits(str_value, index){
601 // Get the number after @
602 var str = str_value.substring(index, str_value.length);
605 for (var x = 0; x < str.length; x++){
616 function getDictionary(attribute){
617 var dicName = attribute;
619 if(attribute.includes(":")){
620 dicName = attribute.split(":")[0];
623 var dictionaryRegExp = new RegExp(dicName);
624 listemunerateValues = [];
625 if (dictionaryRegExp.test(dictionaryNameList)) {
626 for (p=0; p < dictionaryList.length; p += 1) {
627 if (dicName == dictionaryList[p].name) {
628 listemunerateValues.push(dictionaryList[p].value);
632 return listemunerateValues;
635 function getList(attribute) {
636 var enumName = attribute;
637 console.log("In getList: attribute => " + attribute);
639 if(attribute.includes(":")){
640 enumName = attribute.split(":")[0];
643 var baseEnum = $scope.dcaeModelData.enumValues;
645 if(baseEnum != null){
646 enumList = baseEnum.split(splitEnum);
649 var patternTest = new RegExp(enumName);
650 for (k=0; k < enumList.length; k += 1){
651 if(patternTest.test(enumList[k]) == true){
652 enumAttributes = enumList[k].trim();
657 enumAttributes = enumAttributes.replace("[", "");
658 enumAttributes = enumAttributes.replace("]", "");
659 enumAttributes = enumAttributes.replace(/ /g, '');
660 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
661 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
662 //enumKeyList.push(attribute);
663 return listemunerateValues;
669 function getBooleanList(){
670 var booleanList = [];
671 booleanList.push(true);
672 booleanList.push(false);
677 function isArray(arrayTest) {
678 return Object.prototype.toString.call(arrayTest) === '[object Array]';
682 $scope.layOutElementList = [];
683 $scope.layOutOnlyLableList = [];
685 var elementOrderNum = 0;
687 function deconstructJSON(layOutData, level , name) {
691 var stringValue = "java.lang.String";
692 var string = "string";
693 var intValue = "int";
694 var integerValue = "integer";
695 var double = "double";
696 var boolean = "boolean";
697 var baseLevel = level;
699 var String = "String";
701 var attributekey = "";
703 if (name.length > 1){
704 label = label + name + '.';
707 for (key in layOutData) {
708 array = isArray(layOutData[key]);
709 console.log("key: " + key , "value: " + layOutData[key]);
711 if (!!layOutData[key] && typeof(layOutData[key])=="object") {
713 if (array==false && key!=="0"){
715 if($scope.dataOrderInfo){
716 var labelObject = {"label" : key, "level" : label, "array" : array};
717 //save it to the list
718 $scope.layOutOnlyLableList.push(labelObject);
722 $scope.labelLayout(label, key, array );
727 if (array == true && key!=0){
731 if (lableList.length > 0){
735 var newKey = lableList.pop();
737 if($scope.dataOrderInfo){
739 var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
740 //save it to the list
741 $scope.layOutOnlyLableList.push(labelObject);
745 $scope.labelLayout(baseLevel, newKey, array );
749 label = baseLevel + newKey + '@0.';
751 label = baseLevel + newKey + '.';
754 deconstructJSON(layOutData[key] , label, key);
756 var attirbuteLabel = label;
759 var isRequired = false;
760 if (layOutData[key].includes('defaultValue-')){
761 defaultValue = layOutData[key].split('defaultValue-')[1];
764 if (layOutData[key].includes('description-')){
765 description = layOutData[key].split('description-')[1];
771 attributekey = lableList.pop();
772 attirbuteLabel = baseLevel;
774 attributekey = key.split();
777 if (layOutData[key].includes('required-true')){
781 var subAttributes = $scope.dcaeModelData.sub_attributes;
784 var jsonObject = JSON.parse(subAttributes);
786 var lablInfo = findVal(jsonObject, attributekey);
787 console.log("deconstructJSON:findValue : " + attributekey +": "+ lablInfo);
789 if(lablInfo.includes('required-true')){
792 if(lablInfo.includes('defaultValue-')){
793 defaultValue = lablInfo.split('defaultValue-')[1];
796 if(lablInfo.includes('description-')){
797 description = lablInfo.split('description-')[1];
801 var allkeys = Object.keys(jsonObject);
803 for (var k = 0; k < allkeys.length; k++) {
804 var keyValue = allkeys[k];
805 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
806 if(jsonObject[keyValue]){
807 var tempObject = jsonObject[keyValue];
808 if(tempObject && tempObject[key]){
809 if (tempObject[key].includes('required-true')){
813 if(tempObject[key].includes('defaultValue-')){
814 defaultValue = tempObject[key].split('defaultValue-')[1];
817 if(tempObject[key].includes('description-')){
818 description = tempObject[key].split('description-')[1];
828 var elementObject = {};
829 switch (layOutData[key].split(splitcolon)[0]){
833 if($scope.dataOrderInfo){
835 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text", "description":description};
836 $scope.layOutElementList.push(elementObject);
838 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
843 if($scope.dataOrderInfo){
845 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number" , "description":description};
846 $scope.layOutElementList.push(elementObject);
848 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
852 if($scope.dataOrderInfo){
854 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double", "description":description};
855 $scope.layOutElementList.push(elementObject);
857 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
861 if($scope.dataOrderInfo){
863 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"boolean", "description":description};
864 $scope.layOutElementList.push(elementObject);
866 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
870 if (layOutData[key].includes('dictionary-')){
871 var list = getDictionary(layOutData[key].split('dictionary-')[1]);
873 //--- get dropdown values from enumValues
874 var list = getList(layOutData[key]);
876 if (list.length===0){ //not dropdown element
877 if($scope.dataOrderInfo){
879 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description};
880 $scope.layOutElementList.push(elementObject);
883 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
886 if($scope.dataOrderInfo){
888 elementObject = {"id": elementOrderNum, "attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "list":list, "type":"dropBox", "description":description};
889 $scope.layOutElementList.push(elementObject);
891 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
901 $scope.validContionalRequired = function(parentId) {
902 console.log("ng-blur event: parentId : " + parentId);
903 var c = document.getElementById(parentId).children;
905 var hasValue = false;
906 for (i = 0; i < c.length; i++) {
907 if(c[i].getAttribute("data-conditional")){
908 console.log(c[i].getAttribute("data-conditional"));
909 console.log(c[i].value);
910 if(c[i].value != null && c[i].value.trim() != ""){
916 for (i = 0; i < c.length; i++) {
917 if(c[i].getAttribute("data-conditional")){
919 c[i].setAttribute("required", true);
921 c[i].removeAttribute("required");
927 $scope.jsonLayout = function(layOutData){
929 deconstructJSON(layOutData , "", "");
931 var orderValue = $scope.dataOrderInfo;
932 var layOutElementList = $scope.layOutElementList;
933 var labelList = $scope.layOutOnlyLableList;
937 $scope.layOutElementList = [];
938 $scope.layOutOnlyLableList = [];
940 // Only layout in order if order info provided
943 if(orderValue.includes("[")){
944 orderValue = orderValue.replace("[", "") ;
945 orderValue = orderValue.replace("]", "") ;
948 orderValue = orderValue.split(',') ;
950 for (var i = 0; i < orderValue.length; i++) {
951 console.log("orderValue["+i+"]"+ orderValue[i]);
952 var key = orderValue[i].trim();
954 //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
956 for (var k = 0; k < labelList.length; k++){
958 var label = labelList[k].label.toString().trim();
959 var level = labelList[k].level.toString().trim();
960 var array = labelList[k].array;
963 $scope.labelLayout(level, label, array);
964 //in case to have duplicate label names
965 labelList[k].label = "*processed*";
970 //--- then layout each element based on its order defined in YAML file
971 for (var j = 0; j < layOutElementList.length; j++) {
973 var attributekey = layOutElementList[j].attributekey.toString().trim();
975 if(key == attributekey){
977 var attirbuteLabel = layOutElementList[j].attirbuteLabel.toString().trim();
978 var defaultValue = layOutElementList[j].defaultValue.toString().trim();
979 var description = layOutElementList[j].description;
980 var isRequired = layOutElementList[j].isRequired;
982 console.log("layOutElementList[" +j+ "]: id:" + layOutElementList[j].id + ", attributekey:"+ layOutElementList[j].attributekey + ", attirbuteLabel:" + layOutElementList[j].attirbuteLabel);
983 console.log("layOutElementList[" +j+ "]: type:" + layOutElementList[j].type);
984 if (layOutElementList[j].type == "dropBox"){
985 $scope.dropBoxLayout(attirbuteLabel, attributekey, layOutElementList[j].array, defaultValue, layOutElementList[j].list, isRequired, description);
988 $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type, description);
992 //in case to have duplicate attribute names
993 layOutElementList[j].attributekey = "*processed*";
1002 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType, description){
1003 $scope.temp.policy.ruleGridData.push(attibuteKey);
1004 var br = document.createElement("BR");
1006 var label = document.createElement("Label");
1007 var labeltext = null;
1008 var requiredLabName = "";
1009 if (matching.includes(attibuteKey)){
1010 labeltext = document.createTextNode(attibuteKey + "*!");
1011 isRequired = true; //set required as true for matching element
1014 requiredLabName = attibuteKey + " * ";
1015 labeltext = document.createTextNode(requiredLabName);
1017 labeltext = document.createTextNode(attibuteKey);
1022 var divID = labelValue;
1024 if (labelValue.length < 1){
1025 divID = "DynamicTemplate";
1026 }else if (labelValue.endsWith('.')){
1027 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1030 label.appendChild(labeltext);
1032 var textField = document.createElement("INPUT");
1034 textField.setAttribute("class" , "form-control");
1036 if(dataType == "double"){
1037 textField.setAttribute("type" , "number");
1038 textField.setAttribute("step" , "any");
1040 }else if(dataType == "boolean"){ //gw1218 testing boolean
1041 var booleanDiv = document.createElement("div");
1043 booleanDiv.setAttribute("class" , "onoffswitch");
1045 //var checkField = document.createElement("INPUT");
1046 textField.setAttribute("type" , "checkbox");
1047 textField.setAttribute("name" , "onoffswitch");
1048 textField.setAttribute("class" , "onoffswitch-checkbox");
1049 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1050 if(defaultValue && defaultValue == "true") {
1051 textField.setAttribute("checked" , "true");
1053 textField.setAttribute("checked" , "false");
1056 var booleanlabel = document.createElement("Label");
1057 booleanlabel.setAttribute("class" , "onoffswitch-label");
1058 booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+'');
1060 var span1 = document.createElement("span");
1061 span1.setAttribute("class" , "onoffswitch-inner");
1063 var span2 = document.createElement("span");
1064 span2.setAttribute("class" , "onoffswitch-switch");
1067 booleanlabel.appendChild(span1);
1068 booleanlabel.appendChild(span2);
1069 booleanDiv.appendChild(textField);
1070 booleanDiv.appendChild(booleanlabel);
1072 document.getElementById(divID).appendChild(label);
1073 document.getElementById(divID).appendChild(booleanDiv);
1077 textField.setAttribute("type" , dataType);
1084 if(dataType != "boolean"){
1085 textField.setAttribute("style" , "width:300px;");
1086 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1087 if(description && description != "null"){
1088 textField.setAttribute("title", description);
1094 if(attributeManyKey){
1095 checkKey = labelValue + attibuteKey+'@0';
1096 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
1097 var divTag = document.createElement("div");
1098 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
1099 var addButton = document.createElement("BUTTON");
1100 var buttonaddLabel = document.createTextNode("+");
1101 addButton.appendChild(buttonaddLabel);
1102 addButton.setAttribute("id", labelValue + attibuteKey);
1103 addButton.setAttribute("class", "btn btn-add-remove");
1104 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + attibuteKey+'");');
1105 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1106 var removeButton = document.createElement("BUTTON");
1107 var buttonremoveLabel = document.createTextNode("-");
1108 removeButton.appendChild(buttonremoveLabel);
1109 removeButton.setAttribute("class", "btn btn-add-remove");
1110 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue + attibuteKey+'");');
1111 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1112 document.getElementById(divID).appendChild(addButton);
1113 document.getElementById(divID).appendChild(removeButton);
1114 document.getElementById(divID).appendChild(label);
1115 id = "div."+labelValue+attibuteKey;
1116 //var divTag = document.createElement("div");
1117 divTag.setAttribute("id", id);
1118 document.getElementById(divID).appendChild(divTag);
1119 textField.className += ' first_child';
1121 textField.setAttribute("required", "true");
1124 divTag.appendChild(textField);
1125 document.getElementById(divID).appendChild(divTag);
1127 }else if (dataType != "boolean"){
1128 checkKey = labelValue + attibuteKey;
1129 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1130 if(document.getElementById(divID).hasAttribute('required') || !document.getElementById(divID).hasAttribute('data-conditional')){
1131 if(requiredLabName.includes("*") || isRequired){
1132 textField.setAttribute("required", "true");
1134 }else if (document.getElementById(divID).hasAttribute('data-conditional')){
1135 if(requiredLabName.includes("*")){
1136 var requiredNode = document.createElement('span');
1137 requiredNode.setAttribute("class", "mstooltip");
1138 requiredNode.textContent = "?";
1139 label.appendChild(requiredNode);
1141 var requiredNodeToolTip = document.createElement('span');
1142 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1143 requiredNodeToolTip.textContent = "Conditional Required";
1144 requiredNode.appendChild(requiredNodeToolTip);
1146 textField.setAttribute("data-conditional", divID);
1147 textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1151 document.getElementById(divID).appendChild(label);
1152 document.getElementById(divID).appendChild(textField);
1153 document.getElementById(divID).appendChild(br);
1157 if(dataType != "boolean" && divID.includes("@0") && divID.includes("div.")){
1158 var firstChild_Id = divID.split("@0")[0];
1159 var firstChild_element = document.getElementById(firstChild_Id);
1160 if(firstChild_element){
1162 if(!firstChild_element.className.includes('children_group border')){
1167 firstChild_element.className += ' children_group border' + layer; //here is div with a group of children.
1171 console.log('firstChild_Id: ' + firstChild_Id);
1172 console.log('divID: ' + divID);
1174 if(dataType != "boolean" && defaultValue.length > 0){
1175 if(defaultValue.includes(":")){
1176 defaultValue = defaultValue.split(":")[0];
1177 if(defaultValue === "NA") {
1181 if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
1182 document.getElementById(checkKey).value = defaultValue;
1186 if($scope.temp.policy.ruleData != null){
1187 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1188 if (attributeManyKey){
1189 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
1190 if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){
1191 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
1194 if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
1195 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1200 if (dataType != "boolean"){
1201 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
1203 plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean");
1207 $scope.labelManyKeys = [];
1208 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
1209 var label = document.createElement("Label")
1210 var divID = labelValue;
1211 if (labelValue.endsWith('.')){
1212 var workingLabel = labelValue.substring(0, labelValue.length-1);
1214 var workingLabel = labelValue;
1217 if (labelValue.length < 1){
1218 divID = "DynamicTemplate";
1219 } else if (labelValue.endsWith('.')){
1220 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1223 var subAttributes = $scope.dcaeModelData.sub_attributes;
1224 var jsonObject = JSON.parse(subAttributes);
1225 var lablInfo = findVal(jsonObject, lableName);
1226 console.log("findValue : " + lableName +": "+ lablInfo);
1228 var required = null;
1230 if(typeof lablInfo === 'string' ){
1231 if(lablInfo.includes("required-true")){
1234 }else if (lablInfo.includes("required-false")){
1240 var labeltext = document.createTextNode(lableName + star);
1242 label.appendChild(labeltext);
1246 var addButton = document.createElement("BUTTON");
1247 var buttonLabel = document.createTextNode("+");
1248 addButton.appendChild(buttonLabel);
1249 addButton.setAttribute("class", "btn btn-add-remove");
1250 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + lableName+'");');
1251 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1252 var removeButton = document.createElement("BUTTON");
1253 var buttonremoveLabel = document.createTextNode("-");
1254 removeButton.appendChild(buttonremoveLabel);
1255 removeButton.setAttribute("class", "btn btn-add-remove");
1256 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue +lableName+'");');
1257 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1258 document.getElementById(divID).appendChild(addButton);
1259 document.getElementById(divID).appendChild(removeButton);
1260 document.getElementById(divID).appendChild(label);
1261 var id = "div."+labelValue+lableName;
1262 var divTag = document.createElement("div");
1263 divTag.setAttribute("id", id);
1264 document.getElementById(divID).appendChild(divTag);
1266 var divTag = document.createElement("div");
1267 divTag.setAttribute("id", id +'@0');
1269 if(!divTag.className.includes('children_group border')){
1274 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1277 divTag.setAttribute("required", required);
1278 }else if(required == false){
1279 divTag.setAttribute("data-conditional", "yes");
1282 document.getElementById(id).appendChild(divTag);
1284 $scope.labelManyKeys.push(lableName);
1287 var divTag = document.createElement("div");
1288 divTag.setAttribute("id", "div."+labelValue+lableName);
1290 if(!divTag.className.includes('children_group border')){
1295 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1298 divTag.setAttribute("required", required);
1299 }else if(required == false){
1300 divTag.setAttribute("data-conditional", "yes");
1302 document.getElementById(divID).appendChild(label);
1303 document.getElementById(divID).appendChild(divTag);
1307 $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){
1308 var br = document.createElement("BR");
1310 if (labelLevel.length < 1){
1311 var divID = "DynamicTemplate";
1312 } else if (labelLevel.endsWith('.')){
1313 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1317 var label = document.createElement("Label")
1319 var refAttributes = $scope.dcaeModelData.ref_attributes;
1320 if(isRequired != true && refAttributes){ //check refAttributes also
1321 var refAttributesList = refAttributes.split(splitComma);
1322 for (k = 0; k < refAttributesList.length; k++){
1323 var refAttribute = refAttributesList[k].split(splitEqual);
1324 if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
1330 if (matching.includes(attributeName)){
1331 var labeltext = document.createTextNode(attributeName + "*!");
1332 label.appendChild(labeltext);
1333 isRequired = true; //set required as true for matching element
1335 var labeltext = document.createTextNode(attributeName);
1337 var requiredLabName = attributeName+ " * ";
1338 labeltext = document.createTextNode(requiredLabName);
1340 labeltext = document.createTextNode(attributeName);
1343 label.appendChild(labeltext);
1345 label.appendChild(labeltext);
1346 // if this field is required, but its parent is not required
1347 if(isRequired && document.getElementById(divID).hasAttribute('data-conditional')){
1348 var requiredNode = document.createElement('span');
1349 requiredNode.setAttribute("class", "mstooltip");
1350 requiredNode.textContent = "?";
1351 label.appendChild(requiredNode);
1353 var requiredNodeToolTip = document.createElement('span');
1354 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1355 requiredNodeToolTip.textContent = "Conditional Required";
1356 requiredNode.appendChild(requiredNodeToolTip);
1360 var listField = document.createElement("SELECT");
1361 listField.setAttribute("class" , "form-control");
1362 listField.setAttribute("style" , "width:300px;");
1363 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1365 if(description && description != "null"){
1366 listField.setAttribute("title", description);
1370 if(document.getElementById(divID).hasAttribute('data-conditional')){
1371 listField.setAttribute("data-conditional", divID);
1372 listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1374 listField.setAttribute("required", true);
1377 if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element
1378 var optionFirst = document.createElement('option');
1379 optionFirst.setAttribute('value', "");
1380 listField.appendChild(optionFirst);
1383 for (i=0; i < listemunerateValues.length; i += 1) {
1384 if(listemunerateValues[i].includes("equal-sign")){
1385 listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','=');
1387 option = document.createElement('option');
1388 option.setAttribute('value', listemunerateValues[i]);
1389 option.appendChild(document.createTextNode(listemunerateValues[i]));
1390 option.setAttribute('value', listemunerateValues[i]);
1391 listField.appendChild(option);
1393 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1395 enumKeyList.push(attributeName);
1397 document.getElementById(divID).appendChild(label);
1398 document.getElementById(divID).appendChild(br);
1401 document.getElementById(divID).appendChild(listField).multiple = true;
1402 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1404 document.getElementById(divID).appendChild(listField).multiple = false;
1405 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1408 if(defaultValue.includes(':')){
1409 defaultValue = defaultValue.split(':')[0];
1411 var location = listemunerateValues.indexOf(defaultValue);
1412 document.getElementById(labelLevel +attributeName).options[location+1].selected = true;
1416 if($scope.temp.policy.ruleData != null){
1418 document.getElementById(labelLevel +attributeName).options[0].selected = false;
1419 for (i=0; i < listemunerateValues.length; i += 1) {
1420 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
1421 if (testValue === undefined){
1422 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
1424 var location = listemunerateValues.indexOf(testValue);
1426 document.getElementById(labelLevel +attributeName).options[location].selected = true;
1430 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1431 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
1437 function onlyUnique(value, index, self) {
1438 return self.indexOf(value) === index;
1442 function checkDictionary(value){
1443 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
1444 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
1450 $scope.savePolicy = function(policy){
1451 if(policy.itemContent != undefined){
1452 $scope.refreshCheck = true;
1453 $scope.policyNavigator = policy.itemContent;
1454 policy.itemContent = "";
1456 $scope.savebutton = false;
1459 var jsonPolicy = {};
1460 if(plainAttributeKeys != null){
1461 for(a = 0; a < plainAttributeKeys.length; a++){
1462 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1463 console.log("splitPlainAttributeKey: " + splitPlainAttributeKey);
1464 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1465 var key = splitPlainAttributeKey[0];
1466 if(searchElement == null){
1467 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1468 key = splitPlainAttributeKey[0]+'@0';
1469 }else if (searchElement.nodeName == 'BUTTON'){
1470 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1471 key = splitPlainAttributeKey[0]+'@0';
1473 if(searchElement != null){
1474 var keySplit = key.split(dot);
1475 var elumentLocation = keySplit.length;
1477 if (elumentLocation > 1){
1478 enumKey = keySplit[keySplit.length - 1];
1480 //check it is undefined or not
1481 if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){
1482 if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){
1483 var multiSlect = [];
1484 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1485 multiSlect.push(searchElement.selectedOptions[i].value);
1487 jsonPolicy[key]= multiSlect;
1489 console.log(" searchElement.value = > " + searchElement.value);
1490 if(splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1] == "boolean"){
1491 jsonPolicy[key]= false;
1492 for(var i=0; i<booleanTrueElements.length; i++){
1493 if(booleanTrueElements[i] == key){
1494 jsonPolicy[key]= true;
1499 jsonPolicy[key]= searchElement.value;
1503 if(searchElement.value != null){
1504 jsonPolicy[key]= searchElement.value;
1505 console.log(" searchElement.value = > " + searchElement.value);
1506 if(splitPlainAttributeKey[1] == "boolean"){
1507 jsonPolicy[key]= false;
1508 for(var i=0; i<booleanTrueElements.length; i++){
1509 if(booleanTrueElements[i] == key){
1510 jsonPolicy[key]= true;
1519 var uuu = "policycreation/save_policy";
1520 var postData={policyData: policy, policyJSON : jsonPolicy};
1525 contentType: 'application/json',
1526 data: JSON.stringify(postData),
1527 success : function(data){
1528 $scope.$apply(function(){
1529 $scope.data=data.policyData;
1530 if($scope.data == 'success'){
1531 $scope.temp.policy.readOnly = 'true';
1532 $scope.safetyChecker = data.policyData.split("#")[2];
1533 if ($scope.safetyChecker!=undefined) {
1534 Notification.success($scope.safetyChecker);
1536 $scope.pushStatus=data.policyData.split("&")[1];
1537 if($scope.pushStatus=="successPush"){
1538 Notification.success("Policy pushed successfully");
1540 Notification.success("Policy Saved Successfully.");
1541 }else if ($scope.data == 'PolicyExists'){
1542 $scope.savebutton = true;
1543 Notification.error("Policy Already Exists with Same Name in Scope.");
1546 console.log($scope.data);
1548 error : function(data){
1549 Notification.error("Error Occured while saving Policy.");
1554 var booleanTrueElements = [];
1555 $scope.validatePolicy = function(policy){
1556 document.getElementById("validate").innerHTML = "";
1559 var jsonPolicy = {};
1560 if(plainAttributeKeys != null){
1561 for(a = 0; a < plainAttributeKeys.length; a++){
1562 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1563 console.log(splitPlainAttributeKey[1]);
1564 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1565 var key = splitPlainAttributeKey[0];
1566 if(searchElement == null){
1567 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1568 key = splitPlainAttributeKey[0]+'@0';
1569 }else if (searchElement.nodeName == 'BUTTON'){
1570 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1571 key = splitPlainAttributeKey[0]+'@0';
1573 if(searchElement != null){
1574 if (enumKeyList.indexOf(key) != -1){
1575 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
1576 var multiSlect = [];
1577 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1578 multiSlect.push(searchElement.selectedOptions[i].value);
1580 jsonPolicy[key]= multiSlect;
1582 jsonPolicy[key]= searchElement.value;
1584 if(searchElement.getAttribute("required")){
1585 if(!searchElement.value){
1590 if(searchElement.value != null){
1591 jsonPolicy[key]= searchElement.value;
1592 if(searchElement.getAttribute("required")){
1593 if(!searchElement.value){
1603 var checkedValue = $('.onoffswitch-checkbox:checked').val();
1605 var x = document.getElementsByClassName("onoffswitch-checkbox");
1609 console.log("checkedValue:" + checkedValue);
1610 for(var i=0; i<x.length; x++){
1611 console.log("checkbox id: " + x[i].id);
1612 booleanTrueElements.push(x[i].id)
1616 var uuu = "policyController/validate_policy.htm";
1618 console.log("$scope.isCheck:" + $scope.isCheck);
1620 if($scope.isCheck == true){
1621 if(("configName" in policy) == false){
1622 Notification.error("Validation Failed: configName is required");
1623 $scope.savebutton = true;
1626 if(("location" in policy) == false){
1627 Notification.error("Validation Failed: location is required");
1628 $scope.savebutton = true;
1631 if(("uuid" in policy) == false){
1632 Notification.error("Validation Failed: uuid is required");
1633 $scope.savebutton = true;
1636 if(("policyScope" in policy) == false){
1637 Notification.error("Validation Failed: policyScope is required");
1638 $scope.savebutton = true;
1643 var postData={policyData: policy, policyJSON : jsonPolicy};
1648 contentType: 'application/json',
1649 data: JSON.stringify(postData),
1650 success : function(data){
1651 $scope.$apply(function(){
1652 $scope.validateData = data.data.replace(/\"/g, "");
1653 $scope.data=data.data.substring(1,8);
1654 var size = data.data.length;
1655 if($scope.data == 'success'){
1656 Notification.success("Validation Success.");
1657 $scope.savebutton = false;
1659 var displayWarning = data.data.substring(19,size - 1);
1660 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
1661 document.getElementById("validate").style.color = "white";
1662 document.getElementById("validate").style.backgroundColor = "skyblue";
1665 Notification.error("Validation Failed.");
1666 document.getElementById("validate").innerHTML = $scope.validateData;
1667 document.getElementById("validate").style.color = "white";
1668 document.getElementById("validate").style.backgroundColor = "red";
1669 $scope.savebutton = true;
1673 console.log($scope.data);
1675 error : function(data){
1676 Notification.error("Validation Failed.");
1677 $scope.savebutton = true;
1682 function extend(obj, src) {
1683 for (var key in src) {
1684 if (src.hasOwnProperty(key)) obj[key] = src[key];
1690 $('.Switch').click(function() {
1691 // Check If Enabled (Has 'On' Class)
1692 if ($(this).hasClass('On')){
1693 // Try To Find Checkbox Within Parent Div, And Check It
1694 $(this).parent().find('input:checkbox').attr('checked', true);
1695 // Change Button Style - Remove On Class, Add Off Class
1696 $(this).removeClass('On').addClass('Off');
1697 } else { // If Button Is Disabled (Has 'Off' Class)
1698 // Try To Find Checkbox Within Parent Div, And Uncheck It
1699 $(this).parent().find('input:checkbox').attr('checked', false);
1700 // Change Button Style - Remove Off Class, Add On Class
1701 $(this).removeClass('Off').addClass('On');
1704 // Loops Through Each Toggle Switch On Page
1705 $('.Switch').each(function() {
1706 // Search of a checkbox within the parent
1707 if ($(this).parent().find('input:checkbox').length){
1709 // If checkbox doesnt have the show class then hide it
1710 if (!$(this).parent().find('input:checkbox').hasClass("show")){
1711 $(this).parent().find('input:checkbox').hide(); }
1713 // Look at the checkbox's checkked state
1714 if ($(this).parent().find('input:checkbox').is(':checked')){
1715 // Checkbox is not checked, Remove the On Class and Add the Off Class
1716 $(this).removeClass('On').addClass('Off');
1718 // Checkbox Is Checked Remove Off Class, and Add the On Class
1719 $(this).removeClass('Off').addClass('On');