CLIENT GUI Framework
[vnfsdk/refrepo.git] / portal-lifecyclemgr / src / main / webapp / lifecyclemgr / js / rest.js
1 /* Copyright 2016-2017, Huawei Technologies Co., Ltd.\r
2  *\r
3  * Licensed under the Apache License, Version 2.0 (the "License");\r
4  * you may not use this file except in compliance with the License.\r
5  * You may obtain a copy of the License at\r
6  *\r
7  *    http://www.apache.org/licenses/LICENSE-2.0\r
8  *\r
9  * Unless required by applicable law or agreed to in writing, software\r
10  * distributed under the License is distributed on an "AS IS" BASIS,\r
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12  * See the License for the specific language governing permissions and\r
13  * limitations under the License.\r
14  */\r
15 \r
16 var url = "";\r
17 $(function () {\r
18 \r
19     $.getJSON("./conf/dataconfig.json", function (jsonData){\r
20         url = jsonData.url +":"+ jsonData.port;\r
21         console.log("URL = " + url);\r
22     });\r
23 \r
24     $('.creat-btn').click(function () {\r
25         /*$('#vmAppDialog').addClass('in').css({'display': 'block'});*/\r
26         $('#vmAppDialog').modal();\r
27 \r
28     });\r
29     $('.close,.button-previous').click(function () {\r
30         $('#vmAppDialog').removeClass('in').css('display', 'none');\r
31     });\r
32     $('.detail-top ul li').click(function () {\r
33         $(this).addClass('current').siblings().removeClass('current');\r
34     });\r
35     $('.para').click(function () {\r
36         if ($('#serviceTemplateName').val() == '') {\r
37             alert('Please choose the service templateļ¼');\r
38             $('#flavorTab').css('display', 'none');\r
39         } else {\r
40             $('#flavorTab').css('display', 'block');\r
41         }\r
42         $('#basicTab').css('display', 'block');\r
43     });\r
44     $('.basic').click(function () {\r
45         $('#flavorTab').css('display', 'none');\r
46     });\r
47 /*\r
48     $('.table tbody tr').click(function(){\r
49         $(this).addClass('openoTable_row_selected').siblings().removeClass('openoTable_row_selected');\r
50     });*/\r
51     $('.table tr:odd').addClass('active');\r
52     $('#false').click(function () {\r
53         /*$('#vmAppDialog').addClass('in').css({'display': 'block'});*/\r
54     $('#vmAppDialog').modal();\r
55     });\r
56     $('.close,.button-previous').click(function () {\r
57         $('#vmAppDialog').removeClass('in').css('display', 'none');\r
58     });\r
59     $('#filterTpLogicalType').click(function () {\r
60         $('#filterTpLogicalType_select_popupcontainer').toggleClass('openo-hide');\r
61         $('#filterTpLogicalType').toggleClass('openo-focus');\r
62         var oLeft = $('#open_base_tpL_td6').offset().left;\r
63         var oTop = $('#open_base_tpL_td6').offset().top;\r
64         var oHeight = $('#open_base_tpL_td6').height();\r
65         $('#filterTpLogicalType_select_popupcontainer').css({'left': oLeft, 'top': oTop + oHeight + 10});\r
66     });\r
67     $('div.openo-select-popup-container>div.openo-select-item>label').click(function () {\r
68         var Lvalue = $(this).html();\r
69         $('#filterTpLogicalType_select_input').attr('value', Lvalue);\r
70         $('#filterTpLogicalType_select_popupcontainer').addClass('openo-hide');\r
71         $('#filterTpLogicalType').removeClass('openo-focus');\r
72     });\r
73     $.fn.serializeObject = function () {\r
74         var o = {};\r
75         var a = this.serializeArray();\r
76         $.each(a, function () {\r
77             if (o[this.name] !== undefined) {\r
78                 if (!o[this.name].push) {\r
79                     o[this.name] = [o[this.name]];\r
80                 }\r
81                 o[this.name].push(this.value || '');\r
82             } else {\r
83                 o[this.name] = this.value || '';\r
84             }\r
85         });\r
86         return o;\r
87     };\r
88     /*\r
89     $('#createNS').click(function(){\r
90         var formData = JSON.stringify($("#neForm").serializeObject());\r
91         var jsonobj = JSON.parse(formData);\r
92         var newJson = {"managedElement": jsonobj};\r
93         formData = JSON.stringify(newJson);\r
94         var requestUrl = url + "/openoapi/sdnobrs/v1/managed-elements";\r
95         $\r
96             .ajax({\r
97                 type : "POST",\r
98                 url : requestUrl,\r
99                 contentType : "application/json",\r
100                 dataType : "json",\r
101                 data : formData,\r
102                 success : function(jsonResp) {\r
103                     alert("NS saved successfully!!!");\r
104                     jsonobj["id"]= jsonResp.managedElement.id;\r
105                     $('#ne').bootstrapTable("append", jsonobj);\r
106                     $('#vmAppDialog').removeClass('in').css('display','none');\r
107 \r
108                 },\r
109                 error : function(xhr, ajaxOptions, thrownError) {\r
110                     alert("Error on page : " + xhr.responseText);\r
111                 }\r
112             });\r
113     });*/\r
114     //init the templates combo\r
115     $.when(\r
116             generateTemplatesComponent()\r
117         ).then(\r
118             function (templates) {\r
119                 document.getElementById("svcTempl").innerHTML = templates;\r
120             }\r
121         );\r
122 })\r
123 \r
124 /**\r
125  * generate the templates Component\r
126  * @returns\r
127  */\r
128 function generateTemplatesComponent(){\r
129     var defer = $.Deferred();\r
130     $.when(\r
131             queryTemplates()\r
132         ).then(\r
133             function (tmplatesResponse) {\r
134                 var templatesInfo = translateToTemplatesInfo(tmplatesResponse);\r
135                 defer.resolve(templatesInfo);\r
136             }\r
137         )\r
138     return defer;\r
139 }\r
140 \r
141 /**\r
142  * query templates\r
143  * @returns\r
144  */\r
145 function queryTemplates() {\r
146     var queryTemplatesUrl = '/openoapi/catalog/v1/servicetemplates';\r
147     return $.ajax({\r
148         type : "GET",\r
149         url : queryTemplatesUrl\r
150     });\r
151 }\r
152 \r
153 /**\r
154  * generate templates html string\r
155  * @param templates\r
156  * @returns\r
157  */\r
158 function translateToTemplatesInfo(templates) {\r
159     var options = '<option value="select">--select--</option>';\r
160     var i;\r
161     for (i = 0; i < templates.length; i += 1) {\r
162         var option = '<option value="' + templates[i].serviceTemplateId + '">' + templates[i].templateName\r
163                 + '</option>';\r
164         options = options + option;\r
165     }\r
166     return options;\r
167 }\r
168 \r
169 /*******************************************Get Service**********************************************/\r
170 function loadGetServiceData(){\r
171 \r
172     var returnVal = [];\r
173     var requestUrl = "/openoapi/inventory/v1/services";\r
174     var parameter = {\r
175             'sort': [],\r
176             'pagination': 0,\r
177             'pagesize': 10000,\r
178             'condition': {},\r
179             'serviceId': ""\r
180         };\r
181     $\r
182         .ajax({\r
183             type : "POST",\r
184             url : requestUrl,\r
185             async: false,\r
186             contentType : "application/json",\r
187             dataType: "json",\r
188             data: JSON.stringify(parameter),\r
189             success : function(jsonobj) {\r
190                 // TODO return according to the json data received.\r
191                 returnVal =  jsonobj;\r
192             },\r
193             error : function(xhr, ajaxOptions, thrownError) {\r
194                 alert("Error on getting link data : " + xhr.responseText);\r
195             }\r
196         });\r
197     return returnVal;\r
198 }\r
199 \r
200 /*********************************************Get Service Details********************************************/\r
201 function loadServiceDetails(serviceId){\r
202    \r
203    // TODO re-confirm the latest url.\r
204     var requestUrl ="/openoapi/gso/v1/services/toposequence/" + serviceId;\r
205     var returnObj;\r
206     $\r
207         .ajax({\r
208             type : "GET",\r
209             async: false,\r
210             url : requestUrl,\r
211             contentType : "application/json",\r
212             success : function(jsonobj) {\r
213                 // TODO return according to the json data received.\r
214                 returnObj = jsonobj;\r
215             },\r
216             error : function(xhr, ajaxOptions, thrownError) {\r
217                 alert("Error on getting link data : " + xhr.responseText);\r
218             }\r
219         });\r
220     return returnObj;\r
221 }\r
222 \r
223 \r
224 function anchorClick(serviceId){\r
225     var jsonData = loadServiceDetails(serviceId);\r
226     //TODO populate the modal according to json response\r
227     return true;\r
228 }\r