2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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',
22 ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification',
23 function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
26 $scope.policyNavigator;
27 $scope.isCheck = false;
28 $scope.savebutton = true;
29 $scope.refreshCheck = false;
33 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
34 $scope.temp.policy = {
35 policyType : "Config",
36 configPolicyType : "Micro Service"
40 $scope.refresh = function(){
41 if($scope.refreshCheck){
42 $scope.policyNavigator.refresh();
44 $scope.modal('createNewPolicy', true);
45 $scope.temp.policy = "";
48 $scope.modal = function(id, hide) {
49 return $('#' + id).modal(hide ? 'hide' : 'show');
52 $('#ttlDate').datepicker({
53 dateFormat: 'dd/mm/yy',
56 onSelect: function(date) {
57 angular.element($('#ttlDate')).triggerHandler('input');
61 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
62 if ($scope.temp.policy.configName == undefined){
63 $scope.isCheck = false;
65 $scope.isCheck = true;
68 $scope.isCheck = false;
71 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
73 $scope.data = JSON.parse(j.data);
74 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
77 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
79 $scope.data = JSON.parse(j.data);
80 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
83 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
85 $scope.data = JSON.parse(j.data);
86 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
89 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 if($scope.data.microServiceConfigNameDictionaryDatas){
93 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceConfigNameDictionaryDatas);
97 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
99 $scope.data = JSON.parse(j.data);
100 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
103 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
105 $scope.data = JSON.parse(j.data);
106 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
109 for(var i = 0; i < inputModelList.length; i++){
110 if(typeof unique[inputModelList[i]] == "undefined"){
111 unique[inputModelList[i]] = "";
112 uniqueList.push(inputModelList[i]);
115 $scope.microServiceModelsDictionaryDatas = uniqueList;
118 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
120 $scope.data = JSON.parse(j.data);
121 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
124 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
126 $scope.data = JSON.parse(j.data);
127 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
130 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
132 $scope.data = JSON.parse(j.data);
133 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
138 $scope.attributeDatas = [{"attributes" : $scope.choices}];
139 addNewChoice = function(value) {
140 var isFoundInRuleData = false;
141 if(value != undefined){
142 if (value.startsWith('div.')){
143 value = value.replace('div.','');
146 var parentElement = document.getElementById("div."+value);
147 var div = document.getElementById(value+"@0");
149 var clone = div.cloneNode(true);
150 var addElement = parentElement.childElementCount;
151 clone.id = ''+value+'@'+addElement;
153 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
155 if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){
156 //Only append child if its value found in ruleData or edit mode
157 if($scope.temp.policy.ruleData[clone.id]){
158 clone.value = $scope.temp.policy.ruleData[clone.id];
159 isFoundInRuleData = true;
161 if(!isFoundInRuleData && isInitViewEdit){
164 if(!clone.className.includes("child_single")){
165 clone.className += ' child_single'; // here cloned is single element
167 document.getElementById("div."+value).appendChild(clone);
168 plainAttributeKeys.push(''+value+'@'+addElement);
170 }else{ // not view or edit
171 if(!clone.className.includes("child_single")){
172 clone.className += ' child_single'; // here cloned is single element
174 document.getElementById("div."+value).appendChild(clone);
175 plainAttributeKeys.push(''+value+'@'+addElement);
179 if(parentElement == null){
182 div = document.getElementById("div."+value+"@0");
185 if(!div.className.includes('children_group border')){
190 div.className += ' children_group border' + layer; // here is div with a group of children.
193 var childElement = parentElement.firstElementChild;
194 var countParent = parentElement.childElementCount;
195 var childElementString = childElement.innerHTML;
196 var find = value+"@0";
197 var re = new RegExp(find, 'g');
198 childElementString = childElementString.replace(re,value+'@' + countParent);
199 var clone = childElement.cloneNode(true);
200 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
201 var childId = parentElement.childNodes[ii].id;
202 if(ii = parentElement.childNodes.length){
203 var childnewId = childId.slice(0, -1);
204 var count = childId.slice(-1);
207 var countvalue = parseInt(count) + 1;
208 clone.id = childnewId+countvalue;
210 clone.innerHTML=childElementString;
211 document.getElementById("div."+value).appendChild(clone);
212 var selects = clone.getElementsByTagName("select");
213 var inputs = clone.getElementsByTagName("input");
214 var removeValues = [];
215 for(var i=0; i<inputs.length; i++){
216 plainAttributeKeys.push(inputs[i].id);
217 if ($scope.temp.policy.ruleData!=undefined){
218 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
219 if (checkValue!=undefined && checkValue != "undefined"){
220 if(checkValue == "false"){
221 document.getElementById(inputs[i].id).removeAttribute("checked");
223 else if(checkValue == "true"){
224 document.getElementById(inputs[i].id).setAttribute("checked", true);
226 document.getElementById(inputs[i].id).value = checkValue;
229 if(inputs[i].type == "checkbox"){
230 inputs[i].checked = false;
234 document.getElementById(inputs[i].id).removeAttribute("checked");
238 for(var i=0; i<selects.length; i++){
239 if ($scope.temp.policy.ruleData!=undefined){
240 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
241 if (checkValue!=undefined && checkValue!="undefined"){
242 if($scope.temp.policy.ruleData != null){
243 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
244 var option = document.createElement('option');
245 option.setAttribute('value', checkValue);
246 option.appendChild(document.createTextNode(checkValue));
247 document.getElementById(selects[i].id).appendChild(option);
248 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
249 plainAttributeKeys.push(selects[i].id);
252 plainAttributeKeys.push(selects[i].id);
255 plainAttributeKeys.push(selects[i].id);
259 for (var k=0; k<removeValues.length; k++){
260 var elem = document.getElementById(removeValues[k]);
261 elem.parentNode.removeChild(elem);
263 var ele = angular.element(document.getElementById("div."+value));
264 $compile(ele.contents())($scope)
270 removeChoice = function(value) {
271 if(value != undefined){
272 var c = document.getElementById("div."+value).childElementCount;
275 Notification.error("The original one is not removable.");
278 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
282 function findVal(object, key) {
284 Object.keys(object).some(function(k) {
289 if (object[k] && typeof object[k] === 'object') {
290 value = findVal(object[k], key);
291 return value !== undefined;
297 $scope.pullVersion = function(serviceName) {
298 if(serviceName != undefined){
299 var uuu = "policyController/getModelServiceVersioneData.htm";
300 var postData={policyData: serviceName};
305 contentType: 'application/json',
306 data: JSON.stringify(postData),
307 success : function(data){
308 $scope.$apply(function(){
309 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
312 error : function(data){
313 Notification.error("Error While Retriving the Template Layout Pattren.");
319 var splitEqual = '=';
320 var splitComma = ',';
321 var splitcolon = ':';
322 var splitEnum = "],";
323 var plainAttributeKeys = [];
325 var enumKeyList = [];
326 var dictionaryList = [];
327 var dictionaryNameList = [];
328 var isInitViewEdit = false;
329 $scope.addDataToFields = function(serviceName, version){
330 if(serviceName != null && version !=null){
331 var service=serviceName+"-v"+version;
332 var myNode = document.getElementById("DynamicTemplate");
333 myNode.innerHTML = '';
334 var uuu = "policyController/getDCAEMSTemplateData.htm";
335 var postData={policyData: service};
338 var dataOrderInfo = "";
340 booleanTrueElements = [];
342 document.getElementById("msPolicyloader").style.visibility = "visible";
348 contentType: 'application/json',
349 data: JSON.stringify(postData),
350 success : function(data){
352 document.getElementById("msPolicyloader").style.visibility = "hidden";
354 $scope.$apply(function(){
355 $scope.dcaeModelData = data[0].dcaeModelData;
356 $scope.dcaeJsonDate = data[0].jsonValue;
357 $scope.dataOrderInfo = null;
358 $scope.dataOrderInfo = data[0].dataOrderInfo;
360 if(data[0].allManyTrueKeys){
362 var attributes = $scope.dcaeModelData.attributes;
363 var refAttributes = $scope.dcaeModelData.ref_attributes;
364 var subAttributes = $scope.dcaeModelData.sub_attributes;
365 var headDefautlsData = data[0].headDefautlsData;
366 if(headDefautlsData != null){
367 $scope.temp.policy.onapName = headDefautlsData.onapName;
368 $scope.temp.policy.guard = headDefautlsData.guard;
369 $scope.temp.policy.riskType = headDefautlsData.riskType;
370 $scope.temp.policy.riskLevel = headDefautlsData.riskLevel;
371 $scope.temp.policy.priority = headDefautlsData.priority;
374 var annotation = $scope.dcaeModelData.annotation;
375 var dictionary = $scope.microServiceAttributeDictionaryDatas;
377 if (annotation == null || annotation.length<1){
378 $scope.isCheck = true;
380 $scope.isCheck = false;
381 var annoationList = annotation.split(splitComma);
382 for (k = 0; k < annoationList.length; k++){
383 var splitAnnotation = annoationList[k].split(splitEqual);
384 if (splitAnnotation[1].includes("matching-true")){
385 matching.push(splitAnnotation[0].trim());
391 if (dictionary!= null && dictionary.length>1){
392 for (m=0; m < dictionary.length; m += 1){
393 var valueCompare = dictionary[m].value;
394 var valueModel = dictionary[m].modelName;
395 var conpairService = serviceName;
396 if (valueModel.includes('-v')){
397 conpairService = service;
399 if(valueModel.localeCompare(conpairService) == 0){
400 dictionaryList.push(dictionary[m]);
401 if (!dictionaryNameList.includes(dictionary[m].name)){
402 dictionaryNameList.push(dictionary[m].name)
408 $scope.temp.policy.ruleGridData = [];
410 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
411 dataOrderInfo = $scope.dataOrderInfo;
414 $scope.jsonLayout($scope.dcaeJsonDate);
418 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ // If it's veiw or edit
419 isInitViewEdit = true;
422 // If ruleData contains extra elements created by clicked add button
423 if($scope.temp.policy.ruleData != null){
424 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
425 propNames.forEach(function(name) {
426 if(document.getElementById(name) != null){
427 if(document.getElementById(name).getAttribute("class") == "onoffswitch-checkbox"){
428 if($scope.temp.policy.ruleData[name] == "true"){
429 document.getElementById(name).setAttribute("checked", true);
432 document.getElementById(name).removeAttribute("checked");
438 var extraElements = data;
439 if(plainAttributeKeys != null){
440 for(var b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
441 var newValue = plainAttributeKeys[b].split("*");
442 for(var a = 0; a < data.length; a++){
443 if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
444 extraElements.splice(a, 1);
448 // --- Populate these extra elements created by clicked add button
449 for(var a = 0; a < extraElements.length; a++){
450 if(extraElements[a].includes("@")){
451 var index = extraElements[a].lastIndexOf("@");
453 // Get the number after @
454 var n = getNumOfDigits(extraElements[a], index+1);
455 var key = extraElements[a].substring(0, index+n+1); // include @x in key also by n+2 since x can be 1,12,etc
460 var unique = checkData.filter(onlyUnique);
461 var parentLevelElements = [];
463 // --- get all root level exta elments first (only contains one "@")
464 for(var i =0; i < unique.length; i++){
465 var firstIndex = unique[i].indexOf("@");
466 var lastIndex = unique[i].lastIndexOf("@");
467 if(firstIndex == lastIndex){
468 var newKey = unique[i].substring(0, firstIndex);
469 parentLevelElements.push(newKey);
470 unique[i] = "*processed*";
474 for (var i = 0; i < $scope.labelManyKeys.length; i++) {
475 var label = $scope.labelManyKeys[i];
476 if(parentLevelElements){
477 for (var k = 0; k < parentLevelElements.length; k++){
478 if(label == parentLevelElements[k]){
485 // if no layout order info, keep the process as before
487 for(var i =0; i < unique.length; i++){
488 if(unique[i] != "*processed*"){
489 var index = unique[i].lastIndexOf("@");
490 var newKey = unique[i].substring(0, index);
492 var newElement = document.getElementById("div."+unique[j]);
493 // check weather it has been created already
494 if(newElement != null){
497 newElement = document.getElementById(unique[j]);
498 if(newElement != null){
504 addNewChoice(newKey);
509 // ---reset to default
511 $scope.labelManyKeys = [];
513 // ---process none labels
514 for (var j = 0; j < unique.length; j++){
515 if(unique[j] != "*processed*"){
516 // if not created yet
517 if(!document.getElementById(unique[j])){
518 var index = unique[j].lastIndexOf("@");
519 var newKey = unique[j].substring(0, index);
521 var newElement = document.getElementById("div."+unique[j]);
523 // check weather it has been created already
524 if(newElement != null){
527 newElement = document.getElementById(unique[j]);
528 if(newElement != null){
532 // if not created yet,then create it.
533 addNewChoice(newKey);
543 var ele = angular.element(document.getElementById("DynamicTemplate"));
544 $compile(ele.contents())($scope);
546 isInitViewEdit = false;
549 error : function(data){
550 Notification.error("Error While Retriving the Template Layout Pattren.");
557 function getNumOfDigits(str_value, index){
558 // Get the number after @
559 var str = str_value.substring(index, str_value.length);
562 for (var x = 0; x < str.length; x++){
573 function getDictionary(attribute){
574 var dicName = attribute;
576 if(attribute.includes(":")){
577 dicName = attribute.split(":")[0];
580 var dictionaryRegExp = new RegExp(dicName);
581 listemunerateValues = [];
582 if (dictionaryRegExp.test(dictionaryNameList)) {
583 for (p=0; p < dictionaryList.length; p += 1) {
584 if (dicName == dictionaryList[p].name) {
585 listemunerateValues.push(dictionaryList[p].value);
589 return listemunerateValues;
592 function getList(attribute) {
593 var enumName = attribute;
595 if(attribute.includes(":")){
596 enumName = attribute.split(":")[0];
599 var baseEnum = $scope.dcaeModelData.enumValues;
601 if(baseEnum != null){
602 enumList = baseEnum.split(splitEnum);
605 var patternTest = new RegExp(enumName);
606 for (k=0; k < enumList.length; k += 1){
607 if(patternTest.test(enumList[k]) == true){
608 enumAttributes = enumList[k].trim();
613 enumAttributes = enumAttributes.replace("[", "");
614 enumAttributes = enumAttributes.replace("]", "");
615 enumAttributes = enumAttributes.replace(/ /g, '');
616 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
617 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
618 // enumKeyList.push(attribute);
619 return listemunerateValues;
625 function getBooleanList(){
626 var booleanList = [];
627 booleanList.push(true);
628 booleanList.push(false);
633 function isArray(arrayTest) {
634 return Object.prototype.toString.call(arrayTest) === '[object Array]';
638 $scope.layOutElementList = [];
639 $scope.layOutOnlyLableList = [];
641 var elementOrderNum = 0;
643 function deconstructJSON(layOutData, level , name) {
647 var stringValue = "java.lang.String";
648 var string = "string";
649 var intValue = "int";
650 var integerValue = "integer";
651 var double = "double";
652 var boolean = "boolean";
653 var baseLevel = level;
655 var attributekey = "";
657 if (name.length > 1){
658 label = label + name + '.';
661 for (key in layOutData) {
662 array = isArray(layOutData[key]);
664 if (!!layOutData[key] && typeof(layOutData[key])=="object") {
666 if (array==false && key!=="0"){
668 if($scope.dataOrderInfo){
669 var labelObject = {"label" : key, "level" : label, "array" : array};
670 // save it to the list
671 $scope.layOutOnlyLableList.push(labelObject);
675 $scope.labelLayout(label, key, array );
680 if (array == true && key!=0){
684 if (lableList.length > 0){
688 var newKey = lableList.pop();
690 if($scope.dataOrderInfo){
692 var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
693 // save it to the list
694 $scope.layOutOnlyLableList.push(labelObject);
698 $scope.labelLayout(baseLevel, newKey, array );
702 label = baseLevel + newKey + '@0.';
704 label = baseLevel + newKey + '.';
707 deconstructJSON(layOutData[key] , label, key);
709 var attirbuteLabel = label;
712 var isRequired = false;
713 if (layOutData[key].includes('defaultValue-')){
714 defaultValue = layOutData[key].split('defaultValue-')[1];
717 if (layOutData[key].includes('description-')){
718 description = layOutData[key].split('description-')[1];
724 attributekey = lableList.pop();
725 attirbuteLabel = baseLevel;
727 attributekey = key.split();
730 if (layOutData[key].includes('required-true')){
734 var subAttributes = $scope.dcaeModelData.subAttributes;
737 var jsonObject = JSON.parse(subAttributes);
739 var lablInfo = findVal(jsonObject, attributekey);
741 if(lablInfo.includes('required-true')){
744 if(lablInfo.includes('defaultValue-')){
745 defaultValue = lablInfo.split('defaultValue-')[1];
748 if(lablInfo.includes('description-')){
749 description = lablInfo.split('description-')[1];
753 var allkeys = Object.keys(jsonObject);
755 for (var k = 0; k < allkeys.length; k++) {
756 var keyValue = allkeys[k];
757 if(jsonObject[keyValue]){
758 var tempObject = jsonObject[keyValue];
759 if(tempObject && tempObject[key]){
760 if (tempObject[key].includes('required-true')){
764 if(tempObject[key].includes('defaultValue-')){
765 defaultValue = tempObject[key].split('defaultValue-')[1];
768 if(tempObject[key].includes('description-')){
769 description = tempObject[key].split('description-')[1];
779 var elementObject = {};
780 switch (layOutData[key].split(splitcolon)[0]){
784 if($scope.dataOrderInfo){
786 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text", "description":description};
787 $scope.layOutElementList.push(elementObject);
789 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
794 if($scope.dataOrderInfo){
796 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number" , "description":description};
797 $scope.layOutElementList.push(elementObject);
799 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
803 if($scope.dataOrderInfo){
805 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double", "description":description};
806 $scope.layOutElementList.push(elementObject);
808 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
812 if($scope.dataOrderInfo){
814 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"boolean", "description":description};
815 $scope.layOutElementList.push(elementObject);
817 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
821 if (layOutData[key].includes('dictionary-')){
822 var list = getDictionary(layOutData[key].split('dictionary-')[1]);
824 // --- get dropdown values from enumValues
825 var list = getList(layOutData[key]);
827 if (list.length===0){ // not dropdown element
828 if($scope.dataOrderInfo){
830 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description};
831 $scope.layOutElementList.push(elementObject);
834 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
837 if($scope.dataOrderInfo){
839 elementObject = {"id": elementOrderNum, "attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "list":list, "type":"dropBox", "description":description};
840 $scope.layOutElementList.push(elementObject);
842 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
852 $scope.validContionalRequired = function(parentId) {
853 var c = document.getElementById(parentId).children;
855 var hasValue = false;
856 for (i = 0; i < c.length; i++) {
857 if(c[i].getAttribute("data-conditional")){
858 if(c[i].value != null && c[i].value.trim() != ""){
864 for (i = 0; i < c.length; i++) {
865 if(c[i].getAttribute("data-conditional")){
867 c[i].setAttribute("required", true);
869 c[i].removeAttribute("required");
875 $scope.jsonLayout = function(layOutData){
877 deconstructJSON(layOutData , "", "");
879 var orderValue = $scope.dataOrderInfo;
880 var layOutElementList = $scope.layOutElementList;
881 var labelList = $scope.layOutOnlyLableList;
885 $scope.layOutElementList = [];
886 $scope.layOutOnlyLableList = [];
888 // Only layout in order if order info provided
891 if(orderValue.includes("[")){
892 orderValue = orderValue.replace("[", "") ;
893 orderValue = orderValue.replace("]", "") ;
896 orderValue = orderValue.split(',') ;
898 for (var i = 0; i < orderValue.length; i++) {
899 var key = orderValue[i].trim();
901 // --- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
903 for (var k = 0; k < labelList.length; k++){
905 var label = labelList[k].label.toString().trim();
906 var level = labelList[k].level.toString().trim();
907 var array = labelList[k].array;
910 $scope.labelLayout(level, label, array);
911 // in case to have duplicate label names
912 labelList[k].label = "*processed*";
917 // --- then layout each element based on its order defined in YAML file
918 for (var j = 0; j < layOutElementList.length; j++) {
920 var attributekey = layOutElementList[j].attributekey.toString().trim();
922 if(key == attributekey){
924 var attirbuteLabel = layOutElementList[j].attirbuteLabel.toString().trim();
925 var defaultValue = layOutElementList[j].defaultValue.toString().trim();
926 var description = layOutElementList[j].description;
927 var isRequired = layOutElementList[j].isRequired;
929 if (layOutElementList[j].type == "dropBox"){
930 $scope.dropBoxLayout(attirbuteLabel, attributekey, layOutElementList[j].array, defaultValue, layOutElementList[j].list, isRequired, description);
933 $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type, description);
937 // in case to have duplicate attribute names
938 layOutElementList[j].attributekey = "*processed*";
947 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType, description){
948 $scope.temp.policy.ruleGridData.push(attibuteKey);
949 var br = document.createElement("BR");
951 var label = document.createElement("Label");
952 var labeltext = null;
953 var requiredLabName = "";
954 if (matching.includes(attibuteKey)){
955 labeltext = document.createTextNode(attibuteKey + "*!");
956 isRequired = true; // set required as true for matching element
959 requiredLabName = attibuteKey + " * ";
960 labeltext = document.createTextNode(requiredLabName);
962 labeltext = document.createTextNode(attibuteKey);
967 var divID = labelValue;
969 if (labelValue.length < 1){
970 divID = "DynamicTemplate";
971 }else if (labelValue.endsWith('.')){
972 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
975 label.appendChild(labeltext);
977 var textField = document.createElement("INPUT");
979 textField.setAttribute("class" , "form-control");
981 if(dataType == "double"){
982 textField.setAttribute("type" , "number");
983 textField.setAttribute("step" , "any");
985 }else if(dataType == "boolean"){ // gw1218 testing boolean
986 var booleanDiv = document.createElement("div");
988 booleanDiv.setAttribute("class" , "onoffswitch");
990 // var checkField = document.createElement("INPUT");
991 textField.setAttribute("type" , "checkbox");
992 textField.setAttribute("name" , "onoffswitch");
993 textField.setAttribute("class" , "onoffswitch-checkbox");
994 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
995 if(defaultValue.substring(0,defaultValue.indexOf(":")) == "true") {
996 textField.setAttribute("checked" , true);
998 textField.removeAttribute("checked");
1000 textField.setAttribute("ng-click" , "validateOnAndOff('"+labelValue +attibuteKey+"', $event)");
1001 var booleanlabel = document.createElement("Label");
1002 booleanlabel.setAttribute("class" , "onoffswitch-label");
1003 booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+'');
1005 var span1 = document.createElement("span");
1006 span1.setAttribute("class" , "onoffswitch-inner");
1008 var span2 = document.createElement("span");
1009 span2.setAttribute("class" , "onoffswitch-switch");
1012 booleanlabel.appendChild(span1);
1013 booleanlabel.appendChild(span2);
1014 booleanDiv.appendChild(textField);
1015 booleanDiv.appendChild(booleanlabel);
1017 document.getElementById(divID).appendChild(label);
1018 document.getElementById(divID).appendChild(booleanDiv);
1022 textField.setAttribute("type" , dataType);
1029 if(dataType != "boolean"){
1030 textField.setAttribute("style" , "width:300px;");
1031 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1032 if(description && description != "null"){
1033 textField.setAttribute("title", description);
1039 if(attributeManyKey){
1040 checkKey = labelValue + attibuteKey+'@0';
1041 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
1042 var divTag = document.createElement("div");
1043 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
1044 var addButton = document.createElement("BUTTON");
1045 var buttonaddLabel = document.createTextNode("+");
1046 addButton.appendChild(buttonaddLabel);
1047 addButton.setAttribute("id", labelValue + attibuteKey);
1048 addButton.setAttribute("class", "btn btn-add-remove");
1049 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + attibuteKey+'");');
1050 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1051 var removeButton = document.createElement("BUTTON");
1052 var buttonremoveLabel = document.createTextNode("-");
1053 removeButton.appendChild(buttonremoveLabel);
1054 removeButton.setAttribute("class", "btn btn-add-remove");
1055 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue + attibuteKey+'");');
1056 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1057 document.getElementById(divID).appendChild(addButton);
1058 document.getElementById(divID).appendChild(removeButton);
1059 document.getElementById(divID).appendChild(label);
1060 id = "div."+labelValue+attibuteKey;
1061 // var divTag = document.createElement("div");
1062 divTag.setAttribute("id", id);
1063 document.getElementById(divID).appendChild(divTag);
1064 textField.className += ' first_child';
1066 textField.setAttribute("required", "true");
1069 divTag.appendChild(textField);
1070 document.getElementById(divID).appendChild(divTag);
1072 }else if (dataType != "boolean"){
1073 checkKey = labelValue + attibuteKey;
1074 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1075 if(document.getElementById(divID).hasAttribute('required') || !document.getElementById(divID).hasAttribute('data-conditional')){
1076 if(requiredLabName.includes("*") || isRequired){
1077 textField.setAttribute("required", "true");
1079 }else if (document.getElementById(divID).hasAttribute('data-conditional')){
1080 if(requiredLabName.includes("*")){
1081 var requiredNode = document.createElement('span');
1082 requiredNode.setAttribute("class", "mstooltip");
1083 requiredNode.textContent = "?";
1084 label.appendChild(requiredNode);
1086 var requiredNodeToolTip = document.createElement('span');
1087 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1088 requiredNodeToolTip.textContent = "Conditional Required";
1089 requiredNode.appendChild(requiredNodeToolTip);
1091 textField.setAttribute("data-conditional", divID);
1092 textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1096 document.getElementById(divID).appendChild(label);
1097 document.getElementById(divID).appendChild(textField);
1098 document.getElementById(divID).appendChild(br);
1102 if(dataType != "boolean" && divID.includes("@0") && divID.includes("div.")){
1103 var firstChild_Id = divID.split("@0")[0];
1104 var firstChild_element = document.getElementById(firstChild_Id);
1105 if(firstChild_element){
1107 if(!firstChild_element.className.includes('children_group border')){
1112 firstChild_element.className += ' children_group border' + layer; // here is div with a group of children.
1117 if(dataType != "boolean" && defaultValue.length > 0){
1118 if(defaultValue.includes(":")){
1119 defaultValue = defaultValue.split(":")[0];
1120 if(defaultValue === "NA") {
1124 if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
1125 document.getElementById(checkKey).value = defaultValue;
1129 if($scope.temp.policy.ruleData != null){
1130 // document.getElementById(checkKey).value =
1131 // $scope.temp.policy.ruleData[checkKey];
1132 if (attributeManyKey){
1133 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
1134 if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){
1135 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
1138 if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
1139 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1144 if (dataType != "boolean"){
1145 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
1147 plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean");
1151 $scope.validateOnAndOff = function(id , value) {
1152 console.log(id, value);
1153 if (value.target.checked) {
1154 document.getElementById(id).setAttribute("checked", true);
1156 document.getElementById(id).removeAttribute("checked");
1160 $scope.labelManyKeys = [];
1161 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
1162 var label = document.createElement("Label")
1163 var divID = labelValue;
1164 if (labelValue.endsWith('.')){
1165 var workingLabel = labelValue.substring(0, labelValue.length-1);
1167 var workingLabel = labelValue;
1169 if (labelValue.length < 1){
1170 divID = "DynamicTemplate";
1171 } else if (labelValue.endsWith('.')){
1172 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1175 var subAttributes = $scope.dcaeModelData.subAttributes;
1176 var jsonObject = JSON.parse(subAttributes);
1177 var lablInfo = findVal(jsonObject, lableName);
1179 var required = null;
1181 if(typeof lablInfo === 'string' ){
1182 if(lablInfo.includes("required-true")){
1185 }else if (lablInfo.includes("required-false")){
1191 var labeltext = document.createTextNode(lableName + star);
1193 label.appendChild(labeltext);
1197 var addButton = document.createElement("BUTTON");
1198 var buttonLabel = document.createTextNode("+");
1199 addButton.appendChild(buttonLabel);
1200 addButton.setAttribute("class", "btn btn-add-remove");
1201 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + lableName+'");');
1202 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1203 var removeButton = document.createElement("BUTTON");
1204 var buttonremoveLabel = document.createTextNode("-");
1205 removeButton.appendChild(buttonremoveLabel);
1206 removeButton.setAttribute("class", "btn btn-add-remove");
1207 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue +lableName+'");');
1208 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1209 document.getElementById(divID).appendChild(addButton);
1210 document.getElementById(divID).appendChild(removeButton);
1211 document.getElementById(divID).appendChild(label);
1212 var id = "div."+labelValue+lableName;
1213 var divTag = document.createElement("div");
1214 divTag.setAttribute("id", id);
1215 document.getElementById(divID).appendChild(divTag);
1217 var divTag = document.createElement("div");
1218 divTag.setAttribute("id", id +'@0');
1220 if(!divTag.className.includes('children_group border')){
1225 divTag.className += ' children_group border' + layer; // here is div with a group of children.
1228 divTag.setAttribute("required", required);
1229 }else if(required == false){
1230 divTag.setAttribute("data-conditional", "yes");
1233 document.getElementById(id).appendChild(divTag);
1235 $scope.labelManyKeys.push(lableName);
1238 var divTag = document.createElement("div");
1239 divTag.setAttribute("id", "div."+labelValue+lableName);
1241 if(!divTag.className.includes('children_group border')){
1246 divTag.className += ' children_group border' + layer; // here is div with a group of children.
1249 divTag.setAttribute("required", required);
1250 }else if(required == false){
1251 divTag.setAttribute("data-conditional", "yes");
1253 document.getElementById(divID).appendChild(label);
1254 document.getElementById(divID).appendChild(divTag);
1258 $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){
1259 var br = document.createElement("BR");
1261 if (labelLevel.length < 1){
1262 var divID = "DynamicTemplate";
1263 } else if (labelLevel.endsWith('.')){
1264 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1268 var label = document.createElement("Label")
1270 var refAttributes = $scope.dcaeModelData.refAttributes;
1271 if(isRequired != true && refAttributes){ // check refAttributes also
1272 var refAttributesList = refAttributes.split(splitComma);
1273 for (k = 0; k < refAttributesList.length; k++){
1274 var refAttribute = refAttributesList[k].split(splitEqual);
1275 if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
1281 if (matching.includes(attributeName)){
1282 var labeltext = document.createTextNode(attributeName + "*!");
1283 label.appendChild(labeltext);
1284 isRequired = true; // set required as true for matching element
1286 var labeltext = document.createTextNode(attributeName);
1288 var requiredLabName = attributeName+ " * ";
1289 labeltext = document.createTextNode(requiredLabName);
1291 labeltext = document.createTextNode(attributeName);
1294 label.appendChild(labeltext);
1296 label.appendChild(labeltext);
1297 // if this field is required, but its parent is not required
1298 if(isRequired && document.getElementById(divID).hasAttribute('data-conditional')){
1299 var requiredNode = document.createElement('span');
1300 requiredNode.setAttribute("class", "mstooltip");
1301 requiredNode.textContent = "?";
1302 label.appendChild(requiredNode);
1304 var requiredNodeToolTip = document.createElement('span');
1305 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1306 requiredNodeToolTip.textContent = "Conditional Required";
1307 requiredNode.appendChild(requiredNodeToolTip);
1311 var listField = document.createElement("SELECT");
1312 listField.setAttribute("class" , "form-control");
1313 listField.setAttribute("style" , "width:300px;");
1314 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1316 if(description && description != "null"){
1317 listField.setAttribute("title", description);
1321 if(document.getElementById(divID).hasAttribute('data-conditional')){
1322 listField.setAttribute("data-conditional", divID);
1323 listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1325 listField.setAttribute("required", true);
1328 if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element
1329 var optionFirst = document.createElement('option');
1330 var optionValue = "";
1331 if($scope.temp.policy.ruleData != null){
1332 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1333 optionValue = $scope.temp.policy.ruleData[labelLevel + attributeName];
1336 optionFirst.setAttribute('value', optionValue);
1337 optionFirst.appendChild(document.createTextNode(optionValue));
1338 listField.appendChild(optionFirst);
1340 var ruleFormationCheck = false;
1341 if(listemunerateValues.length !== 0 && typeof listemunerateValues[0] == "string" && listemunerateValues[0].includes("dictionary:")) {
1342 var ruleCheck = listemunerateValues[0].split("&");
1343 var dictParams = ruleCheck[0].split(":");
1344 var dictParamsSplit = dictParams[1].split("@");
1345 if (ruleCheck[1] != undefined && ruleCheck[1] == 'Rule') {
1346 ruleFormationCheck = true;
1348 PolicyAppService.getData(dictParamsSplit[0]).then(function (data) {
1350 $scope.data = JSON.parse(j.data);
1351 $scope.listDictionarys = JSON.parse($scope.data[dictParamsSplit[1]]);
1352 for (i=0; i < $scope.listDictionarys.length; i += 1) {
1353 option = document.createElement('option');
1354 option.setAttribute('value', $scope.listDictionarys[i]);
1355 option.appendChild(document.createTextNode($scope.listDictionarys[i]));
1356 listField.appendChild(option);
1362 for (i=0; i < listemunerateValues.length; i += 1) {
1363 if(typeof listemunerateValues[i] == "string" && listemunerateValues[i].includes("equal-sign")){
1364 listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','=');
1367 option = document.createElement('option');
1368 option.setAttribute('value', listemunerateValues[i]);
1369 option.appendChild(document.createTextNode(listemunerateValues[i]));
1370 option.setAttribute('value', listemunerateValues[i]);
1371 listField.appendChild(option);
1374 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1376 enumKeyList.push(attributeName);
1378 document.getElementById(divID).appendChild(label);
1379 document.getElementById(divID).appendChild(br);
1382 document.getElementById(divID).appendChild(listField).multiple = true;
1383 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1385 document.getElementById(divID).appendChild(listField).multiple = false;
1386 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1389 if(defaultValue.includes(':')){
1390 defaultValue = defaultValue.split(':')[0];
1392 var location = listemunerateValues.indexOf(defaultValue);
1393 document.getElementById(labelLevel +attributeName).options[location+1].selected = true;
1397 if (ruleFormationCheck) {
1398 var optionInput = document.createElement("INPUT");
1399 optionInput.setAttribute("type" , "text");
1400 optionInput.setAttribute("id" , ''+ labelLevel + attributeName + '.input');
1401 optionInput.setAttribute("name" , "ruleName");
1402 optionInput.setAttribute("value" , " ");
1403 optionInput.setAttribute("style" , "width:300px;");
1404 optionInput.setAttribute("ng-disabled" , "temp.policy.readOnly");
1405 optionInput.removeAttribute("required");
1407 document.getElementById(divID).appendChild(optionInput);
1409 var optionButton = document.createElement("BUTTON");
1410 optionButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1411 var buttonLabel = document.createTextNode("+");
1412 optionButton.appendChild(buttonLabel);
1413 optionButton.setAttribute("class", "btn btn-add-remove");
1414 optionButton.setAttribute("onclick" , 'addDynamicOptions("'+ labelLevel + attributeName + '");');
1415 optionButton.removeAttribute("required");
1418 document.getElementById(divID).appendChild(optionButton);
1419 document.getElementById(divID).appendChild(br);
1422 if($scope.temp.policy.ruleData != null){
1424 document.getElementById(labelLevel +attributeName).options[0].selected = false;
1425 for (i=0; i < listemunerateValues.length; i += 1) {
1426 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
1427 if (testValue === undefined){
1428 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
1430 var location = listemunerateValues.indexOf(testValue);
1432 document.getElementById(labelLevel +attributeName).options[location].selected = true;
1436 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1437 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
1443 addDynamicOptions = function(id) {
1444 var option = document.createElement("option");
1445 var value = document.getElementById(id+".input").value;
1446 option.setAttribute('value', value);
1447 option.appendChild(document.createTextNode(value));
1448 document.getElementById(id).options.add(option);
1449 document.getElementById(id+".input").value = "";
1452 function onlyUnique(value, index, self) {
1453 return self.indexOf(value) === index;
1456 $scope.savePolicy = function(policy){
1457 if(policy.itemContent != undefined){
1458 $scope.refreshCheck = true;
1459 $scope.policyNavigator = policy.itemContent;
1460 policy.itemContent = "";
1462 $scope.savebutton = false;
1465 var jsonPolicy = {};
1466 if(plainAttributeKeys != null){
1467 for(a = 0; a < plainAttributeKeys.length; a++){
1468 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1469 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1470 var key = splitPlainAttributeKey[0];
1471 if(searchElement == null){
1472 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1473 key = splitPlainAttributeKey[0]+'@0';
1474 }else if (searchElement.nodeName == 'BUTTON'){
1475 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1476 key = splitPlainAttributeKey[0]+'@0';
1478 if(searchElement != null){
1479 var keySplit = key.split(dot);
1480 var elumentLocation = keySplit.length;
1482 if (elumentLocation > 1){
1483 enumKey = keySplit[keySplit.length - 1];
1485 // check it is undefined or not
1486 if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){
1487 if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){
1488 var multiSlect = [];
1489 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1490 multiSlect.push(searchElement.selectedOptions[i].value);
1492 jsonPolicy[key]= multiSlect;
1494 if(splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1] == "boolean"){
1495 jsonPolicy[key]= false;
1496 for(var i=0; i<booleanTrueElements.length; i++){
1497 if(booleanTrueElements[i] == key){
1498 jsonPolicy[key]= true;
1503 jsonPolicy[key]= searchElement.value;
1507 if(searchElement.value != null){
1508 if(searchElement.parentElement.children[0].checked == true){
1509 jsonPolicy[key]= searchElement.checked;
1512 jsonPolicy[key]= window.btoa(searchElement.value);
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 $scope.temp.policy.readOnly = 'true';
1541 $scope.savebutton = true;
1542 Notification.success("Policy Saved Successfully.");
1543 }else if ($scope.data == 'PolicyExists'){
1544 $scope.savebutton = true;
1545 Notification.error("Policy Already Exists with Same Name in Scope.");
1549 error : function(data){
1550 Notification.error("Error Occured while saving Policy.");
1555 var booleanTrueElements = [];
1556 $scope.validatePolicy = function(policy){
1557 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 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1564 var key = splitPlainAttributeKey[0];
1565 if(searchElement == null){
1566 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1567 key = splitPlainAttributeKey[0]+'@0';
1568 }else if (searchElement.nodeName == 'BUTTON'){
1569 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1570 key = splitPlainAttributeKey[0]+'@0';
1572 if(searchElement != null){
1573 if (enumKeyList.indexOf(key) != -1){
1574 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
1575 var multiSlect = [];
1576 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1577 multiSlect.push(searchElement.selectedOptions[i].value);
1579 jsonPolicy[key]= multiSlect;
1581 jsonPolicy[key]= searchElement.value;
1583 if(searchElement.getAttribute("required")){
1584 if(!searchElement.value){
1589 if(searchElement.value != null){
1590 if(searchElement.parentElement.children[0].checked == true){
1591 jsonPolicy[key]= searchElement.checked;
1594 jsonPolicy[key]= searchElement.value;
1596 if(searchElement.getAttribute("required")){
1597 if(!searchElement.value){
1607 var checkedValue = $('.onoffswitch-checkbox:checked').val();
1609 var x = document.getElementsByClassName("onoffswitch-checkbox");
1613 for(var i=0; i<x.length; x++){
1614 booleanTrueElements.push(x[i].id)
1618 var uuu = "policyController/validate_policy.htm";
1621 if($scope.isCheck == true){
1622 if(("configName" in policy) == false){
1623 Notification.error("Validation Failed: configName is required");
1624 $scope.savebutton = true;
1627 if(("location" in policy) == false){
1628 Notification.error("Validation Failed: location is required");
1629 $scope.savebutton = true;
1632 if(("uuid" in policy) == false){
1633 Notification.error("Validation Failed: uuid is required");
1634 $scope.savebutton = true;
1637 if(("policyScope" in policy) == false){
1638 Notification.error("Validation Failed: policyScope is required");
1639 $scope.savebutton = true;
1644 var postData={policyData: policy, policyJSON : jsonPolicy};
1649 contentType: 'application/json',
1650 data: JSON.stringify(postData),
1651 success : function(data){
1652 $scope.$apply(function(){
1653 $scope.validateData = data.data.replace(/\"/g, "");
1654 $scope.data=data.data.substring(1,8);
1655 var size = data.data.length;
1656 if($scope.data == 'success'){
1657 Notification.success("Validation Success.");
1658 $scope.savebutton = false;
1660 var displayWarning = data.data.substring(19,size - 1);
1661 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
1662 document.getElementById("validate").style.color = "white";
1663 document.getElementById("validate").style.backgroundColor = "skyblue";
1666 Notification.error("Validation Failed.");
1667 document.getElementById("validate").innerHTML = $scope.validateData;
1668 document.getElementById("validate").style.color = "white";
1669 document.getElementById("validate").style.backgroundColor = "red";
1670 $scope.savebutton = true;
1675 error : function(data){
1676 Notification.error("Validation Failed.");
1677 $scope.savebutton = true;
1683 $('.Switch').click(function() {
1684 // Check If Enabled (Has 'On' Class)
1685 if ($(this).hasClass('On')){
1686 // Try To Find Checkbox Within Parent Div, And Check It
1687 $(this).parent().find('input:checkbox').attr('checked', true);
1688 // Change Button Style - Remove On Class, Add Off Class
1689 $(this).removeClass('On').addClass('Off');
1690 } else { // If Button Is Disabled (Has 'Off' Class)
1691 // Try To Find Checkbox Within Parent Div, And Uncheck It
1692 $(this).parent().find('input:checkbox').attr('checked', false);
1693 // Change Button Style - Remove Off Class, Add On Class
1694 $(this).removeClass('Off').addClass('On');
1697 // Loops Through Each Toggle Switch On Page
1698 $('.Switch').each(function() {
1699 // Search of a checkbox within the parent
1700 if ($(this).parent().find('input:checkbox').length){
1702 // If checkbox doesnt have the show class then hide it
1703 if (!$(this).parent().find('input:checkbox').hasClass("show")){
1704 $(this).parent().find('input:checkbox').hide(); }
1706 // Look at the checkbox's checkked state
1707 if ($(this).parent().find('input:checkbox').is(':checked')){
1708 // Checkbox is not checked, Remove the On Class and Add the Off Class
1709 $(this).removeClass('On').addClass('Off');
1711 // Checkbox Is Checked Remove Off Class, and Add the On Class
1712 $(this).removeClass('Off').addClass('On');