Remove SDC query
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / GlobalPropertiesCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * 
22  */
23 app.controller('GlobalPropertiesCtrl', [
24 '$scope',
25 '$rootScope',
26 '$uibModalInstance',
27 'cldsModelService',
28 '$location',
29 'dialogs',
30 'cldsTemplateService',
31 function($scope, $rootScope, $uibModalInstance, cldsModelService, $location,
32          dialogs, cldsTemplateService) {
33         $scope.$watch('name', function(newValue, oldValue) {
34
35                 setASDCFields()
36
37                 var el = elementMap["global"];
38                 if (el !== undefined) {
39                         for (var i = 0; i < el.length; i++) {
40                                 if (el[i].name === 'deployParameters')
41                                 {
42                                         // This is a special case, that value is not a string but a JSON
43                                         $("#" + el[i].name).val(JSON.stringify(el[i].value));
44                                 } else {
45                                         $("#" + el[i].name).val(el[i].value);
46                                 }
47                         }
48                 }
49                 setMultiSelect();
50                 if (readMOnly) {
51                         $("#savePropsBtn").attr("disabled", "");
52                         $('select[multiple] option').each(function() {
53                                 var input = $('input[value="' + $(this).val() + '"]');
54                                 input.prop('disabled', true);
55                                 input.parent('li').addClass('disabled');
56                         });
57                         $('input[value="multiselect-all"]').prop('disabled', true).parent(
58                         'li').addClass('disabled');
59                         ($("select:not([multiple])")).multiselect("disable");
60                 }
61         });
62         $scope.retry = function() {
63                 console.log("retry");
64         }
65         $scope.close = function() {
66                 console.log("close");
67                 $uibModalInstance.close("closed");
68         };
69     $scope.convertDeployParametersJsonToString = function() {
70         var index = elementMap["global"].findIndex(function(e) {
71                 return (typeof e == "object" && !(e instanceof Array))
72                 && "deployParameters" == e["name"];
73         });
74         if (index != -1) {
75                 $('#deployParameters').val(JSON.stringify(elementMap["global"][index].value));
76         }
77     }
78     
79     function noRepeats(form) {
80         var select = {};
81         for (var i = 0; i < form.length; i++) {
82                 if (form[i].hasOwnProperty("name")) {
83                         if (form[i].name === 'deployParameters') {
84                                         // This is a special case, that value MUST not be a string but a JSON
85                                 select[form[i].name]=JSON.parse(form[i].value);
86                         } else {
87                                 if (select[form[i].name] === undefined)
88                                         select[form[i].name] = []
89                                 select[form[i].name].push(form[i].value);
90                         }
91                 }
92         }
93         var arr = []
94         for (s in select) {
95                 var f = {}
96                 f.name = s
97                 f.value = select[s]
98                 if (!(s == "service" && f.value == "")) {
99                         arr.push(f)
100                 }
101         }
102         return arr
103     }
104     
105     $scope.submitForm = function() {
106         saveGlobalProperties(noRepeats($("#saveProps").serializeArray()))
107         //module reset, based on property updates
108         if (elementMap["global"]) {
109                 $.each(Object.keys(elementMap), function(i, v) {
110                         if ((v.match(/^Policy/)) && asDiff) {
111                                 elementMap[v] = {};
112                         }
113                         if ((v.match(/^TCA/)) && (vfDiff || serDiff)) {
114                                 elementMap[v] = {};
115                         }
116                 });
117         }
118         $uibModalInstance.close();
119     }
120   
121 } ]);