rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / lifecyclemgr / src / main / webapp / lifecyclemgr / js / underlay.js
1 /* Copyright 2016-2017, Huawei Technologies Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 var url = {};
17 $.getJSON("./conf/dataconfig.json", function (jsonData){
18     url.overlay = jsonData.url +":"+ jsonData.port + "/org.openo.sdno.overlayvpnservice";
19     url.underlay = jsonData.url +":"+ jsonData.port + "/org.openo.sdno.l3vpnservice";
20     console.log("URL = " + JSON.stringify(url));
21 });
22
23 function loadUnderlayData() {
24     var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns";
25     $
26         .ajax({
27             type: "GET",
28             url: requestUrl,
29             contentType: "application/json",
30             success: function (jsonobj) {
31                 alert("loading underlay data");
32                 //TODO: Update the table
33             },
34             error: function (xhr, ajaxOptions, thrownError) {
35                 //alert("Error on getting underlay data : " + xhr.responseText);
36             }
37         });
38 }
39 function deleteUnderlayData(objectId) {
40     var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns/" + objectId;
41     $
42         .ajax({
43             type: "DELETE",
44             url: requestUrl,
45             contentType: "application/json",
46             success: function (jsonobj) {
47                 alert("deleting underlay data");
48                 //TODO: Update the table
49             },
50             error: function (xhr, ajaxOptions, thrownError) {
51                 alert("Error on deleting underlay data : " + xhr.responseText);
52             }
53         });
54 }
55 function loadOverlayData() {
56     var requestUrl =  "/openoapi/sdnooverlayvpn/v1/site2dc-vpn";
57     $
58         .ajax({
59             type: "GET",
60             url: requestUrl,
61             contentType: "application/json",
62             success: function (jsonobj) {
63                 alert("loading Overlay data...");
64                 //TODO: Update the table
65             },
66             error: function (xhr, ajaxOptions, thrownError) {
67                 //alert("Error on getting Overlayvpn data : " + xhr.responseText);
68             }
69         });
70 }
71 function refressTpDataTable(overlayTable, TpTable) {
72     alert("refesssing Tp data table");
73 }
74 $(function () {
75     $.fn.serializeObject = function () {
76         var o = {};
77         var a = this.serializeArray();
78         $.each(a, function () {
79             if (o[this.name] !== undefined) {
80                 if (!o[this.name].push) {
81                     o[this.name] = [o[this.name]];
82                 }
83                 o[this.name].push(this.value || '');
84             } else {
85                 o[this.name] = this.value || '';
86             }
87         });
88         return o;
89     };
90     $('#createUnderlay').click(function () {
91         var formData = JSON.stringify($("#underlayForm").serializeObject());
92         alert(formData);
93         var jsonobj = JSON.parse(formData);
94         var requestUrl = "/openoapi/sdnol3vpn/v1/l3vpns";
95         $
96             .ajax({
97                 type: "POST",
98                 url: requestUrl,
99                 contentType: "application/json",
100                 dataType: "json",
101                 data: formData,
102                 success: function (jsonobj) {
103                     alert("Details saved successfully!!!");
104                     //var data = [jsonobj.name,jsonobj.hostName,jsonobj.productName,jsonobj.vendor,jsonobj.description];
105                     //TODO: update the table
106                 },
107                 error: function (xhr, ajaxOptions, thrownError) {
108                     alert("Error on page : " + xhr.responseText);
109                 }
110             });
111     });
112     $('.underlayNameLink').click(function () {
113         alert("coming here");
114         var data = $(this).parent().parent().parent().find('td:last').find('div:last').html();
115         alert(data);
116         var jsonObj = JSON.parse(data);
117         for (var i = 0; i < jsonObj.length; i++) {
118             var obj = jsonObj[i];
119             var rowData = [obj.tpName, obj.peName, obj.vlanId, obj.siteCidr, obj.ip];
120             $('#underlayTpDataTable').DataTable();
121             $('#underlayTpDataTable').dataTable().fnAddData(rowData);
122         }
123
124     });
125
126 })