Update css file name in conf.py
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / OptimizationPolicyController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018-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 angular.module('abs').controller('optimizationController', 
21     ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', 
22     function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23     $("#dialog").hide();
24     
25     $scope.policyNavigator;
26     $scope.isCheck = false;
27     $scope.savebutton = true;
28     $scope.refreshCheck = false;
29     
30     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
31     $scope.temp.policy = {
32         policyType : "Config",
33         configPolicyType : "Optimization"
34     }
35     }
36     
37     $scope.refresh = function(){
38     if($scope.refreshCheck){
39         $scope.policyNavigator.refresh();
40     }
41     $scope.modal('createNewPolicy', true);
42     $scope.temp.policy = "";
43     };
44     
45     $scope.modal = function(id, hide) {
46         return $('#' + id).modal(hide ? 'hide' : 'show');
47     };
48     
49     $('#ttlDate').datepicker({
50     dateFormat: 'dd/mm/yy',
51     changeMonth: true,
52     changeYear: true,
53     onSelect: function(date) {
54         angular.element($('#ttlDate')).triggerHandler('input');
55     }
56     });
57     
58     if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly  != undefined){
59     if ($scope.temp.policy.configName == undefined){
60     $scope.isCheck = false;
61     }else{
62         $scope.isCheck = true;
63     }
64     }else {
65         $scope.isCheck = false;
66     }
67     
68     PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
69     var j = data;
70     $scope.data = JSON.parse(j.data);
71     $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
72     });
73
74     PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
75     var j = data;
76     $scope.data = JSON.parse(j.data);
77     $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
78     });
79
80     PolicyAppService.getData('getDictionary/get_OptimizationModelsDataByName').then(function (data) {
81     var j = data;
82     $scope.data = JSON.parse(j.data);
83     var inputModelList = JSON.parse($scope.data.optimizationModelsDictionaryDatas);
84     var unique = {};
85     var uniqueList = [];
86     for(var i = 0; i < inputModelList.length; i++){
87     if(typeof unique[inputModelList[i]] == "undefined"){
88         unique[inputModelList[i]] = "";
89         uniqueList.push(inputModelList[i]);
90     }
91     }
92     $scope.optimizationModelsDictionaryDatas = uniqueList;
93     });
94
95     PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
96     var j = data;
97     $scope.data = JSON.parse(j.data);
98     $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
99     });
100
101      $scope.choices = [];
102      $scope.attributeDatas = [{"attributes" : $scope.choices}];
103      $scope.isInitEditTemplate = true;  //just initially create the edit template, didn't click add button yet.
104      $scope.addNewChoice = function(value) {
105      if(value != undefined){
106     if (value.startsWith('div.')){
107         value = value.replace('div.','');
108     }
109     var parentElement = document.getElementById("div."+value);
110     var div = document.getElementById(value+"@0");
111     if(div != null){
112         var clone = div.cloneNode(true); 
113         var addElement = parentElement.childElementCount;
114         clone.id = ''+value+'@'+addElement;
115         clone.value = '';
116         if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ //if it's view or edit
117         if($scope.temp.policy.ruleData[clone.id] || ($scope.temp.policy.editPolicy && !$scope.isInitEditTemplate)){  // Only append child if its value found in ruleData or edit mode
118             if($scope.temp.policy.ruleData[clone.id]){
119                 clone.value = $scope.temp.policy.ruleData[clone.id];
120             }
121             if(!clone.className.includes("child_single")){   
122             clone.className += ' child_single'; //single element clone
123             }
124             document.getElementById("div."+value).appendChild(clone);
125             plainAttributeKeys.push(''+value+'@'+addElement);
126         }
127         }else{ //not view or edit
128         if(!clone.className.includes("child_single")){   
129             clone.className += ' child_single'; //single element clone
130         }
131         document.getElementById("div."+value).appendChild(clone);
132         plainAttributeKeys.push(''+value+'@'+addElement);
133         }
134     }else{
135         div = document.getElementById("div."+value+"@0");
136         
137         if(div){
138         div.className += ' children_group'; //div with a group of children.
139         }        
140         var childElement = parentElement.firstElementChild;
141         var countParent = parentElement.childElementCount;
142         var childElementString = childElement.innerHTML;
143         var find = value+"@0";
144         var re = new RegExp(find, 'g');
145         childElementString = childElementString.replace(re,value+'@' + countParent);
146         var clone = childElement.cloneNode(true);
147         for (var ii = 0; ii < parentElement.childNodes.length; ii++){
148                 var childId = parentElement.childNodes[ii].id;
149                 if(ii = parentElement.childNodes.length){
150                 var childnewId = childId.slice(0, -1);
151                 var count = childId.slice(-1);
152                 }
153             }
154         var countvalue = parseInt(count) + 1;
155         clone.id = childnewId+countvalue;
156         clone.value = '';
157         clone.innerHTML=childElementString;
158         document.getElementById("div."+value).appendChild(clone);
159         var selects = clone.getElementsByTagName("select");
160         var inputs = clone.getElementsByTagName("input");
161         var removeValues = [];
162         for(var i=0; i<inputs.length; i++){
163         if ($scope.temp.policy.ruleData!=undefined){
164             var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
165             if (checkValue!=undefined && checkValue != "undefined"){
166             if($scope.temp.policy.ruleData != null){
167                 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
168                 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
169                 plainAttributeKeys.push(inputs[i].id);
170             }
171             } else {
172             plainAttributeKeys.push(inputs[i].id);
173             }
174         }else {
175             plainAttributeKeys.push(inputs[i].id);
176         }
177         }
178         
179         for(var i=0; i<selects.length; i++){
180         if ($scope.temp.policy.ruleData!=undefined){
181             var checkValue = $scope.temp.policy.ruleData[selects[i].id];
182             if (checkValue!=undefined && checkValue!="undefined"){
183             if($scope.temp.policy.ruleData != null){
184                 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
185                 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
186                 plainAttributeKeys.push(selects[i].id);
187             }
188             } else {
189             plainAttributeKeys.push(selects[i].id);
190             }
191         }else {
192             plainAttributeKeys.push(selects[i].id);
193         }
194         }
195         
196         for (var k=0; k<removeValues.length; k++){
197         var elem = document.getElementById(removeValues[k]);
198         elem.parentNode.removeChild(elem);
199         }
200         var ele = angular.element(document.getElementById("div."+value));
201             $compile(ele.contents())($scope);
202                 $scope.$apply();
203     }
204      }
205      };
206      
207      function findVal(object, key) {
208         var value;
209         Object.keys(object).some(function(k) {
210             if (k === key) {
211                 value = object[k];
212                 return true;
213             }
214             if (object[k] && typeof object[k] === 'object') {
215                 value = findVal(object[k], key);
216                 return value !== undefined;
217             }
218         });
219         return value;
220     }
221      
222      $scope.removeChoice = function(value) {
223      if(value != undefined){
224      var c = document.getElementById("div."+value).childElementCount;
225      
226      if(c == 1){
227          Notification.error("The original one is not removable.");
228          return;
229      }    
230      document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);     
231      }
232      };
233      
234      $scope.pullVersion = function(serviceName) {
235      if(serviceName != undefined){
236      var uuu = "policyController/getModelServiceVersionData.htm";
237      var postData={policyData: serviceName};
238      $.ajax({
239          type : 'POST',
240          url : uuu,
241          dataType: 'json',
242          contentType: 'application/json',
243          data: JSON.stringify(postData),
244          success : function(data){
245          $scope.$apply(function(){
246              $scope.optimizationModelsDictionaryVersionDatas = data[0].optimizationModelVersionData;
247          });
248          },
249          error : function(data){
250          Notification.error("Error While Retrieving the Template Layout Pattern.");
251          }
252      });     
253      }
254      };
255     
256     var splitEqual = '=';
257     var splitComma = ',';
258     var splitcolon = ':';
259     var splitEnum = "],";
260     var plainAttributeKeys = [];
261     var matching = [];
262     var enumKeyList = [];
263     var dictionaryList = [];
264     var dictionaryNameList = [];
265     $scope.addDataToFields = function(serviceName, version){
266         if(serviceName != null && version !=null){
267         var service=serviceName+"-v"+version;
268         var myNode = document.getElementById("DynamicTemplate");
269         myNode.innerHTML = '';
270             var uuu = "policyController/getOptimizationTemplateData.htm";
271             var postData={policyData: service};
272             var dataOrderInfo = "";
273             
274             $.ajax({
275                 type : 'POST',
276                 url : uuu,
277                 dataType: 'json',
278                 contentType: 'application/json',
279                 data: JSON.stringify(postData),
280                 success : function(data){
281                     $scope.$apply(function(){
282                     $scope.optimizationModelData = data[0].optimizationModelData;
283                     $scope.optimizationJsonDate = data[0].jsonValue;
284                         $scope.dataOrderInfo = null;
285                     var headDefautlsData  = data[0].headDefautlsData;
286                     if(headDefautlsData != null){
287                         $scope.temp.policy.onapName = headDefautlsData.onapName;
288                         $scope.temp.policy.guard = headDefautlsData.guard;
289                         $scope.temp.policy.riskType = headDefautlsData.riskType;
290                         $scope.temp.policy.riskLevel = headDefautlsData.riskLevel;
291                         $scope.temp.policy.priority = headDefautlsData.priority;
292                         
293                     }else if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
294                         $scope.temp.policy.onapName = "";
295                         $scope.temp.policy.guard = "";
296                         $scope.temp.policy.riskType = "";
297                         $scope.temp.policy.riskLevel = "";
298                         $scope.temp.policy.priority = "";
299                     }
300                     
301                        var annotation = $scope.optimizationModelData.annotation;
302                        var dictionary = $scope.microServiceAttributeDictionaryDatas;
303
304                        if (annotation == null || annotation.length<1){
305                            $scope.isCheck = true;
306                        }else {
307                            $scope.isCheck = false;
308                            var annoationList = annotation.split(splitComma);
309                            for (k = 0; k < annoationList.length; k++){
310                                var splitAnnotation = annoationList[k].split(splitEqual);
311                                if (splitAnnotation[1].includes("matching-true")){
312                                matching.push(splitAnnotation[0].trim());
313                                }
314                            }
315
316                        }
317
318                        if (dictionary!= null && dictionary.length>1){
319                            for (m=0; m < dictionary.length; m += 1){
320                            var valueCompare = dictionary[m].value;
321                            var valueModel = dictionary[m].modelName;
322                            var conpairService = serviceName;
323                            if (valueModel.includes('-v')){
324                                conpairService = service;
325                            }
326                            if(valueModel.localeCompare(conpairService) == 0){
327                                dictionaryList.push(dictionary[m]);
328                                if (!dictionaryNameList.includes(dictionary[m].name)){
329                                dictionaryNameList.push(dictionary[m].name)
330                                }
331                            }
332                            }
333                        }
334
335                     $scope.temp.policy.ruleGridData = [];
336                     
337                     if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
338                     dataOrderInfo = $scope.dataOrderInfo;
339                     }
340                     
341                     $scope.jsonLayout($scope.optimizationJsonDate);
342                     
343                     });
344                     
345                     if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){  // If it's veiw or edit
346                     
347                     if($scope.temp.policy.editPolicy){
348                         $scope.isInitEditTemplate = true;
349                     }
350                     
351                     var checkData = [];
352                     var data = [];
353                         // If ruleData contains extra elements created by clicked add button 
354                         if($scope.temp.policy.ruleData != null){
355                             var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
356                             propNames.forEach(function(name) {
357                             data.push(name);
358                             });
359                             
360                             var extraElements = data;
361                             
362                             if(plainAttributeKeys != null){
363                             for(b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
364                             var newValue = plainAttributeKeys[b].split("*");
365                             for(a = 0; a < data.length; a++){
366                             if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
367                                 extraElements.splice(a, 1);
368                             }
369                             }
370                         
371                             }
372                             
373                         //--- Populate these extra elements created by clicked add button 
374                         for(a = 0; a < extraElements.length; a++){                
375                             if(extraElements[a].includes("@")){
376                             var index = extraElements[a].lastIndexOf("@");
377                             if(index > 0){
378                                 // Get the number after @
379                                 var n = getNumOfDigits(extraElements[a], index+1);
380                                     
381                                     var key = extraElements[a].substring(0, index+n+1); //include @x in key also by n+2 since x can be 1,12, etc
382                                 checkData.push(key);
383                             }
384                             }
385                         }
386                             var unique = checkData.filter(onlyUnique);
387                             //if no layout order info, keep the process as before
388                             if(!dataOrderInfo){
389                             for(i =0; i < unique.length; i++){
390                             //remove @x and let addNewChoice add @1 or @2...
391                             //var newKey = unique[i].substring(0, unique[i].length-2);
392                             var index = unique[i].lastIndexOf("@");
393                             var newKey = unique[i].substring(0, index);
394                             $scope.addNewChoice(newKey);
395                             }
396                         }else{
397
398                           for (i = 0; i < $scope.labelManyKeys.length; i++) {
399                               var label = $scope.labelManyKeys[i];
400                               // first add parent/label level
401                           for (k = 0; k < unique.length; k++){
402                                 var newKey = unique[k].substring(0, index);
403                                    if(label == newKey){
404                                                         //Check this label has bee created or not
405                                    if(!document.getElementById(unique[k])){
406                                        $scope.addNewChoice(newKey);
407                                    }
408                                    unique[k] = "*processed*";
409                               break;
410                                    }
411                           }                              
412                           }
413                           
414                           //---reset to default
415                           dataOrderInfo = [];
416                           $scope.labelManyKeys = [];
417                           
418                           //---process none labels
419                           for (j = 0; j < unique.length; j++){
420                               if(unique[j] != "*processed*"){
421                               // if not created yet
422                               if(!document.getElementById(unique[j])){
423                                 var index = unique[j].lastIndexOf("@");
424                                 var newKey = unique[j].substring(0, index);
425                                    $scope.addNewChoice(newKey);
426                               }
427                               }
428                           }
429                           }
430                         }
431                         }
432                         
433                     if($scope.temp.policy.editPolicy){
434                         //clean all the events of addNewChoice
435                         $scope.$on('$destroy', addNewChoice);
436                     }
437                         
438                     }
439                     var ele = angular.element(document.getElementById("DynamicTemplate"));
440                 $compile(ele.contents())($scope);
441                     $scope.$apply();
442                 },
443                 error : function(data){
444                 Notification.error("Error While Retrieving the Template Layout Pattern.");
445                 }
446             });
447         }
448     };
449     
450     function getNumOfDigits(str_value, index){
451     // Get the number after @
452     var str = str_value.substring(index, str_value.length);    
453     var c = '';
454     var n = 0;
455     for (var x = 0; x < str.length; x++){                                
456         c = str.charAt(x);
457         if(!isNaN(c)){ 
458                 n++;                                                     
459         }else{
460                 break;
461             }
462     }
463     return n;
464     }
465     
466     function getDictionary(attribute){
467     var dicName = attribute;
468     if(attribute){
469        if(attribute.includes(":")){
470            dicName = attribute.split(":")[0];
471        }
472     }
473         var dictionaryRegExp = new RegExp(dicName);
474         listemunerateValues = [];
475         if (dictionaryRegExp.test(dictionaryNameList)) {
476     for (p=0; p < dictionaryList.length; p += 1) {
477         if (dicName == dictionaryList[p].name) {
478         listemunerateValues.push(dictionaryList[p].value);
479         }
480     }
481         }
482         return listemunerateValues;
483     }
484     
485     function getList(attribute) {
486     var enumName = attribute;
487     if(attribute){
488        if(attribute.includes(":")){
489            enumName = attribute.split(":")[0];
490        }
491     }   
492         var baseEnum = $scope.optimizationModelData.enumValues;
493         var enumList = [];
494         if(baseEnum != null){
495         enumList = baseEnum.split(splitEnum);
496         }
497     var enumAttributes;
498     var patternTest = new RegExp(enumName);
499     for (k=0; k < enumList.length; k += 1){
500         if(patternTest.test(enumList[k]) == true){
501         enumAttributes = enumList[k].trim();
502         }
503     }
504
505     if(enumAttributes){
506             enumAttributes = enumAttributes.replace("[", "");
507            enumAttributes = enumAttributes.replace("]", "");
508            enumAttributes = enumAttributes.replace(/ /g, '');
509     var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
510     listemunerateValues  = dropListAfterCommaSplit[1].split(splitComma);
511             return listemunerateValues;
512          }
513            
514          return [];
515     }
516         
517     function getBooleanList(){
518     var booleanList = [];
519     booleanList.push(true);
520     booleanList.push(false);
521     return booleanList;
522     }
523
524     function isArray(arrayTest) {
525         return Object.prototype.toString.call(arrayTest) === '[object Array]';
526     }
527         
528     var lableList = [];
529     
530     $scope.layOutElementList = [];
531     $scope.layOutOnlyLableList = [];
532     
533     var elementOrderNum = 0;
534         
535     function deconstructJSON(layOutData, level , name) {
536
537      var array = false;
538      var label = level;
539      var stringValue = "java.lang.String";
540      var string = "string";
541      var intValue = "int";
542      var integerValue = "integer";
543      var double = "double";
544      var boolean = "boolean";
545      var baseLevel = level;
546      var list = "list";
547      var String = "String";
548      
549      var attributekey = "";
550      
551     if (name.length > 1){
552     label = label + name + '.';
553     }
554     
555         for (key in layOutData) {
556         array = isArray(layOutData[key]);
557        
558         if (!!layOutData[key] && typeof(layOutData[key])=="object") {
559             
560             if (array==false && key!=="0"){
561             
562             if($scope.dataOrderInfo){
563                 var labelObject = {"label" : key, "level" : label, "array" : array};
564                 //save it to the list
565                 $scope.layOutOnlyLableList.push(labelObject);
566                 
567             }else {
568                 //call label layout
569                 $scope.labelLayout(label, key, array );
570             }
571             
572             }
573             
574             if (array == true && key!=0){
575             lableList.push(key);
576             }
577             
578             if (lableList.length > 0){
579             array = true;
580             }
581             if ( key==="0"){
582             var newKey = lableList.pop();
583             
584             if($scope.dataOrderInfo){
585                 
586             var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
587             //save it to the list
588             $scope.layOutOnlyLableList.push(labelObject);
589             
590             }else {
591                 //call label layout 
592                 $scope.labelLayout(baseLevel, newKey, array );
593             }
594             
595             if (array){
596                 label = baseLevel + newKey + '@0.';
597             } else {
598                 label = baseLevel + newKey + '.';
599             }
600             }
601             deconstructJSON(layOutData[key] , label, key);
602             } else {
603             var attirbuteLabel = label;
604             var defaultValue='';
605             var isRequired = false;
606             if (layOutData[key].includes('defaultValue-')){
607                 defaultValue = layOutData[key].split('defaultValue-')[1];
608             }
609
610             if (key==="0"){
611                 array = true;
612                 attributekey = lableList.pop();
613                 attirbuteLabel = baseLevel;
614             } else {
615                 attributekey = key.split();
616             }
617             
618             if (layOutData[key].includes('required-true')){
619                 isRequired = true;
620             }
621             
622             var subAttributes = $scope.optimizationModelData.sub_attributes;
623             
624             if(subAttributes){            
625             var jsonObject = JSON.parse(subAttributes);            
626             var allkeys = Object.keys(jsonObject);
627             if(allkeys){
628                 for (var k = 0; k < allkeys.length; k++) {
629                 var keyValue = allkeys[k];
630                 if(jsonObject[keyValue]){
631                     var tempObject = jsonObject[keyValue];
632                     if(tempObject && tempObject[key]){
633                         if (tempObject[key].includes('required-true')){
634                             isRequired = true;
635                         }    
636                     }
637                 }
638                 }                
639             }            
640             }
641             
642             var elementObject = {};
643             switch (layOutData[key].split(splitcolon)[0]){
644             
645                 case stringValue:
646                 case string:
647                 if($scope.dataOrderInfo){                    
648                 elementOrderNum++;
649                 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text"};
650                 $scope.layOutElementList.push(elementObject);
651                 }else{
652                     $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
653                 }
654                 break;                
655                 case intValue: 
656                 case integerValue: 
657                 if($scope.dataOrderInfo){
658                 elementOrderNum++;
659                 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number"};
660                 $scope.layOutElementList.push(elementObject);
661                 }else{
662                     $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
663                 }
664                 break;                
665                 case double:
666                 if($scope.dataOrderInfo){
667                 elementOrderNum++;
668                 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double"};
669                 $scope.layOutElementList.push(elementObject);                    
670                 }else{
671                     $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
672                 }
673                 break;
674                 case boolean:
675                 if($scope.dataOrderInfo){
676                 elementOrderNum++;
677                 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": layOutData[key], "list": getBooleanList, "isRequired": isRequired, "type":"dropBox"};
678                 $scope.layOutElementList.push(elementObject);
679                 }else{
680                     $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
681                 }
682                 break;
683                 default:
684                 if (layOutData[key].includes('dictionary-')){
685                     var list = getDictionary(layOutData[key].split('dictionary-')[1]);
686                 }else{
687                     //--- get dropdown values from enumValues
688                     var list = getList(layOutData[key]);
689                 }
690                 if (list.length===0){ //not dropdown element
691                     if($scope.dataOrderInfo){
692                     elementOrderNum++;
693                     elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text"};
694                     $scope.layOutElementList.push(elementObject);
695                     
696                     }else{
697                     $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
698                     }                    
699                 }else{
700                     if($scope.dataOrderInfo){
701                     elementOrderNum++;
702                     elementObject = {"id": elementOrderNum, "attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": layOutData[key],"isRequired": isRequired, "list":list, "type":"dropBox"};
703                     $scope.layOutElementList.push(elementObject);                    
704                     }else{
705                     $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
706                     }
707                 }
708                 break;
709             }
710             }
711         }
712     }  
713
714     $scope.validContionalRequired = function(parentId) {
715         var c = document.getElementById(parentId).children;
716         var i;
717         var hasValue = false;
718         for (i = 0; i < c.length; i++) {
719         if(c[i].getAttribute("data-conditional")){
720             if(c[i].value != null && c[i].value.trim() != ""){
721             hasValue = true;
722             }
723         }
724         }
725
726         for (i = 0; i < c.length; i++) {
727             if(c[i].getAttribute("data-conditional")){
728             if(hasValue){
729                 c[i].setAttribute("required", true);
730             }else{
731                 c[i].removeAttribute("required");
732             }
733             }
734         }        
735      }
736     
737     $scope.jsonLayout = function(layOutData){
738     
739        deconstructJSON(layOutData , "", "");
740            
741        var orderValue = $scope.dataOrderInfo;
742        var layOutElementList = $scope.layOutElementList;
743        var labelList = $scope.layOutOnlyLableList;
744         
745        //reset to default
746        elementOrderNum = 0;
747        $scope.layOutElementList = [];
748        $scope.layOutOnlyLableList = [];
749        
750        // Only layout in order if order info provided
751        if(orderValue){
752        
753        if(orderValue.includes("[")){
754       orderValue = orderValue.replace("[", "") ;
755       orderValue = orderValue.replace("]", "") ;
756        }
757        
758        orderValue = orderValue.split(',') ;
759        
760        for (i = 0; i < orderValue.length; i++) {
761        var key = orderValue[i].trim();
762      
763         //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
764        if(labelList){
765            for (k = 0; k < labelList.length; k++){
766            
767           var label = labelList[k].label.toString().trim();
768           var level = labelList[k].level.toString().trim();
769           var array = labelList[k].array;
770           
771           if(key == label){                       
772              $scope.labelLayout(level, label, array);
773                         //in case to have duplicate label names
774              labelList[k].label = "*processed*";
775              break;
776           }
777            }
778        }
779        //--- then layout each element based on its order defined in YAML file
780            for (j = 0; j < layOutElementList.length; j++) { 
781                
782                var attributekey = layOutElementList[j].attributekey.toString().trim();                          
783             
784                if(key == attributekey){     
785     
786                      var attirbuteLabel = layOutElementList[j].attirbuteLabel.toString().trim();
787                      var defaultValue = layOutElementList[j].defaultValue.toString().trim();
788                      var isRequired = layOutElementList[j].isRequired;
789                      
790                   
791                      if (layOutElementList[j].type == "dropBox"){ 
792                     $scope.dropBoxLayout(attirbuteLabel, attributekey, layOutElementList[j].array, defaultValue, layOutElementList[j].list, isRequired);
793                             
794                    }else{
795                     $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type);    
796     
797                    }
798                      
799                      //in case to have duplicate attribute names
800                      layOutElementList[j].attributekey = "*processed*";
801                    break;
802                }
803            
804            }
805        
806        }
807        }
808     }
809     
810     
811     $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType ){
812     $scope.temp.policy.ruleGridData.push(attibuteKey);    
813     var br = document.createElement("BR");
814     
815     var label = document.createElement("Label");
816     var labeltext = null;
817     var requiredLabName = "";
818     if (matching.includes(attibuteKey)){
819     labeltext = document.createTextNode(attibuteKey + "*!");    
820     isRequired = true;  //set required as true for matching element
821     }else {
822     if(isRequired){
823         requiredLabName = attibuteKey + " * ";
824         labeltext = document.createTextNode(requiredLabName);
825     }else{
826         labeltext = document.createTextNode(attibuteKey);    
827     }
828     }
829
830     
831     var divID = labelValue;
832     
833     if (labelValue.length  < 1){
834     divID = "DynamicTemplate";
835     }else if (labelValue.endsWith('.')){
836     var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
837     }
838     
839     label.appendChild(labeltext);
840     
841     var textField = document.createElement("INPUT");
842     
843     textField.setAttribute("class" , "form-control");
844     if(dataType){
845        if(dataType == "double"){
846            textField.setAttribute("type" , "number");
847            textField.setAttribute("step" , "any");
848        }else{
849           textField.setAttribute("type" , dataType);
850        }
851     }
852     textField.setAttribute("style" , "width:300px;");
853     textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
854     var checkKey;
855     var id = "";
856     if(attributeManyKey){
857     checkKey = labelValue + attibuteKey+'@0';
858     textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+''); 
859     var divTag = document.createElement("div");
860     divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
861     var addButton = document.createElement("BUTTON");
862     var buttonaddLabel = document.createTextNode("+");       
863     addButton.appendChild(buttonaddLabel); 
864     addButton.setAttribute("id", labelValue + attibuteKey);
865     addButton.setAttribute("class", "btn btn-add-remove");
866     addButton.setAttribute("ng-click" ,  'addNewChoice("'+labelValue + attibuteKey+'");');
867     addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
868     var removeButton = document.createElement("BUTTON");
869     var buttonremoveLabel = document.createTextNode("-");       
870     removeButton.appendChild(buttonremoveLabel); 
871     removeButton.setAttribute("class", "btn btn-add-remove");
872     removeButton.setAttribute("ng-click" ,  'removeChoice("'+labelValue + attibuteKey+'");');
873     removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
874     document.getElementById(divID).appendChild(addButton); 
875     document.getElementById(divID).appendChild(removeButton); 
876     document.getElementById(divID).appendChild(label); 
877     id = "div."+labelValue+attibuteKey;
878     divTag.setAttribute("id", id); 
879     document.getElementById(divID).appendChild(divTag);
880     textField.className += ' first_child';    
881     if(isRequired){
882         textField.setAttribute("required", "true");
883     }    
884     divTag.appendChild(textField);     
885     document.getElementById(divID).appendChild(divTag); 
886     
887     }else{
888     checkKey = labelValue + attibuteKey;
889     textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
890     if(document.getElementById(divID).hasAttribute('required') || !document.getElementById(divID).hasAttribute('data-conditional')){
891         if(requiredLabName.includes("*") || isRequired){
892         textField.setAttribute("required", "true");
893         }
894     }else if (document.getElementById(divID).hasAttribute('data-conditional')){
895         if(requiredLabName.includes("*")){        
896         var requiredNode = document.createElement('span');
897         requiredNode.setAttribute("class", "mstooltip");
898         requiredNode.textContent = "?";
899         label.appendChild(requiredNode);
900         
901         var requiredNodeToolTip = document.createElement('span');
902         requiredNodeToolTip.setAttribute("class", "tooltiptext");
903         requiredNodeToolTip.textContent = "Conditional Required";
904         requiredNode.appendChild(requiredNodeToolTip);
905         
906         textField.setAttribute("data-conditional", divID);
907         textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
908         }
909     }
910             
911     document.getElementById(divID).appendChild(label);  
912     document.getElementById(divID).appendChild(textField);  
913     document.getElementById(divID).appendChild(br); 
914     
915     }
916
917     if(divID.includes("@0") && divID.includes("div.")){
918     var firstChild_Id = divID.split("@0")[0];
919     var firstChild_element = document.getElementById(firstChild_Id);
920     if(firstChild_element){
921         firstChild_element.className += ' children_group';  //here is a div with a group of children.
922     }
923     }
924     
925     if (defaultValue.length > 0){    
926     if(defaultValue.includes(":")){
927         defaultValue = defaultValue.split(":")[0];
928         if(defaultValue === "NA") {
929         defaultValue = "";
930         }        
931     }
932     if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
933         document.getElementById(checkKey).value = defaultValue;
934     }
935     }
936     
937     if($scope.temp.policy.ruleData != null){
938     if (attributeManyKey){
939         var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
940         if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){
941           document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
942         }
943     }else{
944         if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
945             document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
946         }
947     }
948     } 
949     plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);    
950
951     };
952     
953     $scope.labelManyKeys = [];
954     $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
955     var label = document.createElement("Label")
956     var divID = labelValue;
957     if (labelValue.endsWith('.')){
958     var workingLabel = labelValue.substring(0, labelValue.length-1);
959     }else {
960     var workingLabel = labelValue;
961     }
962     
963     if (labelValue.length  < 1){
964     divID = "DynamicTemplate";
965     } else if (labelValue.endsWith('.')){
966     var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
967     }
968     
969     var subAttributes = $scope.optimizationModelData.subattributes;
970         var jsonObject = JSON.parse(subAttributes);    
971         var lablInfo = findVal(jsonObject, lableName);
972     var star = "";
973     var required = null;
974     if(lablInfo){
975     if(lablInfo.includes("required-true")){
976         star = " *";
977         required = true;
978     }else if (lablInfo.includes("required-false")){
979         required = false
980     }
981     }
982     
983     var labeltext = document.createTextNode(lableName + star);
984     
985     label.appendChild(labeltext);
986
987
988     if(labelManyKey){
989     var addButton = document.createElement("BUTTON");
990     var buttonLabel = document.createTextNode("+");       
991     addButton.appendChild(buttonLabel); 
992     addButton.setAttribute("class", "btn btn-add-remove");
993     addButton.setAttribute("ng-click" ,  'addNewChoice("'+labelValue + lableName+'");');
994     addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
995     var removeButton = document.createElement("BUTTON");
996     var buttonremoveLabel = document.createTextNode("-");       
997     removeButton.appendChild(buttonremoveLabel); 
998     removeButton.setAttribute("class", "btn btn-add-remove");
999     removeButton.setAttribute("ng-click" ,  'removeChoice("'+labelValue +lableName+'");');
1000     removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly"); 
1001     document.getElementById(divID).appendChild(addButton); 
1002     document.getElementById(divID).appendChild(removeButton);
1003     document.getElementById(divID).appendChild(label);
1004     var id = "div."+labelValue+lableName;
1005     var divTag = document.createElement("div");
1006     divTag.setAttribute("id", id); 
1007     document.getElementById(divID).appendChild(divTag);
1008     
1009     var divTag = document.createElement("div");
1010     divTag.setAttribute("id", id +'@0');  
1011     
1012     divTag.className += ' children_group'; //here is div with a group of children.
1013     
1014     if(required){
1015        divTag.setAttribute("required", required);  
1016     }else if(required == false){
1017        divTag.setAttribute("data-conditional", "yes");  
1018     }
1019     
1020     document.getElementById(id).appendChild(divTag);
1021     
1022     $scope.labelManyKeys.push(lableName);
1023     
1024     }else{
1025     var divTag = document.createElement("div");
1026     divTag.setAttribute("id", "div."+labelValue+lableName);
1027     divTag.className += ' children_group'; //here is div with a group of children.
1028     if(required){
1029         divTag.setAttribute("required", required);  
1030     }else if(required == false){
1031         divTag.setAttribute("data-conditional", "yes");  
1032     }  
1033     document.getElementById(divID).appendChild(label);  
1034     document.getElementById(divID).appendChild(divTag);    
1035     }
1036     };
1037
1038     $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues, isRequired){
1039     var br = document.createElement("BR");
1040     
1041     if (labelLevel.length  < 1){
1042         var divID = "DynamicTemplate";
1043     } else if (labelLevel.endsWith('.')){
1044         var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1045     }    
1046     
1047     
1048     var label = document.createElement("Label")
1049     
1050     var refAttributes = $scope.optimizationModelData.ref_attributes;
1051     if(isRequired != true && refAttributes){ //check refAttributes also    
1052            var refAttributesList = refAttributes.split(splitComma);
1053            for (k = 0; k < refAttributesList.length; k++){
1054                var refAttribute = refAttributesList[k].split(splitEqual);               
1055                if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
1056                isRequired = true;
1057                }
1058            }
1059     }
1060     
1061     if (matching.includes(attributeName)){
1062     var labeltext = document.createTextNode(attributeName + "*!");
1063     label.appendChild(labeltext);
1064     isRequired = true;  //set required as true for matching element
1065     }else {
1066     var labeltext = document.createTextNode(attributeName);    
1067     if(isRequired){
1068         var requiredLabName = attributeName+ " * ";
1069         labeltext = document.createTextNode(requiredLabName);
1070     }else{
1071         labeltext = document.createTextNode(attributeName);    
1072     }
1073     
1074         label.appendChild(labeltext);    
1075     }
1076     label.appendChild(labeltext);
1077     // if this field is required, but its parent is not required
1078     if(isRequired && document.getElementById(divID).hasAttribute('data-conditional')){
1079        var requiredNode = document.createElement('span');
1080     requiredNode.setAttribute("class", "mstooltip");
1081     requiredNode.textContent = "?";
1082     label.appendChild(requiredNode);
1083         
1084     var requiredNodeToolTip = document.createElement('span');
1085     requiredNodeToolTip.setAttribute("class", "tooltiptext");
1086     requiredNodeToolTip.textContent = "Conditional Required";
1087     requiredNode.appendChild(requiredNodeToolTip);
1088
1089     }
1090     
1091     var listField = document.createElement("SELECT");
1092     listField.setAttribute("class" , "form-control");
1093     listField.setAttribute("style" , "width:300px;");
1094     listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1095     
1096     if(isRequired){
1097         if(document.getElementById(divID).hasAttribute('data-conditional')){
1098         listField.setAttribute("data-conditional", divID);
1099         listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1100         }else{
1101         listField.setAttribute("required", true);
1102         }
1103     }
1104     if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element
1105     var optionFirst = document.createElement('option');
1106     optionFirst.setAttribute('value', "");
1107     listField.appendChild(optionFirst);    
1108     }
1109     
1110     for (var i=0; i < listemunerateValues.length; i += 1) {
1111     if(typeof listemunerateValues[i] == "string" && listemunerateValues[i].includes("equal-sign")){
1112         listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','=');
1113     }
1114         var option = document.createElement('option');
1115         option.setAttribute('value', listemunerateValues[i]);
1116         option.appendChild(document.createTextNode(listemunerateValues[i]));
1117         option.setAttribute('value', listemunerateValues[i]);
1118         listField.appendChild(option);
1119     }
1120     listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1121     
1122     enumKeyList.push(attributeName);
1123     
1124     document.getElementById(divID).appendChild(label);  
1125     document.getElementById(divID).appendChild(br);    
1126         
1127     if(many == true){
1128     document.getElementById(divID).appendChild(listField).multiple = true;
1129     plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1130     }else {
1131     document.getElementById(divID).appendChild(listField).multiple = false;
1132     plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1133     }
1134     
1135     if($scope.temp.policy.ruleData != null){
1136     if (many == true){
1137         document.getElementById(labelLevel +attributeName).options[0].selected = false;
1138         for (i=0; i < listemunerateValues.length; i += 1) {
1139         var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
1140         if (testValue === undefined){
1141             testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
1142             }
1143         var location = listemunerateValues.indexOf(testValue);
1144         if (location!=-1){
1145             document.getElementById(labelLevel +attributeName).options[location].selected = true;
1146             }
1147         }    
1148         }else {
1149             if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1150                         document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];    
1151             }
1152         }
1153     }
1154         };
1155     
1156     function onlyUnique(value, index, self) { 
1157         return self.indexOf(value) === index;
1158     };
1159     
1160     $scope.savePolicy = function(policy){
1161     if(policy.itemContent != undefined){
1162         $scope.refreshCheck = true; 
1163         $scope.policyNavigator = policy.itemContent;
1164         policy.itemContent = "";
1165     }
1166     $scope.savebutton = false;
1167     var splitAt = '*';
1168     var dot ='.';
1169     var jsonPolicy = {};
1170     if(plainAttributeKeys != null){
1171         for(a = 0; a < plainAttributeKeys.length; a++){
1172         var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1173         var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1174         var key = splitPlainAttributeKey[0];
1175         
1176                 if(searchElement == null || searchElement.nodeName == 'BUTTON'){
1177                     searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1178                     key = splitPlainAttributeKey[0]+'@0';
1179                 }
1180                 
1181         if(searchElement != null){
1182             var keySplit = key.split(dot);
1183             var elumentLocation = keySplit.length;
1184             var enumKey = key;
1185             if (elumentLocation > 1){
1186             enumKey = keySplit[keySplit.length - 1];
1187             }
1188             //check it is undefined or not
1189             if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){
1190             if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){
1191             var multiSlect = [];
1192             for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1193                 multiSlect.push(searchElement.selectedOptions[i].value);
1194                 }
1195             jsonPolicy[key]= multiSlect;
1196             }else{
1197             jsonPolicy[key]= searchElement.value;
1198             }
1199             } else {
1200                 if(searchElement.value != null){
1201                 jsonPolicy[key]= searchElement.value;
1202                 }
1203             }
1204         }
1205         }
1206     }
1207         var uuu = "policycreation/save_policy";
1208         var postData={policyData: policy, policyJSON : jsonPolicy};
1209         $.ajax({
1210             type : 'POST',
1211             url : uuu,
1212             dataType: 'json',
1213             contentType: 'application/json',
1214             data: JSON.stringify(postData),
1215             success : function(data){
1216                 $scope.$apply(function(){
1217                 $scope.data=data.policyData;
1218                 if($scope.data == 'success'){
1219                     $scope.temp.policy.readOnly = 'true';
1220                     $scope.safetyChecker = data.policyData.split("#")[2];
1221                     if ($scope.safetyChecker!=undefined) {
1222                     Notification.success($scope.safetyChecker);
1223                     }
1224                     $scope.pushStatus=data.policyData.split("&")[1];
1225                     if($scope.pushStatus=="successPush"){
1226                     Notification.success("Policy pushed successfully");
1227                     }
1228                     Notification.success("Policy Saved Successfully.");    
1229                 }else if ($scope.data == 'PolicyExists'){
1230             $scope.savebutton = true;
1231             Notification.error("Policy Already Exists with Same Name in Scope.");
1232         }
1233                 });
1234             },
1235             error : function(data){
1236             Notification.error("Error Occured while saving Policy.");
1237             }
1238         });
1239     };
1240     
1241     $scope.validatePolicy = function(policy){
1242     document.getElementById("validate").innerHTML = "";
1243     var splitAt = '*';
1244     var dot ='.';
1245     var jsonPolicy = {};
1246     if(plainAttributeKeys != null){
1247         for(a = 0; a < plainAttributeKeys.length; a++){
1248         var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1249         var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1250         var key = splitPlainAttributeKey[0];
1251         if(searchElement == null || searchElement.nodeName == 'BUTTON'){
1252             searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1253             key = splitPlainAttributeKey[0]+'@0';
1254         }
1255         if(searchElement != null){
1256             if (enumKeyList.indexOf(key) != -1){
1257             if (splitPlainAttributeKey[1].indexOf("true") !== -1){
1258             var multiSlect = [];
1259             for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1260                 multiSlect.push(searchElement.selectedOptions[i].value);
1261                 }
1262             jsonPolicy[key]= multiSlect;
1263             }else{
1264             jsonPolicy[key]= searchElement.value;
1265             }
1266             if(searchElement.getAttribute("required")){
1267                 if(!searchElement.value){
1268                 return;
1269                 }
1270             } 
1271             } else {
1272                 if(searchElement.value != null){
1273                 jsonPolicy[key]= searchElement.value;
1274                 if(searchElement.getAttribute("required")){
1275                     if(!searchElement.value){
1276                     return;
1277                     }
1278                 }                
1279                 }
1280             }
1281         }
1282         }
1283     }
1284         var uuu = "policyController/validate_policy.htm";        
1285         var postData={policyData: policy, policyJSON : jsonPolicy};
1286      $.ajax({
1287      type : 'POST',
1288      url : uuu,
1289      dataType: 'json',
1290      contentType: 'application/json',
1291      data: JSON.stringify(postData),
1292      success : function(data){
1293          $scope.$apply(function(){
1294          $scope.validateData = data.data.replace(/\"/g, "");
1295         $scope.data=data.data.substring(1,8);
1296             var size = data.data.length;
1297             if($scope.data == 'success'){
1298             Notification.success("Validation Success.");
1299             $scope.savebutton = false;
1300             if (size > 18){
1301                 var displayWarning = data.data.substring(19,size  - 1);
1302                 document.getElementById("validate").innerHTML = "Safe Policy Warning Message  :  "+displayWarning;
1303                 document.getElementById("validate").style.color = "white";
1304                 document.getElementById("validate").style.backgroundColor = "skyblue";
1305             }
1306              }else{
1307              Notification.error("Validation Failed.");
1308              document.getElementById("validate").innerHTML = $scope.validateData;
1309              document.getElementById("validate").style.color = "white";
1310              document.getElementById("validate").style.backgroundColor = "red";
1311              $scope.savebutton = true;
1312              }
1313              
1314          });
1315      },
1316      error : function(data){
1317          Notification.error("Validation Failed.");
1318          $scope.savebutton = true;
1319      }
1320      });
1321     };
1322
1323     function extend(obj, src) {
1324         for (var key in src) {
1325             if (src.hasOwnProperty(key)) obj[key] = src[key];
1326         }
1327         return obj;
1328     }
1329 }]);/**
1330  * 
1331  */