CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-lifecyclemgr / src / main / webapp / lifecyclemgr / js / underlay.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 $.getJSON("./conf/dataconfig.json", function (jsonData){\r
18     url.overlay = jsonData.url +":"+ jsonData.port + "/org.openo.sdno.overlayvpnservice";\r
19     url.underlay = jsonData.url +":"+ jsonData.port + "/org.openo.sdno.l3vpnservice";\r
20     console.log("URL = " + JSON.stringify(url));\r
21 });\r
22 \r
23 function loadUnderlayData() {\r
24     var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns";\r
25     $\r
26         .ajax({\r
27             type: "GET",\r
28             url: requestUrl,\r
29             contentType: "application/json",\r
30             success: function (jsonobj) {\r
31                 alert("loading underlay data");\r
32                 //TODO: Update the table\r
33             },\r
34             error: function (xhr, ajaxOptions, thrownError) {\r
35                 //alert("Error on getting underlay data : " + xhr.responseText);\r
36             }\r
37         });\r
38 }\r
39 function deleteUnderlayData(objectId) {\r
40     var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns/" + objectId;\r
41     $\r
42         .ajax({\r
43             type: "DELETE",\r
44             url: requestUrl,\r
45             contentType: "application/json",\r
46             success: function (jsonobj) {\r
47                 alert("deleting underlay data");\r
48                 //TODO: Update the table\r
49             },\r
50             error: function (xhr, ajaxOptions, thrownError) {\r
51                 alert("Error on deleting underlay data : " + xhr.responseText);\r
52             }\r
53         });\r
54 }\r
55 function loadOverlayData() {\r
56     var requestUrl =  "/openoapi/sdnooverlayvpn/v1/site2dc-vpn";\r
57     $\r
58         .ajax({\r
59             type: "GET",\r
60             url: requestUrl,\r
61             contentType: "application/json",\r
62             success: function (jsonobj) {\r
63                 alert("loading Overlay data...");\r
64                 //TODO: Update the table\r
65             },\r
66             error: function (xhr, ajaxOptions, thrownError) {\r
67                 //alert("Error on getting Overlayvpn data : " + xhr.responseText);\r
68             }\r
69         });\r
70 }\r
71 function refressTpDataTable(overlayTable, TpTable) {\r
72     alert("refesssing Tp data table");\r
73 }\r
74 $(function () {\r
75     $.fn.serializeObject = function () {\r
76         var o = {};\r
77         var a = this.serializeArray();\r
78         $.each(a, function () {\r
79             if (o[this.name] !== undefined) {\r
80                 if (!o[this.name].push) {\r
81                     o[this.name] = [o[this.name]];\r
82                 }\r
83                 o[this.name].push(this.value || '');\r
84             } else {\r
85                 o[this.name] = this.value || '';\r
86             }\r
87         });\r
88         return o;\r
89     };\r
90     $('#createUnderlay').click(function () {\r
91         var formData = JSON.stringify($("#underlayForm").serializeObject());\r
92         alert(formData);\r
93         var jsonobj = JSON.parse(formData);\r
94         var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns";\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 (jsonobj) {\r
103                     alert("Details saved successfully!!!");\r
104                     //var data = [jsonobj.name,jsonobj.hostName,jsonobj.productName,jsonobj.vendor,jsonobj.description];\r
105                     //TODO: update the table\r
106                 },\r
107                 error: function (xhr, ajaxOptions, thrownError) {\r
108                     alert("Error on page : " + xhr.responseText);\r
109                 }\r
110             });\r
111     });\r
112     $('.underlayNameLink').click(function () {\r
113         alert("coming here");\r
114         var data = $(this).parent().parent().parent().find('td:last').find('div:last').html();\r
115         alert(data);\r
116         var jsonObj = JSON.parse(data);\r
117         for (var i = 0; i < jsonObj.length; i++) {\r
118             var obj = jsonObj[i];\r
119             var rowData = [obj.tpName, obj.peName, obj.vlanId, obj.siteCidr, obj.ip];\r
120             $('#underlayTpDataTable').DataTable();\r
121             $('#underlayTpDataTable').dataTable().fnAddData(rowData);\r
122         }\r
123 \r
124     });\r
125 \r
126 })