Remove unused vars and methods
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / DCAEMicroServicePolicyController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
22     $("#dialog").hide();
23     
24     $scope.policyNavigator;
25     $scope.isCheck = false;
26     $scope.savebutton = true;
27     $scope.refreshCheck = false;
28     
29     var layer = 0;
30     
31     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
32         $scope.temp.policy = {
33                         policyType : "Config",
34                         configPolicyType : "Micro Service"
35         }
36     }
37     
38     $scope.refresh = function(){
39         if($scope.refreshCheck){
40                 $scope.policyNavigator.refresh();
41         }
42         $scope.modal('createNewPolicy', true);
43         $scope.temp.policy = "";
44     };
45     
46     $scope.modal = function(id, hide) {
47         return $('#' + id).modal(hide ? 'hide' : 'show');
48     };
49     
50     $('#ttlDate').datepicker({
51         dateFormat: 'dd/mm/yy',
52         changeMonth: true,
53         changeYear: true,
54         onSelect: function(date) {
55                 angular.element($('#ttlDate')).triggerHandler('input');
56         }
57     });
58     
59         if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly  != undefined){
60                 if ($scope.temp.policy.configName == undefined){
61                         $scope.isCheck = false;
62                 }else{
63                         $scope.isCheck = true;
64                 }
65         }else {
66                 $scope.isCheck = false;
67         }
68                 
69         PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
70                 var j = 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);
75         }, function (error) {
76                 console.log("failed");
77         });
78
79         PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
80                 var j = 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);
85         }, function (error) {
86                 console.log("failed");
87         });
88
89         PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
90                 var j = 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);
95         }, function (error) {
96                 console.log("failed");
97         });
98
99         PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
100                 var j = 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);
106                 }
107                 console.log($scope.microServiceCongigNameDictionaryDatas);
108         }, function (error) {
109                 console.log("failed");
110         });
111
112         PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
113                 var j = 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");
120         });
121
122         PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
123                 var j = data;
124                 $scope.data = JSON.parse(j.data);
125                 console.log($scope.data);
126                 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
127                 var unique = {};
128                 var uniqueList = [];
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]);
133                         }
134                 }
135                 $scope.microServiceModelsDictionaryDatas = uniqueList;
136                 console.log($scope.microServiceModelsDictionaryDatas);
137         }, function (error) {
138                 console.log("failed");
139         });
140
141         PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
142                 var j = 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");
149         });
150
151         PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
152                 var j = 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");
159         });
160
161         PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
162                 var j = 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");
169         });
170             
171
172          $scope.choices = [];
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.','');
180                         }
181                         
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");
186                         if(div != null){
187                                 var clone = div.cloneNode(true); 
188                                 var addElement = parentElement.childElementCount;
189                                 clone.id = ''+value+'@'+addElement;
190                                 clone.value = '';
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;
196                                                 }
197                                                 console.log("  clone.value :" +  clone.value);
198                                                 console.log(" clone.id :" + clone.id);
199                                                 if(!isFoundInRuleData && isInitViewEdit){
200                                                         return;
201                                                 }
202                                                 if(!clone.className.includes("child_single")){
203                                                    clone.className += ' child_single'; //here cloned is single element
204                                                 }
205                                                 document.getElementById("div."+value).appendChild(clone);
206                                                 plainAttributeKeys.push(''+value+'@'+addElement);
207                                         }
208                                 }else{ //not view or edit
209                                         if(!clone.className.includes("child_single")){
210                                             clone.className += ' child_single'; //here cloned is single element
211                                         }
212                                         document.getElementById("div."+value).appendChild(clone);
213                                         plainAttributeKeys.push(''+value+'@'+addElement);
214                                 }
215                         }else{
216                                 
217                                 if(parentElement == null){
218                                         return;
219                                 }
220                                 div = document.getElementById("div."+value+"@0");
221                                 if(div){
222                                         
223                                         if(!div.className.includes('children_group border')){
224                                                 layer++;
225                                                 if(layer > 4){ 
226                                                         layer = 1
227                                                 }
228                                     div.className += ' children_group border' + layer; //here is div with a group of children.
229                                         }
230                                 }
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);
243                             }
244                         }
245                                 var countvalue = parseInt(count) + 1;
246                                 clone.id = childnewId+countvalue;
247                                 clone.value = '';
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);
261                                                 } else {
262                                                         plainAttributeKeys.push(inputs[i].id);
263                                                 }
264                                         }else {
265                                                 plainAttributeKeys.push(inputs[i].id);
266                                         }
267                                 }
268                                 
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);
281                                                         }
282                                                 } else {
283                                                         plainAttributeKeys.push(selects[i].id);
284                                                 }
285                                         }else {
286                                                 plainAttributeKeys.push(selects[i].id);
287                                         }
288                                 }
289                                 
290                                 for (var k=0; k<removeValues.length; k++){
291                                         var elem = document.getElementById(removeValues[k]);
292                                         elem.parentNode.removeChild(elem);
293                                 }
294                                 var ele = angular.element(document.getElementById("div."+value));
295                         $compile(ele.contents())($scope)
296                         }
297                  }
298          };
299          
300         
301          removeChoice = function(value) {
302                  console.log(value);
303                  if(value != undefined){
304                          var c = document.getElementById("div."+value).childElementCount;
305                          
306                          if(c == 1){
307                                  Notification.error("The original one is not removable.");
308                                  return;
309                          }      
310                          document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);     
311                  }
312          };
313          
314          function findVal(object, key) {
315                     var value;
316                     Object.keys(object).some(function(k) {
317                         if (k === key) {
318                             value = object[k];
319                             return true;
320                         }
321                         if (object[k] && typeof object[k] === 'object') {
322                             value = findVal(object[k], key);
323                             return value !== undefined;
324                         }
325                     });
326                     return value;
327         }
328          
329          $scope.pullVersion = function(serviceName) {
330                  console.log(serviceName);
331                  if(serviceName != undefined){
332                          var uuu = "policyController/getModelServiceVersioneData.htm";
333                          var postData={policyData: serviceName};
334                          $.ajax({
335                                  type : 'POST',
336                                  url : uuu,
337                                  dataType: 'json',
338                                  contentType: 'application/json',
339                                  data: JSON.stringify(postData),
340                                  success : function(data){
341                                          $scope.$apply(function(){
342                                                  $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
343                                          });
344                                  },
345                                  error : function(data){
346                                          alert("Error While Retriving the Template Layout Pattren.");
347                                  }
348                          });             
349                  }
350          };
351     
352         var splitEqual = '=';
353         var splitComma = ',';
354         var splitcolon = ':';
355         var splitEnum = "],";
356         var plainAttributeKeys = [];
357         var matching = [];
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};
369             
370             console.log("service: " +service);
371             
372             var dataOrderInfo = "";
373             
374             booleanTrueElements = [];
375
376             document.getElementById("msPolicyloader").style.visibility = "visible";
377             
378             $.ajax({
379                 type : 'POST',
380                 url : uuu,
381                 dataType: 'json',
382                 contentType: 'application/json',
383                 data: JSON.stringify(postData),
384                 success : function(data){
385                         
386                         document.getElementById("msPolicyloader").style.visibility = "hidden";
387                         
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);   
395                         
396                         if(data[0].allManyTrueKeys){
397                                 console.log("$scope.allManyTrueKeys: " + $scope.allManyTrueKeys);
398                         }
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;
413                         }
414                         
415                         var annotation = $scope.dcaeModelData.annotation;
416                         var dictionary = $scope.microServiceAttributeDictionaryDatas;
417
418                         if (annotation == null || annotation.length<1){
419                                 $scope.isCheck = true;
420                         }else {
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());
427                                         }
428                                 }
429
430                         }
431
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;
439                                         }
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)
445                                                 }
446                                         }
447                                 }
448                         }
449
450                                 $scope.temp.policy.ruleGridData = [];
451                                 
452                                 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
453                                         dataOrderInfo = $scope.dataOrderInfo;
454                                 }
455                                 
456                                 $scope.jsonLayout($scope.dcaeJsonDate);
457                                 
458                     });
459                     
460                     if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){  // If it's veiw or edit
461                         isInitViewEdit = true;
462                         var checkData = [];
463                         var data = [];
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) {
469                                                 data.push(name);
470                                         });
471                                         
472                                         var extraElements = data;
473                                         
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);
480                                                                         }
481                                                                 }
482                                                 }
483                                                 
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("@");
488                                                                 if(index > 0){
489                                                                     // Get the number after @
490                                                                     var n = getNumOfDigits(extraElements[a], index+1);
491                                                                                         
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);
494                                                                         checkData.push(key);
495                                                                 }
496                                                         }
497                                                 }
498                                                 var unique = checkData.filter(onlyUnique);
499                                                 var parentLevelElements = [];
500                                                 if(unique){
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*";
510                                                                 }
511                                                         }                                                       
512                                                 }
513                                                 
514                                                 
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]){
520                                                                         addNewChoice(label);
521                                                                 }
522                                                         }                                                                       
523                                                     }                                                                           
524                                                 }
525                                                 
526                                                 //if no layout order info, keep the process as before
527                                                 if(!dataOrderInfo){
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);       
533                                                                         
534                                                                         var newElement = document.getElementById("div."+unique[j]);
535                                                                         //check weather it has been created already
536                                                 if(newElement != null){
537                                                         continue;
538                                                 }else{
539                                                         newElement = document.getElementById(unique[j]);
540                                                         if(newElement != null){
541                                                                 continue;
542                                                         }
543                                                 } 
544                                                 
545                                                                         if(newKey){
546                                                                                 addNewChoice(newKey);
547                                                                         }
548                                                                 }
549                                                         }
550                                                 }else{
551                                                                 //---reset to default
552                                                                 dataOrderInfo = [];
553                                                                 $scope.labelManyKeys = [];
554                                                                 
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);
562                                                                                         
563                                                                                         var newElement = document.getElementById("div."+unique[j]);
564                                                                                         
565                                                                                         //check weather it has been created already
566                                                         if(newElement != null){
567                                                                 continue;
568                                                         }else{
569                                                                 newElement = document.getElementById(unique[j]);
570                                                                 if(newElement != null){
571                                                                         continue;
572                                                                 }
573                                                         } 
574                                                         //if not created yet, then create it.                                                                                           
575                                                                                         addNewChoice(newKey);
576                                                                                    
577                                                                                 }
578                                                                         }
579                                                                 }
580                                                         }
581                                             }
582                                 }
583
584                     }
585                     var ele = angular.element(document.getElementById("DynamicTemplate"));
586                         $compile(ele.contents())($scope);
587                     $scope.$apply();
588                     isInitViewEdit = false;                   
589                     
590                 },
591                 error : function(data){
592                     alert("Error While Retriving the Template Layout Pattren.");
593                 }
594             });
595
596         }
597     };
598     
599     function getNumOfDigits(str_value, index){
600                 // Get the number after @
601                 var str = str_value.substring(index, str_value.length); 
602                 var c = '';
603                 var n = 0;
604                 for (var x = 0; x < str.length; x++){                                                                   
605                     c = str.charAt(x);
606                             if(!isNaN(c)){ 
607                 n++;                                                     
608                     }else{
609                 break;
610             }
611                 }
612                 return n;
613     }
614     
615     function getDictionary(attribute){
616         var dicName = attribute;
617         if(attribute){
618            if(attribute.includes(":")){
619                    dicName = attribute.split(":")[0];
620            }
621         }
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);
628                                 }
629                         }
630             }
631             return listemunerateValues;
632     }
633     
634     function getList(attribute) {
635                 var enumName = attribute;
636                 console.log("In getList: attribute => " + attribute);
637                 if(attribute){
638                    if(attribute.includes(":")){
639                            enumName = attribute.split(":")[0];
640                    }
641                 }   
642             var baseEnum = $scope.dcaeModelData.enumValues;
643             var enumList = [];
644             if(baseEnum != null){
645                 enumList = baseEnum.split(splitEnum);
646             }
647                 var enumAttributes;
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();
652                 }
653         }
654
655          if(enumAttributes){
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;
663          }
664          
665             return [];
666             }
667             
668             function getBooleanList(){
669                 var booleanList = [];
670                 booleanList.push(true);
671                 booleanList.push(false);
672                 return booleanList;
673             }
674             
675
676             function isArray(arrayTest) {
677                 return Object.prototype.toString.call(arrayTest) === '[object Array]';
678             }
679             var lableList = [];
680             
681             $scope.layOutElementList = [];
682             $scope.layOutOnlyLableList = [];
683             
684             var elementOrderNum = 0;
685             
686                 function deconstructJSON(layOutData, level , name) {
687
688                          var array = false;
689                          var label = level;
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;
697                          
698                          var attributekey = "";
699                          
700                         if (name.length > 1){
701                                 label = label + name + '.';
702                         }
703                         
704                     for (key in layOutData) {
705                         array = isArray(layOutData[key]);
706                         console.log("key: " + key , "value: " + layOutData[key]);
707                 
708                         if (!!layOutData[key] && typeof(layOutData[key])=="object") {
709                                 
710                                 if (array==false && key!=="0"){
711                                         
712                                         if($scope.dataOrderInfo){
713                                             var labelObject = {"label" : key, "level" : label, "array" : array};
714                                             //save it to the list
715                                             $scope.layOutOnlyLableList.push(labelObject);
716                                             
717                                         }else {
718                                                 //call label layout
719                                                 $scope.labelLayout(label, key, array );
720                                         }
721                                         
722                                 }
723                                 
724                                 if (array == true && key!=0){
725                                         lableList.push(key);
726                                 }
727                                 
728                                 if (lableList.length > 0){
729                                         array = true;
730                                 }
731                                 if ( key==="0"){
732                                         var newKey = lableList.pop();
733                                         
734                                         if($scope.dataOrderInfo){
735                                                 
736                                                 var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
737                                                 //save it to the list
738                                                 $scope.layOutOnlyLableList.push(labelObject);
739                                                 
740                                         }else {
741                                                 //call label layout 
742                                             $scope.labelLayout(baseLevel, newKey, array );
743                                         }
744                                         
745                                         if (array){
746                                                 label = baseLevel + newKey + '@0.';
747                                         } else {
748                                                 label = baseLevel + newKey + '.';
749                                         }
750                                 }
751                                 deconstructJSON(layOutData[key] , label, key);
752                         } else {
753                                 var attirbuteLabel = label;
754                                 var defaultValue='';
755                                 var description='';
756                                 var isRequired = false;
757                                 if (layOutData[key].includes('defaultValue-')){
758                                         defaultValue = layOutData[key].split('defaultValue-')[1];
759                                 }
760                                 
761                                 if (layOutData[key].includes('description-')){
762                                         description = layOutData[key].split('description-')[1];
763                                 }                               
764                                 
765
766                                 if (key==="0"){
767                                         array = true;
768                                         attributekey = lableList.pop();
769                                         attirbuteLabel = baseLevel;
770                                 } else {
771                                         attributekey = key.split();
772                                 }
773                                 
774                                 if (layOutData[key].includes('required-true')){
775                                         isRequired = true;
776                                 }
777                                 
778                                 var subAttributes = $scope.dcaeModelData.sub_attributes;
779                                 
780                                 if(subAttributes){                                      
781                                         var jsonObject = JSON.parse(subAttributes);     
782                                         
783                                     var lablInfo = findVal(jsonObject, attributekey);
784                                         console.log("deconstructJSON:findValue : " + attributekey +": "+ lablInfo);
785                                         if (lablInfo){
786                                                 if(lablInfo.includes('required-true')){
787                                                         isRequired = true;
788                                                 }       
789                                                 if(lablInfo.includes('defaultValue-')){
790                                                         defaultValue = lablInfo.split('defaultValue-')[1];
791                                                 }
792                                                 
793                                                 if(lablInfo.includes('description-')){
794                                                         description = lablInfo.split('description-')[1];
795                                                 }
796                                                 
797                                         }else{                                  
798                                            var allkeys = Object.keys(jsonObject);
799                                            if(allkeys){
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')){
807                                                                         isRequired = true;
808                                                                  }      
809                                                                  
810                                                                  if(tempObject[key].includes('defaultValue-')){
811                                                                         defaultValue = tempObject[key].split('defaultValue-')[1];
812                                                                  }
813                                                                  
814                                                                  if(tempObject[key].includes('description-')){
815                                                                          description = tempObject[key].split('description-')[1];
816                                                                   }
817
818                                                                  }
819                                                           }
820                                                    }                                            
821                                            }                                    
822                                         } 
823                                 }
824                                 
825                                 var elementObject = {};
826                                 switch (layOutData[key].split(splitcolon)[0]){
827                                 
828                                         case stringValue:
829                                         case string:
830                                                 if($scope.dataOrderInfo){                                                       
831                                                         elementOrderNum++;
832                                                         elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text", "description":description};
833                                                         $scope.layOutElementList.push(elementObject);
834                                                 }else{
835                                                         $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
836                                                 }
837                                                 break;                                          
838                                         case intValue: 
839                                         case integerValue: 
840                                                 if($scope.dataOrderInfo){
841                                                         elementOrderNum++;
842                                                         elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number" , "description":description};
843                                                         $scope.layOutElementList.push(elementObject);
844                                                 }else{
845                                                         $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
846                                                 }
847                                                 break;                                          
848                                         case double:
849                                                 if($scope.dataOrderInfo){
850                                                         elementOrderNum++;
851                                                         elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double",  "description":description};
852                                                         $scope.layOutElementList.push(elementObject);                                                   
853                                                 }else{
854                                                         $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
855                                                 }
856                                                 break;
857                                         case boolean:
858                                                 if($scope.dataOrderInfo){
859                                                         elementOrderNum++;
860                                                         elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"boolean", "description":description};
861                                                         $scope.layOutElementList.push(elementObject);
862                                                 }else{
863                                                         $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
864                                                 }
865                                                 break;
866                                         default:
867                                                 if (layOutData[key].includes('dictionary-')){
868                                                         var list = getDictionary(layOutData[key].split('dictionary-')[1]);
869                                                 }else{
870                                                         //--- get dropdown values from enumValues
871                                                         var list = getList(layOutData[key]);
872                                                 }
873                                                 if (list.length===0){ //not dropdown element
874                                                         if($scope.dataOrderInfo){
875                                                                 elementOrderNum++;
876                                                                 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description};
877                                                                 $scope.layOutElementList.push(elementObject);
878                                                                 
879                                                         }else{
880                                                                 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
881                                                         }                                                       
882                                                 }else{
883                                                         if($scope.dataOrderInfo){
884                                                                 elementOrderNum++;
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);                                                           
887                                                         }else{
888                                                                 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
889                                                         }
890                                                 }
891                                                 break;
892                                 }
893                         }
894                     }
895                 }  
896                 
897                 
898             $scope.validContionalRequired = function(parentId) {
899                 console.log("ng-blur event: parentId : " + parentId);
900                 var c = document.getElementById(parentId).children;
901                 var i;
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() != ""){
908                                 hasValue = true;
909                             }
910                         }
911                 }
912
913                     for (i = 0; i < c.length; i++) {
914                         if(c[i].getAttribute("data-conditional")){
915                                 if(hasValue){
916                                     c[i].setAttribute("required", true);
917                                 }else{
918                                         c[i].removeAttribute("required");
919                                 }
920                         }
921                     }           
922              }
923                                 
924             $scope.jsonLayout = function(layOutData){
925                 
926                    deconstructJSON(layOutData , "", "");
927                    
928                    var orderValue = $scope.dataOrderInfo;
929                    var layOutElementList = $scope.layOutElementList;
930                    var labelList = $scope.layOutOnlyLableList;
931                     
932                    //reset to default
933                    elementOrderNum = 0;
934                    $scope.layOutElementList = [];
935                    $scope.layOutOnlyLableList = [];
936                    
937                    // Only layout in order if order info provided
938                    if(orderValue){
939                            
940                            if(orderValue.includes("[")){
941                                   orderValue = orderValue.replace("[", "") ;
942                                   orderValue = orderValue.replace("]", "") ;
943                            }
944                            
945                            orderValue = orderValue.split(',') ;
946                            
947                            for (var i = 0; i < orderValue.length; i++) {
948                                    console.log("orderValue["+i+"]"+  orderValue[i]);
949                                    var key = orderValue[i].trim();
950                                  
951                                     //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
952                                    if(labelList){
953                                            for (var k = 0; k < labelList.length; k++){
954                                                    
955                                                   var label = labelList[k].label.toString().trim();
956                                                   var level = labelList[k].level.toString().trim();
957                                                   var array = labelList[k].array;
958                                                   
959                                                   if(key == label){                                                       
960                                                          $scope.labelLayout(level, label, array);
961                                                          //in case to have duplicate label names
962                                                          labelList[k].label = "*processed*";
963                                                          break;
964                                                   }
965                                            }
966                                    }
967                                    //--- then layout each element based on its order defined in YAML file
968                                    for (var j = 0; j < layOutElementList.length; j++) { 
969                                            
970                                            var attributekey = layOutElementList[j].attributekey.toString().trim();                                         
971                                         
972                                            if(key == attributekey){     
973
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;
978                                                    
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);
983                                         
984                                                    }else{
985                                                             $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type, description);    
986         
987                                                    }
988                                                    
989                                                    //in case to have duplicate attribute names
990                                                    layOutElementList[j].attributekey = "*processed*";
991                                                    break;
992                                            }
993                                    }
994                            }
995                    }
996             }
997             
998             
999             $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType,  description){
1000                         $scope.temp.policy.ruleGridData.push(attibuteKey);                      
1001                 var br = document.createElement("BR");
1002                 
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
1009                 }else {
1010                         if(isRequired){
1011                                 requiredLabName = attibuteKey + " * ";
1012                                 labeltext = document.createTextNode(requiredLabName);
1013                         }else{
1014                             labeltext = document.createTextNode(attibuteKey);   
1015                         }
1016                 }
1017
1018                 
1019                 var divID = labelValue;
1020                 
1021                 if (labelValue.length  < 1){
1022                         divID = "DynamicTemplate";
1023                 }else if (labelValue.endsWith('.')){
1024                         var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1025                 }
1026                 
1027                 label.appendChild(labeltext);
1028                 
1029                 var textField = document.createElement("INPUT");
1030                 
1031                 textField.setAttribute("class" , "form-control");
1032                 if(dataType){
1033                         if(dataType == "double"){
1034                                 textField.setAttribute("type" , "number");
1035                                 textField.setAttribute("step" , "any");
1036
1037                         }else if(dataType == "boolean"){  //gw1218 testing boolean
1038                                 var booleanDiv = document.createElement("div");
1039
1040                                 booleanDiv.setAttribute("class" , "onoffswitch");
1041
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);
1049                                 }else{
1050                                         textField.removeAttribute("checked");
1051                                 }
1052
1053                                                 var booleanlabel = document.createElement("Label");
1054                                                 booleanlabel.setAttribute("class" , "onoffswitch-label");
1055                                                 booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+'');
1056                                         
1057                                                 var span1 = document.createElement("span");
1058                                                 span1.setAttribute("class" , "onoffswitch-inner");
1059                                                 
1060                                                 var span2 = document.createElement("span");
1061                                                 span2.setAttribute("class" , "onoffswitch-switch"); 
1062                                                 
1063                                                 
1064                                                 booleanlabel.appendChild(span1);        
1065                                                 booleanlabel.appendChild(span2);        
1066                                                 booleanDiv.appendChild(textField);      
1067                                                 booleanDiv.appendChild(booleanlabel);    
1068                                                 
1069                                                 document.getElementById(divID).appendChild(label);  
1070                                                 document.getElementById(divID).appendChild(booleanDiv);         
1071
1072                                                 //return;
1073                            } else{
1074                               textField.setAttribute("type" , dataType);
1075                            }
1076                            
1077                                 
1078
1079                 }
1080                 
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);
1086                         }
1087                 }
1088
1089                 var checkKey;
1090                 var id = "";
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';  
1117                         if(isRequired){
1118                                 textField.setAttribute("required", "true");
1119                         }       
1120                         
1121                         divTag.appendChild(textField);                  
1122                         document.getElementById(divID).appendChild(divTag); 
1123                         
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");
1130                                 }
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);
1137                                         
1138                                         var requiredNodeToolTip = document.createElement('span');
1139                                         requiredNodeToolTip.setAttribute("class", "tooltiptext");
1140                                         requiredNodeToolTip.textContent = "Conditional Required";
1141                                         requiredNode.appendChild(requiredNodeToolTip);
1142                                         
1143                                         textField.setAttribute("data-conditional", divID);
1144                                         textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1145                                 }
1146                         }
1147             
1148                         document.getElementById(divID).appendChild(label);  
1149                         document.getElementById(divID).appendChild(textField);  
1150                         document.getElementById(divID).appendChild(br); 
1151
1152                 }
1153
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){
1158                         
1159                                 if(!firstChild_element.className.includes('children_group border')){
1160                                         layer++;
1161                                         if(layer > 4){ 
1162                                                 layer = 1
1163                                         }
1164                                         firstChild_element.className += ' children_group border' + layer; //here is div with a group of children.
1165                                 }
1166                         }
1167                 }
1168                 console.log('firstChild_Id: ' + firstChild_Id);
1169                 console.log('divID: ' + divID);
1170                 
1171                 if(dataType != "boolean" && defaultValue.length > 0){   
1172                         if(defaultValue.includes(":")){
1173                                 defaultValue = defaultValue.split(":")[0];
1174                                 if(defaultValue === "NA") {
1175                                         defaultValue = "";
1176                                 }                               
1177                         }
1178                         if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
1179                         document.getElementById(checkKey).value = defaultValue;
1180                         }
1181                 }
1182                 
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'];
1189                                 }
1190                         }else{
1191                                 if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
1192                                     document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1193                                 }
1194                         }
1195                 } 
1196                 
1197                 if (dataType != "boolean"){
1198                     plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);     
1199                 }else{
1200                     plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean");    
1201                 }
1202     };
1203   
1204     $scope.labelManyKeys = [];
1205     $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
1206                 var label = document.createElement("Label")
1207                 var divID = labelValue;
1208                 
1209                 if (labelValue.length  < 1){
1210                         divID = "DynamicTemplate";
1211                 } else if (labelValue.endsWith('.')){
1212                         var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1213                 }
1214                 
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);
1219                 var star = "";
1220                 var required = null;
1221                 if(lablInfo){
1222                         if(typeof lablInfo === 'string' ){
1223                            if(lablInfo.includes("required-true")){
1224                                    star = " *";
1225                                    required = true;
1226                             }else if (lablInfo.includes("required-false")){
1227                                    required = false
1228                             }
1229                         }
1230                 }
1231                 
1232                 var labeltext = document.createTextNode(lableName + star);
1233         
1234                 label.appendChild(labeltext);
1235
1236
1237                 if(labelManyKey){
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);
1257                         
1258                         var divTag = document.createElement("div");
1259                         divTag.setAttribute("id", id +'@0');  
1260                         
1261                         if(!divTag.className.includes('children_group border')){
1262                                 layer++;
1263                                 if(layer > 4){ 
1264                                         layer = 1
1265                                 }
1266                                 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1267                         }
1268                         if(required){
1269                            divTag.setAttribute("required", required);  
1270                         }else if(required == false){
1271                            divTag.setAttribute("data-conditional", "yes");  
1272                         }
1273                         
1274                         document.getElementById(id).appendChild(divTag);
1275                         
1276                         $scope.labelManyKeys.push(lableName);
1277                         
1278                 }else{
1279                         var divTag = document.createElement("div");
1280                         divTag.setAttribute("id", "div."+labelValue+lableName);
1281                         
1282                         if(!divTag.className.includes('children_group border')){
1283                                 layer++;
1284                                 if(layer > 4){ 
1285                                         layer = 1
1286                                 }
1287                                 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1288                         }
1289                         if(required){
1290                             divTag.setAttribute("required", required);  
1291                         }else if(required == false){
1292                                 divTag.setAttribute("data-conditional", "yes");  
1293                         }  
1294                         document.getElementById(divID).appendChild(label);  
1295                         document.getElementById(divID).appendChild(divTag);                     
1296                 }
1297     };
1298
1299     $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){
1300                         var br = document.createElement("BR");
1301                 
1302                         if (labelLevel.length  < 1){
1303                                         var divID = "DynamicTemplate";
1304                         } else if (labelLevel.endsWith('.')){
1305                                         var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1306                         }       
1307                 
1308                 
1309                         var label = document.createElement("Label")
1310                         
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")){
1317                                                 isRequired = true;
1318                                         }
1319                                         }
1320                         }
1321                         
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
1326                         }else {
1327                                 if(isRequired){
1328                                     var requiredLabName = attributeName+ " * ";
1329                                         labeltext = document.createTextNode(requiredLabName);
1330                                 }else{
1331                                     labeltext = document.createTextNode(attributeName); 
1332                                 }
1333                         
1334                             label.appendChild(labeltext);               
1335                         }
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);
1343                                         
1344                                 var requiredNodeToolTip = document.createElement('span');
1345                                 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1346                                 requiredNodeToolTip.textContent = "Conditional Required";
1347                                 requiredNode.appendChild(requiredNodeToolTip);
1348
1349                 }
1350
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");
1355
1356                 if(description && description != "null"){
1357                         listField.setAttribute("title", description);
1358                 }
1359
1360                 if(isRequired){
1361                         if(document.getElementById(divID).hasAttribute('data-conditional')){
1362                                 listField.setAttribute("data-conditional", divID);
1363                                 listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1364                         }else{
1365                                 listField.setAttribute("required", true);
1366                         }
1367                 }
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];  
1374                                 }
1375                         } 
1376                         optionFirst.setAttribute('value', optionValue);
1377                         optionFirst.appendChild(document.createTextNode(optionValue));
1378                         listField.appendChild(optionFirst);     
1379                 }
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;
1387                         }
1388                         PolicyAppService.getData(dictParamsSplit[0]).then(function (data) {
1389                                 var j = 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);
1398                                 }
1399                         }, function (error) {
1400                                 console.log("failed");
1401                         });
1402
1403                 }
1404                 else{
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','=');
1408                                 }
1409                                 
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);
1415                         }
1416                 }
1417                 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1418
1419                 enumKeyList.push(attributeName);
1420
1421                 document.getElementById(divID).appendChild(label);  
1422                 document.getElementById(divID).appendChild(br); 
1423
1424                 if(many == true){
1425                         document.getElementById(divID).appendChild(listField).multiple = true;
1426                         plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1427                 }else {
1428                         document.getElementById(divID).appendChild(listField).multiple = false;
1429                         plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1430
1431                         if (defaultValue){
1432                                 if(defaultValue.includes(':')){
1433                                         defaultValue = defaultValue.split(':')[0];
1434                                 }
1435                                 var location = listemunerateValues.indexOf(defaultValue);
1436                                 document.getElementById(labelLevel +attributeName).options[location+1].selected = true;
1437                         }
1438                 }
1439
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");
1449
1450                         document.getElementById(divID).appendChild(optionInput);
1451
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");
1459
1460
1461                         document.getElementById(divID).appendChild(optionButton);
1462                         document.getElementById(divID).appendChild(br); 
1463                 }
1464
1465                 if($scope.temp.policy.ruleData != null){
1466                         if (many == true){
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];
1472                                         }
1473                                         var location = listemunerateValues.indexOf(testValue);
1474                                         if (location!=-1){
1475                                                 document.getElementById(labelLevel +attributeName).options[location].selected = true;
1476                                         }
1477                                 }                       
1478                         }else {
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];    
1481                                 }
1482                         }
1483                 }
1484         };
1485
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 = "";
1493         };
1494
1495         function onlyUnique(value, index, self) { 
1496                 return self.indexOf(value) === index;
1497         }
1498
1499         $scope.savePolicy = function(policy){
1500                 if(policy.itemContent != undefined){
1501                         $scope.refreshCheck = true; 
1502                         $scope.policyNavigator = policy.itemContent;
1503                         policy.itemContent = "";
1504                 }
1505                 $scope.savebutton = false;
1506                 var splitAt = '*';
1507                 var dot ='.';
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';
1521                                 }
1522                                 if(searchElement != null){
1523                                         var keySplit = key.split(dot);
1524                                         var elumentLocation = keySplit.length;
1525                                         var enumKey = key;
1526                                         if (elumentLocation > 1){
1527                                                 enumKey = keySplit[keySplit.length - 1];
1528                                         }
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);
1535                                                                 }
1536                                                         jsonPolicy[key]= multiSlect;
1537                                                 }else{
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;
1544                                                                         }
1545                                                                 }
1546
1547                                                         }else{
1548                                                                 jsonPolicy[key]= searchElement.value;
1549                                                         }
1550                                                 }
1551                                 } else {
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;
1560                                                                         }
1561                                                                 }
1562                                                         }
1563                                         }
1564                                 }
1565                         }
1566                 }
1567         }
1568         var uuu = "policycreation/save_policy";
1569         var postData={policyData: policy, policyJSON : jsonPolicy};
1570         $.ajax({
1571             type : 'POST',
1572             url : uuu,
1573             dataType: 'json',
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);
1584                                 }
1585                                 $scope.pushStatus=data.policyData.split("&")[1];
1586                                 if($scope.pushStatus=="successPush"){
1587                                         Notification.success("Policy pushed successfully");
1588                                 }
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.");
1593                                         }
1594                 });
1595                 console.log($scope.data);
1596             },
1597             error : function(data){
1598                 Notification.error("Error Occured while saving Policy.");
1599             }
1600         });
1601     };
1602     
1603     var booleanTrueElements = [];
1604     $scope.validatePolicy = function(policy){
1605         document.getElementById("validate").innerHTML = "";
1606         var splitAt = '*';
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';
1620                         }
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);
1627                                                                 }
1628                                                         jsonPolicy[key]= multiSlect;
1629                                                 }else{
1630                                                         jsonPolicy[key]= searchElement.value;
1631                                                 }
1632                                         if(searchElement.getAttribute("required")){
1633                                                 if(!searchElement.value){
1634                                                         return;
1635                                                 }
1636                                         } 
1637                                 } else {
1638                                         if(searchElement.value != null){
1639                                                 jsonPolicy[key]= searchElement.value;
1640                                                 if(searchElement.getAttribute("required")){
1641                                                         if(!searchElement.value){
1642                                                                 return;
1643                                                         }
1644                                                 }                                               
1645                                         }
1646                                 }
1647                         }
1648                 }
1649                 
1650                 
1651                 var checkedValue = $('.onoffswitch-checkbox:checked').val();
1652                 
1653             var x = document.getElementsByClassName("onoffswitch-checkbox");
1654             
1655                              
1656                 if(checkedValue){
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)
1661                         }    
1662                 }
1663         }
1664         var uuu = "policyController/validate_policy.htm";
1665
1666         console.log("$scope.isCheck:" + $scope.isCheck);
1667         
1668         if($scope.isCheck == true){
1669                 if(("configName" in policy) == false){
1670                                 Notification.error("Validation Failed: configName is required");
1671                                 $scope.savebutton = true;
1672                                 return;
1673                 }
1674                 if(("location" in policy) == false){
1675                                 Notification.error("Validation Failed: location is required");
1676                                 $scope.savebutton = true;
1677                                 return;
1678                 }
1679                 if(("uuid" in policy) == false){
1680                                 Notification.error("Validation Failed: uuid is required");
1681                                 $scope.savebutton = true;
1682                                 return;
1683                 }
1684                 if(("policyScope" in policy) == false){
1685                                 Notification.error("Validation Failed: policyScope is required");
1686                                 $scope.savebutton = true;
1687                                 return;
1688                 }
1689         }        
1690         
1691         var postData={policyData: policy, policyJSON : jsonPolicy};
1692                 $.ajax({
1693                         type : 'POST',
1694                         url : uuu,
1695                         dataType: 'json',
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;
1706                                                         if (size > 18){
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";
1711                                                         }
1712                                                 }else{
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;
1718                                                 }
1719                                                 
1720                                 });
1721                                 console.log($scope.data);       
1722                         },
1723                         error : function(data){
1724                                 Notification.error("Validation Failed.");
1725                                 $scope.savebutton = true;
1726                         }
1727                 });
1728     };
1729
1730         // Switch Click
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');      
1743                         }       
1744                 });
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){
1749                                 
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(); }
1753                         
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');
1758                                 } else {                        
1759                                         // Checkbox Is Checked Remove Off Class, and Add the On Class
1760                                         $(this).removeClass('Off').addClass('On');
1761                                 }
1762                         }
1763                 });
1764
1765 }]);