Remove SDC query
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / aOnBoot.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
24
25 //When element is first created it should have a red box because it hasn't been edited
26 function newElementProcessor(id) {
27   if ($('g[data-element-id="' + id + '"]').length > 0) {
28
29     var _idNode = $('g[data-element-id="' + id + '"]')
30     _idNode.children("rect").each(function() {
31       if ($(this).attr('class') === 'djs-outline') {
32         $(this).attr('class', "djs-outline-no-property-saved")
33         $(this).attr('fill', 'red')
34       }
35     });
36
37   }
38 }
39
40 function saveProperties(form) {
41   elementMap[lastElementSelected] = form;
42   totalJsonProperties = JSON.stringify(elementMap);
43
44   //Take off the red border because the element has been edited
45   if ($('g[data-element-id="' + lastElementSelected + '"]').length > 0) {
46     var _idNode = $('g[data-element-id="' + lastElementSelected + '"]')
47     _idNode.children("rect").each(function() {
48       if ($(this).attr('class') === 'djs-outline-no-property-saved') {
49         $(this).attr('class', "djs-outline")
50         $(this).attr('fill', 'none')
51       }
52     });
53   }
54 }
55
56 function saveGlobalProperties(form) {
57   elementMap["global"] = form;
58 }
59 var isObject = function(a) {
60   return (!!a) && (a.constructor === Object);
61 };
62
63 function loadPropertyWindow(type) {
64   if (readMOnly) {
65     if ($("#add_one_more").length == 1) {
66       $("#add_one_more").off();
67       $("#add_one_more").click(function(event) {
68         event.preventDefault();
69       })
70     }
71     $("input,#savePropsBtn").attr("disabled", "");
72     $(".modal-body button").attr("disabled", "");
73     ($("select:not([multiple])")).multiselect("disable");
74   }
75
76   var props = defaults_props[type];
77
78   for (p in props) {
79     if (isObject(props[p])) {
80       var mySelect = $('#' + p);
81       if (p == "operator") {
82         $.each(props[p], function(val, text) {
83           mySelect.append(
84             $('<option></option>').val(val).html(val)
85           );
86         });
87       } else {
88         $.each(props[p], function(val, text) {
89           mySelect.append(
90             $('<option></option>').val(val).html(text)
91           );
92         });
93       }
94     } else {
95       if (p == "pname") {
96         var ms = new Date().getTime();
97         props[p] = "Policy" + ms;
98       }
99       $("#" + p).val(props[p])
100     }
101   }
102   setTimeout(function() {
103     setMultiSelect(type);
104   }, 100);
105
106
107
108 }
109
110 function setMultiSelect() {
111   $("select").each(function(index, mySelect) {
112
113     var mySelectObj = $(mySelect);
114     if (! mySelectObj.parents(".multiselect-native-select")) {
115       // keep native for this one
116       return;
117     }
118
119     if (mySelectObj.parents(".multiselect-native-select").length > 0) {
120       var selectDrop = mySelectObj.parent(".multiselect-native-select").find("select");
121       mySelectObj.parent(".multiselect-native-select").parent().html(selectDrop);
122     }
123
124     var options = {
125       numberDisplayed: 1,
126       maxHeight: 200
127     };
128
129     if (mySelectObj.attr("multiple")
130         && mySelectObj.attr("multiple") != 'false') {
131       options.includeSelectAllOption = true;
132     }
133     
134     if (mySelectObj.attr("enableFilter")
135         && mySelectObj.attr("enableFilter") != 'false') {
136       options.enableCaseInsensitiveFiltering = true;
137       options.enableFiltering = true;
138     }
139
140     mySelectObj.multiselect(options);
141   });
142 }
143
144 function loadSharedPropertyByService(onChangeUUID, refresh, callBack) {
145       setASDCFields()
146 }
147
148 function loadSharedPropertyByServiceProperties(callBack) {
149   $.ajax({
150     async: false,
151     dataType: "json",
152     url: '/restservices/clds/v1/clds/properties/',
153     success: function(data) {
154       vf_Services = JSON.parse(data);
155       setASDCFields();
156       if (callBack && _.isFunction(callBack)) {
157         callBack(true);
158       }
159     },
160     error: function(s, a, err) {
161       $('#servName').text($("#service option:selected").text());
162       if (callBack && _.isFunction(callBack)) {
163         callBack(false);
164       }
165     },
166     timeout: 100000
167
168   });
169 }
170
171 function setASDCFields() {
172     try {
173       var location_values = defaults_props['global']['location'];
174       if (location_values) {
175         for (key in location_values) {
176           if ($("#location").length > 0) {
177             $("#location").append("<option value=\"" + key + "\">" + location_values[key] + "</opton>")
178           }
179         }
180         $("#location").multiselect("rebuild");
181       }
182
183       var actionSet_values = defaults_props['global']['actionSet'];
184       if (actionSet_values) {
185         for (key in actionSet_values) {
186           if ($("#actionSet").length > 0) {
187             $("#actionSet").append("<option value=\"" + key + "\">" + actionSet_values[key] + "</opton>")
188           }
189         }
190         $("#actionSet").multiselect("rebuild");
191       }
192       if ($("#location").length > 0 && !location_values) {
193         showWarn();
194       }
195
196       function showWarn() {
197         $("#paramsWarn").show();
198         $('#servName').text($("#service option:selected").text());
199       }
200     } catch (e) {
201       console.log(e)
202     }
203  
204 }
205
206 //Typically used when opening a new model/template
207 function reloadDefaultVariables(isTemp) {
208   isTemplate = isTemp;
209   vf_Services = null;
210 }
211
212 $(window).on('load',function() {
213   $.ajax({
214     dataType: "json",
215     url: '/restservices/clds/v1/clds/properties',
216     success: function(data) {
217       defaults_props = JSON.parse(data);
218     },
219     error: function(s, a, err) {
220       console.log(err)
221       console.log(s)
222       console.log(a)
223     },
224     timeout: 100000
225   });
226 })