rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / lifecyclemgr / src / main / webapp / lifecyclemgr / js / vpn.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 = jsonData.url +":"+ jsonData.port;
19     console.log("URL = " + url);
20 });
21
22 function deleteSite(objectId) {
23     alert(objectId);
24     var requestUrl = "/openoapi/sdnobrs/v1/sites" + objectId;
25     $
26         .ajax({
27             type: "DELETE",
28             url: requestUrl,
29             contentType: "application/json",
30             success: function (jsonobj) {
31                 alert("Details deleted successfully!!!");
32                 //TODO: Update the table
33             },
34             error: function (xhr, ajaxOptions, thrownError) {
35                 //alert("Error on deleting site: " + xhr.responseText);
36             }
37         });
38 }
39 function deleteLink(objectId) {
40     var requestUrl = "/openoapi/sdnobrs/v1/topological-links" + objectId;
41     $
42         .ajax({
43             type: "DELETE",
44             url: requestUrl,
45             contentType: "application/json",
46             success: function (jsonobj) {
47                 alert("Details deleted successfully!!!");
48                 //TODO: Update the table
49             },
50             error: function (xhr, ajaxOptions, thrownError) {
51                 alert("Error on deleting link : " + xhr.responseText);
52             }
53         });
54 }
55
56 function deleteNe(objectId) {
57     var requestUrl = "/sdnobrs/v1/managed-elements" + objectId;
58     $
59         .ajax({
60             type: "DELETE",
61             url: requestUrl,
62             contentType: "application/json",
63             success: function (jsonobj) {
64                 alert("Details deleted successfully!!!");
65                 //TODO: Update the table
66             },
67             error: function (xhr, ajaxOptions, thrownError) {
68                 alert("Error on deleting ne : " + xhr.responseText);
69             }
70         });
71 }
72
73 function deletePort(objectId) {
74     var requestUrl = "/openoapi/sdnobrs/v1/logical-termination-points" + objectId;
75     $
76         .ajax({
77             type: "DELETE",
78             url: requestUrl,
79             contentType: "application/json",
80             success: function (jsonobj) {
81                 alert("Details deleted successfully!!!");
82                 //TODO: Update the table
83             },
84             error: function (xhr, ajaxOptions, thrownError) {
85                 alert("Error on deleting port : " + xhr.responseText);
86             }
87         });
88 }
89 function loadSiteData() {
90     var requestUrl = "/openoapi/sdnobrs/v1/sites";
91     $
92         .ajax({
93             type: "GET",
94             url: requestUrl,
95             contentType: "application/json",
96             success: function (jsonobj) {
97                 alert("loading Site data");
98                 //TODO: Update the table
99             },
100             error: function (xhr, ajaxOptions, thrownError) {
101                 alert("Error on getting site data : " + xhr.responseText);
102             }
103         });
104 }
105 function loadLinkData() {
106     var requestUrl = "/openoapi/sdnobrs/v1/topological-links";
107     $
108         .ajax({
109             type: "GET",
110             url: requestUrl,
111             contentType: "application/json",
112             success: function (jsonobj) {
113                 alert("loading Link data");
114                 //TODO: Update the table
115             },
116             error: function (xhr, ajaxOptions, thrownError) {
117                 alert("Error on getting link data : " + xhr.responseText);
118             }
119         });
120 }
121 function loadNeData() {
122     var requestUrl = "/sdnobrs/v1/managed-elements";
123     $
124         .ajax({
125             type: "GET",
126             url: requestUrl,
127             contentType: "application/json",
128             success: function (jsonobj) {
129                 alert("loading NE data");
130                 //TODO: Update the table
131             },
132             error: function (xhr, ajaxOptions, thrownError) {
133                 alert("Error on getting ne data : " + xhr.responseText);
134             }
135         });
136 }
137 function loadPortData() {
138     var requestUrl = "/openoapi/sdnobrs/v1/logical-termination-points";
139     $
140         .ajax({
141             type: "GET",
142             url: requestUrl,
143             contentType: "application/json",
144             success: function (jsonobj) {
145                 alert("loading port data");
146                 //TODO: Update the table
147             },
148             error: function (xhr, ajaxOptions, thrownError) {
149                 alert("Error on getting port data : " + xhr.responseText);
150             }
151         });
152 }
153 $(function () {
154     $('.creat-btn').click(function () {
155         $('#vmAppDialog').addClass('in').css({'display': 'block'});
156
157     });
158     $('.close,.button-previous').click(function () {
159         $('#vmAppDialog').removeClass('in').css('display', 'none');
160     });
161     $('.detail-top ul li').click(function () {
162         $(this).addClass('current').siblings().removeClass('current');
163     });
164     $('.para').click(function () {
165         if ($('#serviceTemplateName').val() == '') {
166             alert('Please choose the service templet!');
167             $('#flavorTab').css('display', 'none');
168         } else {
169             $('#flavorTab').css('display', 'block');
170         }
171         $('#basicTab').css('display', 'block');
172     });
173     $('.basic').click(function () {
174         $('#flavorTab').css('display', 'none');
175     });
176
177     $('.table tbody tr').click(function () {
178         $(this).addClass('openoTable_row_selected').siblings().removeClass('openoTable_row_selected');
179     });
180     $('.table tr:odd').addClass('active');
181     $('#false').click(function () {
182         $('#vmAppDialog').addClass('in').css({'display': 'block'});
183     });
184     $('.close,.button-previous').click(function () {
185         $('#vmAppDialog').removeClass('in').css('display', 'none');
186     });
187     $('#filterTpLogicalType').click(function () {
188         $('#filterTpLogicalType_select_popupcontainer').toggleClass('openo-hide');
189         $('#filterTpLogicalType').toggleClass('openo-focus');
190         var oLeft = $('#open_base_tpL_td6').offset().left;
191         var oTop = $('#open_base_tpL_td6').offset().top;
192         var oHeight = $('#open_base_tpL_td6').height();
193         $('#filterTpLogicalType_select_popupcontainer').css({'left': oLeft, 'top': oTop + oHeight + 10});
194     });
195     $('div.openo-select-popup-container>div.openo-select-item>label').click(function () {
196         var Lvalue = $(this).html();
197         $('#filterTpLogicalType_select_input').attr('value', Lvalue);
198         $('#filterTpLogicalType_select_popupcontainer').addClass('openo-hide');
199         $('#filterTpLogicalType').removeClass('openo-focus');
200     });
201     $.fn.serializeObject = function () {
202         var o = {};
203         var a = this.serializeArray();
204         $.each(a, function () {
205             if (o[this.name] !== undefined) {
206                 if (!o[this.name].push) {
207                     o[this.name] = [o[this.name]];
208                 }
209                 o[this.name].push(this.value || '');
210             } else {
211                 o[this.name] = this.value || '';
212             }
213         });
214         return o;
215     };
216     $('#createSite').click(function () {
217         var formData = JSON.stringify($("#vmAppForm").serializeObject());
218         alert(formData);
219         var jsonobj = JSON.parse(formData);
220         var requestUrl = "/openoapi/sdnobrs/v1/sites";
221         $
222             .ajax({
223                 type: "POST",
224                 url: requestUrl,
225                 contentType: "application/json",
226                 dataType: "json",
227                 data: formData,
228                 success: function (jsonobj) {
229                     alert("Details saved successfully!!!");
230                     var data = [jsonobj.name, jsonobj.hostName, jsonobj.productName, jsonobj.vendor, jsonobj.description];
231                     $('#example').dataTable().fnAddData(data);
232                     $('.modal').modal('hide');
233                 },
234                 error: function (xhr, ajaxOptions, thrownError) {
235                     alert("Error on page : " + xhr.responseText);
236                 }
237             });
238     });
239
240     $('#createNe').click(function () {
241         var formData = JSON.stringify($("#neForm").serializeObject());
242         alert(formData);
243         var jsonobj = JSON.parse(formData);
244         var requestUrl = "/sdnobrs/v1/managed-elements";
245         $
246             .ajax({
247                 type: "POST",
248                 url: requestUrl,
249                 contentType: "application/json",
250                 dataType: "json",
251                 data: formData,
252                 success: function (jsonobj) {
253                     alert("Details saved successfully!!!");
254                     var data = [jsonobj.name, jsonobj.hostName, jsonobj.productName, jsonobj.vendor, jsonobj.description];
255                     $('#example').dataTable().fnAddData(data);
256                     $('.modal').modal('hide');
257                 },
258                 error: function (xhr, ajaxOptions, thrownError) {
259                     alert("Error on page : " + xhr.responseText);
260                 }
261             });
262     });
263
264     $('#createPort').click(function () {
265         var formData = JSON.stringify($("#portForm").serializeObject());
266         alert(formData);
267         var jsonobj = JSON.parse(formData);
268         var requestUrl = "/openoapi/sdnobrs/v1/logical-termination-points";
269         $
270             .ajax({
271                 type: "POST",
272                 url: requestUrl,
273                 contentType: "application/json",
274                 dataType: "json",
275                 data: formData,
276                 success: function (jsonobj) {
277                     alert("Details saved successfully!!!");
278                     var data = [jsonobj.name, jsonobj.hostName, jsonobj.productName, jsonobj.vendor, jsonobj.description];
279                     $('#example').dataTable().fnAddData(data);
280                     $('.modal').modal('hide');
281                 },
282                 error: function (xhr, ajaxOptions, thrownError) {
283                     alert("Error on page : " + xhr.responseText);
284                 }
285             });
286     });
287
288     $('#createLink').click(function () {
289         var formData = JSON.stringify($("#linkForm").serializeObject());
290         alert(formData);
291         var jsonobj = JSON.parse(formData);
292         var requestUrl = "/openoapi/sdnobrs/v1/topological-links";
293         $
294             .ajax({
295                 type: "POST",
296                 url: requestUrl,
297                 contentType: "application/json",
298                 dataType: "json",
299                 data: formData,
300                 success: function (jsonobj) {
301                     alert("Details saved successfully!!!");
302                     var data = [jsonobj.name, jsonobj.hostName, jsonobj.productName, jsonobj.vendor, jsonobj.description];
303                     $('#example').dataTable().fnAddData(data);
304                     $('.modal').modal('hide');
305                 },
306                 error: function (xhr, ajaxOptions, thrownError) {
307                     alert("Error on page : " + xhr.responseText);
308                 }
309             });
310     });
311
312 })