347d747201d3117353306171b0600d6736aaeaf7
[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 setMultiSelect() {
41   $("select").each(function(index, mySelect) {
42
43     var mySelectObj = $(mySelect);
44     if (! mySelectObj.parents(".multiselect-native-select")) {
45       // keep native for this one
46       return;
47     }
48
49     if (mySelectObj.parents(".multiselect-native-select").length > 0) {
50       var selectDrop = mySelectObj.parent(".multiselect-native-select").find("select");
51       mySelectObj.parent(".multiselect-native-select").parent().html(selectDrop);
52     }
53
54     var options = {
55       numberDisplayed: 1,
56       maxHeight: 200
57     };
58
59     if (mySelectObj.attr("multiple")
60         && mySelectObj.attr("multiple") != 'false') {
61       options.includeSelectAllOption = true;
62     }
63     
64     if (mySelectObj.attr("enableFilter")
65         && mySelectObj.attr("enableFilter") != 'false') {
66       options.enableCaseInsensitiveFiltering = true;
67       options.enableFiltering = true;
68     }
69
70     mySelectObj.multiselect(options);
71   });
72 }
73
74 function setPolicyOptions() {
75 console.log("reset policy default options");
76     try {
77       var actor_values = defaults_props['policy']['actor'];
78       if (actor_values) {
79         for (key in actor_values) {
80           if ($("#actor").length > 0) {
81             $("#actor").append("<option value=\"" + key + "\">" + actor_values[key] + "</opton>")
82           }
83         }
84         $("#actor").multiselect("rebuild");
85       }
86
87       var recipe_values = defaults_props['policy']['vnfRecipe'];
88       if (recipe_values) {
89         for (key in recipe_values) {
90           if ($("#recipe").length > 0) {
91             $("#recipe").append("<option value=\"" + key + "\">" + recipe_values[key] + "</opton>")
92           }
93         }
94         $("#recipe").multiselect("rebuild");
95       }
96       var parentPolicyConditions_values = defaults_props['policy']['parentPolicyConditions'];
97       if (parentPolicyConditions_values) {
98         for (key in parentPolicyConditions_values) {
99           if ($("#parentPolicyConditions").length > 0) {
100             $("#parentPolicyConditions").append("<option value=\"" + key + "\">" + parentPolicyConditions_values[key] + "</opton>")
101           }
102         }
103         $("#parentPolicyConditions").multiselect("rebuild");
104       }
105       var timeUnitsGuard_values = defaults_props['policy']['timeUnitsGuard'];
106       if (timeUnitsGuard_values) {
107         for (key in timeUnitsGuard_values) {
108           if ($("#timeUnitsGuard").length > 0) {
109             $("#timeUnitsGuard").append("<option value=\"" + key + "\">" + timeUnitsGuard_values[key] + "</opton>")
110           }
111         }
112         $("#timeUnitsGuard").multiselect("rebuild");
113       }
114       function showWarn() {
115         $("#paramsWarn").show();
116         $('#servName').text($("#service option:selected").text());
117       }
118     } catch (e) {
119       console.log(e)
120     }
121  
122 }
123
124
125 //Typically used when opening a new model/template
126 function reloadDefaultVariables(isTemp) {
127   isTemplate = isTemp;
128
129 }
130
131 $(window).on('load',function() {
132           $.ajax({
133             dataType: "json",
134             url: '/restservices/clds/v1/clds/properties',
135             success: function(data) {
136               defaults_props = JSON.parse(data);
137             },
138             error: function(s, a, err) {
139               console.log(err)
140               console.log(s)
141               console.log(a)
142             },
143             timeout: 100000
144           });
145 })
146