e9ff499613f631f0e4235094cdace05e9ba9a158
[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 function($scope, $rootScope, $uibModalInstance, cldsModelService, $location,
31          dialogs) {
32         $scope.$watch('name', function(newValue, oldValue) {
33
34                 var el = getGlobalProperty();
35                 if (el !== undefined) {
36                         for (var i = 0; i < el.length; i++) {
37                                 if (el[i].name === 'deployParameters')
38                                 {
39                                         // This is a special case, that value is not a string but a JSON
40                                         $("#" + el[i].name).val(JSON.stringify(el[i].value));
41                                 } else {
42                                         $("#" + el[i].name).val(el[i].value);
43                                 }
44                         }
45                 }
46                 setMultiSelect();
47                 if (readMOnly) {
48                         $("#savePropsBtn").attr("disabled", "");
49                         $('select[multiple] option').each(function() {
50                                 var input = $('input[value="' + $(this).val() + '"]');
51                                 input.prop('disabled', true);
52                                 input.parent('li').addClass('disabled');
53                         });
54                         $('input[value="multiselect-all"]').prop('disabled', true).parent(
55                         'li').addClass('disabled');
56                         ($("select:not([multiple])")).multiselect("disable");
57                 }
58         });
59         $scope.retry = function() {
60                 console.log("retry");
61         }
62         $scope.close = function() {
63                 console.log("close");
64                 $uibModalInstance.close("closed");
65         };
66
67     function noRepeats(form) {
68         var select = {};
69         for (var i = 0; i < form.length; i++) {
70                 if (form[i].hasOwnProperty("name")) {
71                         if (form[i].name === 'deployParameters') {
72                                         // This is a special case, that value MUST not be a string but a JSON
73                                 select[form[i].name]=JSON.parse(form[i].value);
74                         } else {
75                                 if (select[form[i].name] === undefined)
76                                         select[form[i].name] = []
77                                 select[form[i].name].push(form[i].value);
78                         }
79                 }
80         }
81         var arr = []
82         for (s in select) {
83                 var f = {}
84                 f.name = s
85                 f.value = select[s]
86                 if (!(s == "service" && f.value == "")) {
87                         arr.push(f)
88                 }
89         }
90         return arr
91     }
92     
93     $scope.submitForm = function() {
94         saveGlobalProperties(noRepeats($("#saveProps").serializeArray()))
95         $uibModalInstance.close();
96     }
97   
98 } ]);