2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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 var option = document.createElement('option');
276 option.setAttribute('value', checkValue);
277 option.appendChild(document.createTextNode(checkValue));
278 document.getElementById(selects[i].id).appendChild(option);
279 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
280 plainAttributeKeys.push(selects[i].id);
283 plainAttributeKeys.push(selects[i].id);
286 plainAttributeKeys.push(selects[i].id);
290 for (var k=0; k<removeValues.length; k++){
291 var elem = document.getElementById(removeValues[k]);
292 elem.parentNode.removeChild(elem);
294 var ele = angular.element(document.getElementById("div."+value));
295 $compile(ele.contents())($scope)
301 removeChoice = function(value) {
303 if(value != undefined){
304 var c = document.getElementById("div."+value).childElementCount;
307 Notification.error("The original one is not removable.");
310 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
314 function findVal(object, key) {
316 Object.keys(object).some(function(k) {
321 if (object[k] && typeof object[k] === 'object') {
322 value = findVal(object[k], key);
323 return value !== undefined;
329 $scope.pullVersion = function(serviceName) {
330 console.log(serviceName);
331 if(serviceName != undefined){
332 var uuu = "policyController/getModelServiceVersioneData.htm";
333 var postData={policyData: serviceName};
338 contentType: 'application/json',
339 data: JSON.stringify(postData),
340 success : function(data){
341 $scope.$apply(function(){
342 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
345 error : function(data){
346 alert("Error While Retriving the Template Layout Pattren.");
352 var splitEqual = '=';
353 var splitComma = ',';
354 var splitcolon = ':';
355 var splitEnum = "],";
356 var plainAttributeKeys = [];
358 var enumKeyList = [];
359 var dictionaryList = [];
360 var dictionaryNameList = [];
361 var isInitViewEdit = false;
362 $scope.addDataToFields = function(serviceName, version){
363 if(serviceName != null && version !=null){
364 var service=serviceName+"-v"+version;
365 var myNode = document.getElementById("DynamicTemplate");
366 myNode.innerHTML = '';
367 var uuu = "policyController/getDCAEMSTemplateData.htm";
368 var postData={policyData: service};
370 console.log("service: " +service);
372 var dataOrderInfo = "";
374 booleanTrueElements = [];
376 document.getElementById("msPolicyloader").style.visibility = "visible";
382 contentType: 'application/json',
383 data: JSON.stringify(postData),
384 success : function(data){
386 document.getElementById("msPolicyloader").style.visibility = "hidden";
388 $scope.$apply(function(){
389 $scope.dcaeModelData = data[0].dcaeModelData;
390 $scope.dcaeJsonDate = data[0].jsonValue;
391 $scope.dataOrderInfo = null;
392 $scope.dataOrderInfo = data[0].dataOrderInfo;
393 console.log("data[0].dataOrderInfo: " + data[0].dataOrderInfo);
394 console.log("$scope.dataOrderInfo: " + $scope.dataOrderInfo);
396 if(data[0].allManyTrueKeys){
397 console.log("$scope.allManyTrueKeys: " + $scope.allManyTrueKeys);
399 console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
400 var attributes = $scope.dcaeModelData.attributes;
401 console.log("attributes: " +attributes);
402 var refAttributes = $scope.dcaeModelData.ref_attributes;
403 var subAttributes = $scope.dcaeModelData.sub_attributes;
404 console.log("subAttributes: " + subAttributes);
405 console.log("refAttributes: " + refAttributes);
406 var headDefautlsData = data[0].headDefautlsData;
407 if(headDefautlsData != null){
408 $scope.temp.policy.onapName = headDefautlsData.onapName;
409 $scope.temp.policy.guard = headDefautlsData.guard;
410 $scope.temp.policy.riskType = headDefautlsData.riskType;
411 $scope.temp.policy.riskLevel = headDefautlsData.riskLevel;
412 $scope.temp.policy.priority = headDefautlsData.priority;
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 valueCompare = dictionary[m].value;
435 var valueModel = dictionary[m].modelName;
436 var conpairService = serviceName;
437 if (valueModel.includes('-v')){
438 conpairService = service;
440 if(valueModel.localeCompare(conpairService) == 0){
441 console.log(valueCompare);
442 dictionaryList.push(dictionary[m]);
443 if (!dictionaryNameList.includes(dictionary[m].name)){
444 dictionaryNameList.push(dictionary[m].name)
450 $scope.temp.policy.ruleGridData = [];
452 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
453 dataOrderInfo = $scope.dataOrderInfo;
456 $scope.jsonLayout($scope.dcaeJsonDate);
460 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ // If it's veiw or edit
461 isInitViewEdit = true;
464 // If ruleData contains extra elements created by clicked add button
465 console.log("$scope.temp.policy.ruleData:" + $scope.temp.policy.ruleData);
466 if($scope.temp.policy.ruleData != null){
467 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
468 propNames.forEach(function(name) {
472 var extraElements = data;
474 if(plainAttributeKeys != null){
475 for(var b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
476 var newValue = plainAttributeKeys[b].split("*");
477 for(var a = 0; a < data.length; a++){
478 if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
479 extraElements.splice(a, 1);
484 //--- Populate these extra elements created by clicked add button
485 for(var a = 0; a < extraElements.length; a++){
486 if(extraElements[a].includes("@")){
487 var index = extraElements[a].lastIndexOf("@");
489 // Get the number after @
490 var n = getNumOfDigits(extraElements[a], index+1);
492 var key = extraElements[a].substring(0, index+n+1); //include @x in key also by n+2 since x can be 1,12, etc
493 console.log("key: " + key);
498 var unique = checkData.filter(onlyUnique);
499 var parentLevelElements = [];
501 //--- get all root level exta elments first (only contains one "@")
502 for(var i =0; i < unique.length; i++){
503 var firstIndex = unique[i].indexOf("@");
504 var lastIndex = unique[i].lastIndexOf("@");
505 if(firstIndex == lastIndex){
506 var newKey = unique[i].substring(0, firstIndex);
507 console.log("root element: " + newKey);
508 parentLevelElements.push(newKey);
509 unique[i] = "*processed*";
515 for (var i = 0; i < $scope.labelManyKeys.length; i++) {
516 var label = $scope.labelManyKeys[i];
517 if(parentLevelElements){
518 for (var k = 0; k < parentLevelElements.length; k++){
519 if(label == parentLevelElements[k]){
526 //if no layout order info, keep the process as before
528 for(var i =0; i < unique.length; i++){
529 if(unique[i] != "*processed*"){
530 var index = unique[i].lastIndexOf("@");
531 var newKey = unique[i].substring(0, index);
532 console.log("newKey: " + newKey);
534 var newElement = document.getElementById("div."+unique[j]);
535 //check weather it has been created already
536 if(newElement != null){
539 newElement = document.getElementById(unique[j]);
540 if(newElement != null){
546 addNewChoice(newKey);
551 //---reset to default
553 $scope.labelManyKeys = [];
555 //---process none labels
556 for (var j = 0; j < unique.length; j++){
557 if(unique[j] != "*processed*"){
558 // if not created yet
559 if(!document.getElementById(unique[j])){
560 var index = unique[j].lastIndexOf("@");
561 var newKey = unique[j].substring(0, index);
563 var newElement = document.getElementById("div."+unique[j]);
565 //check weather it has been created already
566 if(newElement != null){
569 newElement = document.getElementById(unique[j]);
570 if(newElement != null){
574 //if not created yet, then create it.
575 addNewChoice(newKey);
585 var ele = angular.element(document.getElementById("DynamicTemplate"));
586 $compile(ele.contents())($scope);
588 isInitViewEdit = false;
591 error : function(data){
592 alert("Error While Retriving the Template Layout Pattren.");
599 function getNumOfDigits(str_value, index){
600 // Get the number after @
601 var str = str_value.substring(index, str_value.length);
604 for (var x = 0; x < str.length; x++){
615 function getDictionary(attribute){
616 var dicName = attribute;
618 if(attribute.includes(":")){
619 dicName = attribute.split(":")[0];
622 var dictionaryRegExp = new RegExp(dicName);
623 listemunerateValues = [];
624 if (dictionaryRegExp.test(dictionaryNameList)) {
625 for (p=0; p < dictionaryList.length; p += 1) {
626 if (dicName == dictionaryList[p].name) {
627 listemunerateValues.push(dictionaryList[p].value);
631 return listemunerateValues;
634 function getList(attribute) {
635 var enumName = attribute;
636 console.log("In getList: attribute => " + attribute);
638 if(attribute.includes(":")){
639 enumName = attribute.split(":")[0];
642 var baseEnum = $scope.dcaeModelData.enumValues;
644 if(baseEnum != null){
645 enumList = baseEnum.split(splitEnum);
648 var patternTest = new RegExp(enumName);
649 for (k=0; k < enumList.length; k += 1){
650 if(patternTest.test(enumList[k]) == true){
651 enumAttributes = enumList[k].trim();
656 enumAttributes = enumAttributes.replace("[", "");
657 enumAttributes = enumAttributes.replace("]", "");
658 enumAttributes = enumAttributes.replace(/ /g, '');
659 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
660 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
661 //enumKeyList.push(attribute);
662 return listemunerateValues;
668 function getBooleanList(){
669 var booleanList = [];
670 booleanList.push(true);
671 booleanList.push(false);
676 function isArray(arrayTest) {
677 return Object.prototype.toString.call(arrayTest) === '[object Array]';
681 $scope.layOutElementList = [];
682 $scope.layOutOnlyLableList = [];
684 var elementOrderNum = 0;
686 function deconstructJSON(layOutData, level , name) {
690 var stringValue = "java.lang.String";
691 var string = "string";
692 var intValue = "int";
693 var integerValue = "integer";
694 var double = "double";
695 var boolean = "boolean";
696 var baseLevel = level;
698 var attributekey = "";
700 if (name.length > 1){
701 label = label + name + '.';
704 for (key in layOutData) {
705 array = isArray(layOutData[key]);
706 console.log("key: " + key , "value: " + layOutData[key]);
708 if (!!layOutData[key] && typeof(layOutData[key])=="object") {
710 if (array==false && key!=="0"){
712 if($scope.dataOrderInfo){
713 var labelObject = {"label" : key, "level" : label, "array" : array};
714 //save it to the list
715 $scope.layOutOnlyLableList.push(labelObject);
719 $scope.labelLayout(label, key, array );
724 if (array == true && key!=0){
728 if (lableList.length > 0){
732 var newKey = lableList.pop();
734 if($scope.dataOrderInfo){
736 var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
737 //save it to the list
738 $scope.layOutOnlyLableList.push(labelObject);
742 $scope.labelLayout(baseLevel, newKey, array );
746 label = baseLevel + newKey + '@0.';
748 label = baseLevel + newKey + '.';
751 deconstructJSON(layOutData[key] , label, key);
753 var attirbuteLabel = label;
756 var isRequired = false;
757 if (layOutData[key].includes('defaultValue-')){
758 defaultValue = layOutData[key].split('defaultValue-')[1];
761 if (layOutData[key].includes('description-')){
762 description = layOutData[key].split('description-')[1];
768 attributekey = lableList.pop();
769 attirbuteLabel = baseLevel;
771 attributekey = key.split();
774 if (layOutData[key].includes('required-true')){
778 var subAttributes = $scope.dcaeModelData.sub_attributes;
781 var jsonObject = JSON.parse(subAttributes);
783 var lablInfo = findVal(jsonObject, attributekey);
784 console.log("deconstructJSON:findValue : " + attributekey +": "+ lablInfo);
786 if(lablInfo.includes('required-true')){
789 if(lablInfo.includes('defaultValue-')){
790 defaultValue = lablInfo.split('defaultValue-')[1];
793 if(lablInfo.includes('description-')){
794 description = lablInfo.split('description-')[1];
798 var allkeys = Object.keys(jsonObject);
800 for (var k = 0; k < allkeys.length; k++) {
801 var keyValue = allkeys[k];
802 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
803 if(jsonObject[keyValue]){
804 var tempObject = jsonObject[keyValue];
805 if(tempObject && tempObject[key]){
806 if (tempObject[key].includes('required-true')){
810 if(tempObject[key].includes('defaultValue-')){
811 defaultValue = tempObject[key].split('defaultValue-')[1];
814 if(tempObject[key].includes('description-')){
815 description = tempObject[key].split('description-')[1];
825 var elementObject = {};
826 switch (layOutData[key].split(splitcolon)[0]){
830 if($scope.dataOrderInfo){
832 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text", "description":description};
833 $scope.layOutElementList.push(elementObject);
835 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
840 if($scope.dataOrderInfo){
842 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number" , "description":description};
843 $scope.layOutElementList.push(elementObject);
845 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
849 if($scope.dataOrderInfo){
851 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double", "description":description};
852 $scope.layOutElementList.push(elementObject);
854 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
858 if($scope.dataOrderInfo){
860 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"boolean", "description":description};
861 $scope.layOutElementList.push(elementObject);
863 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
867 if (layOutData[key].includes('dictionary-')){
868 var list = getDictionary(layOutData[key].split('dictionary-')[1]);
870 //--- get dropdown values from enumValues
871 var list = getList(layOutData[key]);
873 if (list.length===0){ //not dropdown element
874 if($scope.dataOrderInfo){
876 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description};
877 $scope.layOutElementList.push(elementObject);
880 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
883 if($scope.dataOrderInfo){
885 elementObject = {"id": elementOrderNum, "attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "list":list, "type":"dropBox", "description":description};
886 $scope.layOutElementList.push(elementObject);
888 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
898 $scope.validContionalRequired = function(parentId) {
899 console.log("ng-blur event: parentId : " + parentId);
900 var c = document.getElementById(parentId).children;
902 var hasValue = false;
903 for (i = 0; i < c.length; i++) {
904 if(c[i].getAttribute("data-conditional")){
905 console.log(c[i].getAttribute("data-conditional"));
906 console.log(c[i].value);
907 if(c[i].value != null && c[i].value.trim() != ""){
913 for (i = 0; i < c.length; i++) {
914 if(c[i].getAttribute("data-conditional")){
916 c[i].setAttribute("required", true);
918 c[i].removeAttribute("required");
924 $scope.jsonLayout = function(layOutData){
926 deconstructJSON(layOutData , "", "");
928 var orderValue = $scope.dataOrderInfo;
929 var layOutElementList = $scope.layOutElementList;
930 var labelList = $scope.layOutOnlyLableList;
934 $scope.layOutElementList = [];
935 $scope.layOutOnlyLableList = [];
937 // Only layout in order if order info provided
940 if(orderValue.includes("[")){
941 orderValue = orderValue.replace("[", "") ;
942 orderValue = orderValue.replace("]", "") ;
945 orderValue = orderValue.split(',') ;
947 for (var i = 0; i < orderValue.length; i++) {
948 console.log("orderValue["+i+"]"+ orderValue[i]);
949 var key = orderValue[i].trim();
951 //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
953 for (var k = 0; k < labelList.length; k++){
955 var label = labelList[k].label.toString().trim();
956 var level = labelList[k].level.toString().trim();
957 var array = labelList[k].array;
960 $scope.labelLayout(level, label, array);
961 //in case to have duplicate label names
962 labelList[k].label = "*processed*";
967 //--- then layout each element based on its order defined in YAML file
968 for (var j = 0; j < layOutElementList.length; j++) {
970 var attributekey = layOutElementList[j].attributekey.toString().trim();
972 if(key == attributekey){
974 var attirbuteLabel = layOutElementList[j].attirbuteLabel.toString().trim();
975 var defaultValue = layOutElementList[j].defaultValue.toString().trim();
976 var description = layOutElementList[j].description;
977 var isRequired = layOutElementList[j].isRequired;
979 console.log("layOutElementList[" +j+ "]: id:" + layOutElementList[j].id + ", attributekey:"+ layOutElementList[j].attributekey + ", attirbuteLabel:" + layOutElementList[j].attirbuteLabel);
980 console.log("layOutElementList[" +j+ "]: type:" + layOutElementList[j].type);
981 if (layOutElementList[j].type == "dropBox"){
982 $scope.dropBoxLayout(attirbuteLabel, attributekey, layOutElementList[j].array, defaultValue, layOutElementList[j].list, isRequired, description);
985 $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type, description);
989 //in case to have duplicate attribute names
990 layOutElementList[j].attributekey = "*processed*";
999 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType, description){
1000 $scope.temp.policy.ruleGridData.push(attibuteKey);
1001 var br = document.createElement("BR");
1003 var label = document.createElement("Label");
1004 var labeltext = null;
1005 var requiredLabName = "";
1006 if (matching.includes(attibuteKey)){
1007 labeltext = document.createTextNode(attibuteKey + "*!");
1008 isRequired = true; //set required as true for matching element
1011 requiredLabName = attibuteKey + " * ";
1012 labeltext = document.createTextNode(requiredLabName);
1014 labeltext = document.createTextNode(attibuteKey);
1019 var divID = labelValue;
1021 if (labelValue.length < 1){
1022 divID = "DynamicTemplate";
1023 }else if (labelValue.endsWith('.')){
1024 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1027 label.appendChild(labeltext);
1029 var textField = document.createElement("INPUT");
1031 textField.setAttribute("class" , "form-control");
1033 if(dataType == "double"){
1034 textField.setAttribute("type" , "number");
1035 textField.setAttribute("step" , "any");
1037 }else if(dataType == "boolean"){ //gw1218 testing boolean
1038 var booleanDiv = document.createElement("div");
1040 booleanDiv.setAttribute("class" , "onoffswitch");
1042 //var checkField = document.createElement("INPUT");
1043 textField.setAttribute("type" , "checkbox");
1044 textField.setAttribute("name" , "onoffswitch");
1045 textField.setAttribute("class" , "onoffswitch-checkbox");
1046 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1047 if(defaultValue.substring(0,defaultValue.indexOf(":")) == "true") {
1048 textField.setAttribute("checked" , true);
1050 textField.removeAttribute("checked");
1053 var booleanlabel = document.createElement("Label");
1054 booleanlabel.setAttribute("class" , "onoffswitch-label");
1055 booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+'');
1057 var span1 = document.createElement("span");
1058 span1.setAttribute("class" , "onoffswitch-inner");
1060 var span2 = document.createElement("span");
1061 span2.setAttribute("class" , "onoffswitch-switch");
1064 booleanlabel.appendChild(span1);
1065 booleanlabel.appendChild(span2);
1066 booleanDiv.appendChild(textField);
1067 booleanDiv.appendChild(booleanlabel);
1069 document.getElementById(divID).appendChild(label);
1070 document.getElementById(divID).appendChild(booleanDiv);
1074 textField.setAttribute("type" , dataType);
1081 if(dataType != "boolean"){
1082 textField.setAttribute("style" , "width:300px;");
1083 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1084 if(description && description != "null"){
1085 textField.setAttribute("title", description);
1091 if(attributeManyKey){
1092 checkKey = labelValue + attibuteKey+'@0';
1093 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
1094 var divTag = document.createElement("div");
1095 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
1096 var addButton = document.createElement("BUTTON");
1097 var buttonaddLabel = document.createTextNode("+");
1098 addButton.appendChild(buttonaddLabel);
1099 addButton.setAttribute("id", labelValue + attibuteKey);
1100 addButton.setAttribute("class", "btn btn-add-remove");
1101 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + attibuteKey+'");');
1102 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1103 var removeButton = document.createElement("BUTTON");
1104 var buttonremoveLabel = document.createTextNode("-");
1105 removeButton.appendChild(buttonremoveLabel);
1106 removeButton.setAttribute("class", "btn btn-add-remove");
1107 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue + attibuteKey+'");');
1108 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1109 document.getElementById(divID).appendChild(addButton);
1110 document.getElementById(divID).appendChild(removeButton);
1111 document.getElementById(divID).appendChild(label);
1112 id = "div."+labelValue+attibuteKey;
1113 //var divTag = document.createElement("div");
1114 divTag.setAttribute("id", id);
1115 document.getElementById(divID).appendChild(divTag);
1116 textField.className += ' first_child';
1118 textField.setAttribute("required", "true");
1121 divTag.appendChild(textField);
1122 document.getElementById(divID).appendChild(divTag);
1124 }else if (dataType != "boolean"){
1125 checkKey = labelValue + attibuteKey;
1126 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1127 if(document.getElementById(divID).hasAttribute('required') || !document.getElementById(divID).hasAttribute('data-conditional')){
1128 if(requiredLabName.includes("*") || isRequired){
1129 textField.setAttribute("required", "true");
1131 }else if (document.getElementById(divID).hasAttribute('data-conditional')){
1132 if(requiredLabName.includes("*")){
1133 var requiredNode = document.createElement('span');
1134 requiredNode.setAttribute("class", "mstooltip");
1135 requiredNode.textContent = "?";
1136 label.appendChild(requiredNode);
1138 var requiredNodeToolTip = document.createElement('span');
1139 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1140 requiredNodeToolTip.textContent = "Conditional Required";
1141 requiredNode.appendChild(requiredNodeToolTip);
1143 textField.setAttribute("data-conditional", divID);
1144 textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1148 document.getElementById(divID).appendChild(label);
1149 document.getElementById(divID).appendChild(textField);
1150 document.getElementById(divID).appendChild(br);
1154 if(dataType != "boolean" && divID.includes("@0") && divID.includes("div.")){
1155 var firstChild_Id = divID.split("@0")[0];
1156 var firstChild_element = document.getElementById(firstChild_Id);
1157 if(firstChild_element){
1159 if(!firstChild_element.className.includes('children_group border')){
1164 firstChild_element.className += ' children_group border' + layer; //here is div with a group of children.
1168 console.log('firstChild_Id: ' + firstChild_Id);
1169 console.log('divID: ' + divID);
1171 if(dataType != "boolean" && defaultValue.length > 0){
1172 if(defaultValue.includes(":")){
1173 defaultValue = defaultValue.split(":")[0];
1174 if(defaultValue === "NA") {
1178 if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
1179 document.getElementById(checkKey).value = defaultValue;
1183 if($scope.temp.policy.ruleData != null){
1184 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1185 if (attributeManyKey){
1186 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
1187 if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){
1188 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
1191 if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
1192 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1197 if (dataType != "boolean"){
1198 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
1200 plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean");
1204 $scope.labelManyKeys = [];
1205 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
1206 var label = document.createElement("Label")
1207 var divID = labelValue;
1209 if (labelValue.length < 1){
1210 divID = "DynamicTemplate";
1211 } else if (labelValue.endsWith('.')){
1212 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1215 var subAttributes = $scope.dcaeModelData.sub_attributes;
1216 var jsonObject = JSON.parse(subAttributes);
1217 var lablInfo = findVal(jsonObject, lableName);
1218 console.log("findValue : " + lableName +": "+ lablInfo);
1220 var required = null;
1222 if(typeof lablInfo === 'string' ){
1223 if(lablInfo.includes("required-true")){
1226 }else if (lablInfo.includes("required-false")){
1232 var labeltext = document.createTextNode(lableName + star);
1234 label.appendChild(labeltext);
1238 var addButton = document.createElement("BUTTON");
1239 var buttonLabel = document.createTextNode("+");
1240 addButton.appendChild(buttonLabel);
1241 addButton.setAttribute("class", "btn btn-add-remove");
1242 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + lableName+'");');
1243 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1244 var removeButton = document.createElement("BUTTON");
1245 var buttonremoveLabel = document.createTextNode("-");
1246 removeButton.appendChild(buttonremoveLabel);
1247 removeButton.setAttribute("class", "btn btn-add-remove");
1248 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue +lableName+'");');
1249 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1250 document.getElementById(divID).appendChild(addButton);
1251 document.getElementById(divID).appendChild(removeButton);
1252 document.getElementById(divID).appendChild(label);
1253 var id = "div."+labelValue+lableName;
1254 var divTag = document.createElement("div");
1255 divTag.setAttribute("id", id);
1256 document.getElementById(divID).appendChild(divTag);
1258 var divTag = document.createElement("div");
1259 divTag.setAttribute("id", id +'@0');
1261 if(!divTag.className.includes('children_group border')){
1266 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1269 divTag.setAttribute("required", required);
1270 }else if(required == false){
1271 divTag.setAttribute("data-conditional", "yes");
1274 document.getElementById(id).appendChild(divTag);
1276 $scope.labelManyKeys.push(lableName);
1279 var divTag = document.createElement("div");
1280 divTag.setAttribute("id", "div."+labelValue+lableName);
1282 if(!divTag.className.includes('children_group border')){
1287 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1290 divTag.setAttribute("required", required);
1291 }else if(required == false){
1292 divTag.setAttribute("data-conditional", "yes");
1294 document.getElementById(divID).appendChild(label);
1295 document.getElementById(divID).appendChild(divTag);
1299 $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){
1300 var br = document.createElement("BR");
1302 if (labelLevel.length < 1){
1303 var divID = "DynamicTemplate";
1304 } else if (labelLevel.endsWith('.')){
1305 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1309 var label = document.createElement("Label")
1311 var refAttributes = $scope.dcaeModelData.ref_attributes;
1312 if(isRequired != true && refAttributes){ //check refAttributes also
1313 var refAttributesList = refAttributes.split(splitComma);
1314 for (k = 0; k < refAttributesList.length; k++){
1315 var refAttribute = refAttributesList[k].split(splitEqual);
1316 if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
1322 if (matching.includes(attributeName)){
1323 var labeltext = document.createTextNode(attributeName + "*!");
1324 label.appendChild(labeltext);
1325 isRequired = true; //set required as true for matching element
1328 var requiredLabName = attributeName+ " * ";
1329 labeltext = document.createTextNode(requiredLabName);
1331 labeltext = document.createTextNode(attributeName);
1334 label.appendChild(labeltext);
1336 label.appendChild(labeltext);
1337 // if this field is required, but its parent is not required
1338 if(isRequired && document.getElementById(divID).hasAttribute('data-conditional')){
1339 var requiredNode = document.createElement('span');
1340 requiredNode.setAttribute("class", "mstooltip");
1341 requiredNode.textContent = "?";
1342 label.appendChild(requiredNode);
1344 var requiredNodeToolTip = document.createElement('span');
1345 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1346 requiredNodeToolTip.textContent = "Conditional Required";
1347 requiredNode.appendChild(requiredNodeToolTip);
1351 var listField = document.createElement("SELECT");
1352 listField.setAttribute("class" , "form-control");
1353 listField.setAttribute("style" , "width:300px;");
1354 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1356 if(description && description != "null"){
1357 listField.setAttribute("title", description);
1361 if(document.getElementById(divID).hasAttribute('data-conditional')){
1362 listField.setAttribute("data-conditional", divID);
1363 listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1365 listField.setAttribute("required", true);
1368 if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element
1369 var optionFirst = document.createElement('option');
1370 var optionValue = "";
1371 if($scope.temp.policy.ruleData != null){
1372 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1373 optionValue = $scope.temp.policy.ruleData[labelLevel + attributeName];
1376 optionFirst.setAttribute('value', optionValue);
1377 optionFirst.appendChild(document.createTextNode(optionValue));
1378 listField.appendChild(optionFirst);
1380 var ruleFormationCheck = false;
1381 if(listemunerateValues.length !== 0 && typeof listemunerateValues[0] == "string" && listemunerateValues[0].includes("dictionary:")) {
1382 var ruleCheck = listemunerateValues[0].split("&");
1383 var dictParams = ruleCheck[0].split(":");
1384 var dictParamsSplit = dictParams[1].split("@");
1385 if (ruleCheck[1] != undefined && ruleCheck[1] == 'Rule') {
1386 ruleFormationCheck = true;
1388 PolicyAppService.getData(dictParamsSplit[0]).then(function (data) {
1390 $scope.data = JSON.parse(j.data);
1391 console.log($scope.data);
1392 $scope.listDictionarys = JSON.parse($scope.data[dictParamsSplit[1]]);
1393 for (i=0; i < $scope.listDictionarys.length; i += 1) {
1394 option = document.createElement('option');
1395 option.setAttribute('value', $scope.listDictionarys[i]);
1396 option.appendChild(document.createTextNode($scope.listDictionarys[i]));
1397 listField.appendChild(option);
1399 }, function (error) {
1400 console.log("failed");
1405 for (i=0; i < listemunerateValues.length; i += 1) {
1406 if(typeof listemunerateValues[i] == "string" && listemunerateValues[i].includes("equal-sign")){
1407 listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','=');
1410 option = document.createElement('option');
1411 option.setAttribute('value', listemunerateValues[i]);
1412 option.appendChild(document.createTextNode(listemunerateValues[i]));
1413 option.setAttribute('value', listemunerateValues[i]);
1414 listField.appendChild(option);
1417 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1419 enumKeyList.push(attributeName);
1421 document.getElementById(divID).appendChild(label);
1422 document.getElementById(divID).appendChild(br);
1425 document.getElementById(divID).appendChild(listField).multiple = true;
1426 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1428 document.getElementById(divID).appendChild(listField).multiple = false;
1429 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1432 if(defaultValue.includes(':')){
1433 defaultValue = defaultValue.split(':')[0];
1435 var location = listemunerateValues.indexOf(defaultValue);
1436 document.getElementById(labelLevel +attributeName).options[location+1].selected = true;
1440 if (ruleFormationCheck) {
1441 var optionInput = document.createElement("INPUT");
1442 optionInput.setAttribute("type" , "text");
1443 optionInput.setAttribute("id" , ''+ labelLevel + attributeName + '.input');
1444 optionInput.setAttribute("name" , "ruleName");
1445 optionInput.setAttribute("value" , " ");
1446 optionInput.setAttribute("style" , "width:300px;");
1447 optionInput.setAttribute("ng-disabled" , "temp.policy.readOnly");
1448 optionInput.removeAttribute("required");
1450 document.getElementById(divID).appendChild(optionInput);
1452 var optionButton = document.createElement("BUTTON");
1453 optionButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1454 var buttonLabel = document.createTextNode("+");
1455 optionButton.appendChild(buttonLabel);
1456 optionButton.setAttribute("class", "btn btn-add-remove");
1457 optionButton.setAttribute("onclick" , 'addDynamicOptions("'+ labelLevel + attributeName + '");');
1458 optionButton.removeAttribute("required");
1461 document.getElementById(divID).appendChild(optionButton);
1462 document.getElementById(divID).appendChild(br);
1465 if($scope.temp.policy.ruleData != null){
1467 document.getElementById(labelLevel +attributeName).options[0].selected = false;
1468 for (i=0; i < listemunerateValues.length; i += 1) {
1469 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
1470 if (testValue === undefined){
1471 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
1473 var location = listemunerateValues.indexOf(testValue);
1475 document.getElementById(labelLevel +attributeName).options[location].selected = true;
1479 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1480 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
1486 addDynamicOptions = function(id) {
1487 var option = document.createElement("option");
1488 var value = document.getElementById(id+".input").value;
1489 option.setAttribute('value', value);
1490 option.appendChild(document.createTextNode(value));
1491 document.getElementById(id).options.add(option);
1492 document.getElementById(id+".input").value = "";
1495 function onlyUnique(value, index, self) {
1496 return self.indexOf(value) === index;
1499 $scope.savePolicy = function(policy){
1500 if(policy.itemContent != undefined){
1501 $scope.refreshCheck = true;
1502 $scope.policyNavigator = policy.itemContent;
1503 policy.itemContent = "";
1505 $scope.savebutton = false;
1508 var jsonPolicy = {};
1509 if(plainAttributeKeys != null){
1510 for(a = 0; a < plainAttributeKeys.length; a++){
1511 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1512 console.log("splitPlainAttributeKey: " + splitPlainAttributeKey);
1513 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1514 var key = splitPlainAttributeKey[0];
1515 if(searchElement == null){
1516 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1517 key = splitPlainAttributeKey[0]+'@0';
1518 }else if (searchElement.nodeName == 'BUTTON'){
1519 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1520 key = splitPlainAttributeKey[0]+'@0';
1522 if(searchElement != null){
1523 var keySplit = key.split(dot);
1524 var elumentLocation = keySplit.length;
1526 if (elumentLocation > 1){
1527 enumKey = keySplit[keySplit.length - 1];
1529 //check it is undefined or not
1530 if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){
1531 if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){
1532 var multiSlect = [];
1533 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1534 multiSlect.push(searchElement.selectedOptions[i].value);
1536 jsonPolicy[key]= multiSlect;
1538 console.log(" searchElement.value = > " + searchElement.value);
1539 if(splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1] == "boolean"){
1540 jsonPolicy[key]= false;
1541 for(var i=0; i<booleanTrueElements.length; i++){
1542 if(booleanTrueElements[i] == key){
1543 jsonPolicy[key]= true;
1548 jsonPolicy[key]= searchElement.value;
1552 if(searchElement.value != null){
1553 jsonPolicy[key]= searchElement.value;
1554 console.log(" searchElement.value = > " + searchElement.value);
1555 if(splitPlainAttributeKey[1] == "boolean"){
1556 jsonPolicy[key]= false;
1557 for(var i=0; i<booleanTrueElements.length; i++){
1558 if(booleanTrueElements[i] == key){
1559 jsonPolicy[key]= true;
1568 var uuu = "policycreation/save_policy";
1569 var postData={policyData: policy, policyJSON : jsonPolicy};
1574 contentType: 'application/json',
1575 data: JSON.stringify(postData),
1576 success : function(data){
1577 $scope.$apply(function(){
1578 $scope.data=data.policyData;
1579 if($scope.data == 'success'){
1580 $scope.temp.policy.readOnly = 'true';
1581 $scope.safetyChecker = data.policyData.split("#")[2];
1582 if ($scope.safetyChecker!=undefined) {
1583 Notification.success($scope.safetyChecker);
1585 $scope.pushStatus=data.policyData.split("&")[1];
1586 if($scope.pushStatus=="successPush"){
1587 Notification.success("Policy pushed successfully");
1589 Notification.success("Policy Saved Successfully.");
1590 }else if ($scope.data == 'PolicyExists'){
1591 $scope.savebutton = true;
1592 Notification.error("Policy Already Exists with Same Name in Scope.");
1595 console.log($scope.data);
1597 error : function(data){
1598 Notification.error("Error Occured while saving Policy.");
1603 var booleanTrueElements = [];
1604 $scope.validatePolicy = function(policy){
1605 document.getElementById("validate").innerHTML = "";
1607 var jsonPolicy = {};
1608 if(plainAttributeKeys != null){
1609 for(a = 0; a < plainAttributeKeys.length; a++){
1610 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1611 console.log(splitPlainAttributeKey[1]);
1612 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1613 var key = splitPlainAttributeKey[0];
1614 if(searchElement == null){
1615 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1616 key = splitPlainAttributeKey[0]+'@0';
1617 }else if (searchElement.nodeName == 'BUTTON'){
1618 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1619 key = splitPlainAttributeKey[0]+'@0';
1621 if(searchElement != null){
1622 if (enumKeyList.indexOf(key) != -1){
1623 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
1624 var multiSlect = [];
1625 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1626 multiSlect.push(searchElement.selectedOptions[i].value);
1628 jsonPolicy[key]= multiSlect;
1630 jsonPolicy[key]= searchElement.value;
1632 if(searchElement.getAttribute("required")){
1633 if(!searchElement.value){
1638 if(searchElement.value != null){
1639 jsonPolicy[key]= searchElement.value;
1640 if(searchElement.getAttribute("required")){
1641 if(!searchElement.value){
1651 var checkedValue = $('.onoffswitch-checkbox:checked').val();
1653 var x = document.getElementsByClassName("onoffswitch-checkbox");
1657 console.log("checkedValue:" + checkedValue);
1658 for(var i=0; i<x.length; x++){
1659 console.log("checkbox id: " + x[i].id);
1660 booleanTrueElements.push(x[i].id)
1664 var uuu = "policyController/validate_policy.htm";
1666 console.log("$scope.isCheck:" + $scope.isCheck);
1668 if($scope.isCheck == true){
1669 if(("configName" in policy) == false){
1670 Notification.error("Validation Failed: configName is required");
1671 $scope.savebutton = true;
1674 if(("location" in policy) == false){
1675 Notification.error("Validation Failed: location is required");
1676 $scope.savebutton = true;
1679 if(("uuid" in policy) == false){
1680 Notification.error("Validation Failed: uuid is required");
1681 $scope.savebutton = true;
1684 if(("policyScope" in policy) == false){
1685 Notification.error("Validation Failed: policyScope is required");
1686 $scope.savebutton = true;
1691 var postData={policyData: policy, policyJSON : jsonPolicy};
1696 contentType: 'application/json',
1697 data: JSON.stringify(postData),
1698 success : function(data){
1699 $scope.$apply(function(){
1700 $scope.validateData = data.data.replace(/\"/g, "");
1701 $scope.data=data.data.substring(1,8);
1702 var size = data.data.length;
1703 if($scope.data == 'success'){
1704 Notification.success("Validation Success.");
1705 $scope.savebutton = false;
1707 var displayWarning = data.data.substring(19,size - 1);
1708 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
1709 document.getElementById("validate").style.color = "white";
1710 document.getElementById("validate").style.backgroundColor = "skyblue";
1713 Notification.error("Validation Failed.");
1714 document.getElementById("validate").innerHTML = $scope.validateData;
1715 document.getElementById("validate").style.color = "white";
1716 document.getElementById("validate").style.backgroundColor = "red";
1717 $scope.savebutton = true;
1721 console.log($scope.data);
1723 error : function(data){
1724 Notification.error("Validation Failed.");
1725 $scope.savebutton = true;
1731 $('.Switch').click(function() {
1732 // Check If Enabled (Has 'On' Class)
1733 if ($(this).hasClass('On')){
1734 // Try To Find Checkbox Within Parent Div, And Check It
1735 $(this).parent().find('input:checkbox').attr('checked', true);
1736 // Change Button Style - Remove On Class, Add Off Class
1737 $(this).removeClass('On').addClass('Off');
1738 } else { // If Button Is Disabled (Has 'Off' Class)
1739 // Try To Find Checkbox Within Parent Div, And Uncheck It
1740 $(this).parent().find('input:checkbox').attr('checked', false);
1741 // Change Button Style - Remove Off Class, Add On Class
1742 $(this).removeClass('Off').addClass('On');
1745 // Loops Through Each Toggle Switch On Page
1746 $('.Switch').each(function() {
1747 // Search of a checkbox within the parent
1748 if ($(this).parent().find('input:checkbox').length){
1750 // If checkbox doesnt have the show class then hide it
1751 if (!$(this).parent().find('input:checkbox').hasClass("show")){
1752 $(this).parent().find('input:checkbox').hide(); }
1754 // Look at the checkbox's checkked state
1755 if ($(this).parent().find('input:checkbox').is(':checked')){
1756 // Checkbox is not checked, Remove the On Class and Add the Off Class
1757 $(this).removeClass('On').addClass('Off');
1759 // Checkbox Is Checked Remove Off Class, and Add the On Class
1760 $(this).removeClass('Off').addClass('On');