2 Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 function performAction(instance_name
, instance_id
) {
18 var url
= '/instances/ns/'+instance_id
+'/action';
19 $("#formActionNS").attr("action", url
);
20 $('#modal_instance_new_action').modal('show');
23 function exportMetricNs(instance_name
, instance_id
) {
24 var url
= '/instances/ns/'+instance_id
+'/monitoring/metric';
25 $("#formExportMetricNS").attr("action", url
);
26 $('#modal_instance_export_metric').modal('show');
29 function newAlarmNs(instance_name
, instance_id
) {
30 var url
= '/instances/ns/'+instance_id
+'/monitoring/alarm';
31 $("#formAlarmNS").attr("action", url
);
32 $('#modal_instance_new_alarm').modal('show');
35 function deleteNs(instance_name
, instance_id
, force
) {
36 var url
= '/instances/ns/'+instance_id
+'/delete';
37 bootbox
.confirm("Are you sure want to delete " + instance_name
+ "?", function (result
) {
40 url
= url
+ '?force=true';
41 var dialog
= bootbox
.dialog({
42 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
49 contentType
: "application/json;charset=utf-8",
50 success: function (result
) {
51 if (result
['error'] == true){
53 bootbox
.alert("An error occurred.");
60 error: function (result
) {
62 var data
= result
.responseJSON
;
63 var title
= "Error " + (data
&& data
.code
? data
.code
: 'unknown');
64 var message
= data
&& data
.detail
? data
.detail
: 'No detail available.';
74 function deleteNsi(instance_name
, instance_id
, force
) {
75 var url
= '/instances/nsi/'+instance_id
+'/delete';
76 bootbox
.confirm("Are you sure want to delete " + instance_name
+ "?", function (result
) {
79 url
= url
+ '?force=true';
80 var dialog
= bootbox
.dialog({
81 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
88 contentType
: "application/json;charset=utf-8",
89 success: function (result
) {
91 if (result
['error'] == true){
93 var data
= result
.responseJSON
;
94 var title
= "Error " + (data
&& data
.code
? data
.code
: 'unknown');
95 var message
= data
&& data
.detail
? data
.detail
: 'No detail available.';
102 dialog
.modal('hide');
106 error: function (result
) {
107 dialog
.modal('hide');
108 var data
= result
.responseJSON
;
109 var title
= "Error " + (data
&& data
.code
? data
.code
: 'unknown');
110 var message
= data
&& data
.detail
? data
.detail
: 'No detail available.';
121 function deletePDU(instance_name
, instance_id
) {
122 var url
= '/instances/pdu/'+instance_id
+'/delete';
123 bootbox
.confirm("Are you sure want to delete " + instance_name
+ "?", function (result
) {
125 var dialog
= bootbox
.dialog({
126 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
133 contentType
: "application/json;charset=utf-8",
134 success: function (result
) {
135 if (result
['error'] == true){
136 dialog
.modal('hide');
137 bootbox
.alert("An error occurred.");
140 dialog
.modal('hide');
144 error: function (error
) {
145 dialog
.modal('hide');
146 bootbox
.alert("An error occurred.");
153 var addFormGroup = function (event
) {
154 event
.preventDefault();
156 var $formGroup
= $(this).closest('.form-group');
157 var $formGroupClone
= $formGroup
.clone();
159 $formGroupClone
.find('input').val('');
160 $formGroupClone
.find('button').toggleClass('btn-success btn-add btn-danger btn-remove');
161 $formGroupClone
.find('button').text('–');
162 $formGroupClone
.insertAfter($formGroup
);
166 var removeFormGroup = function (event
) {
167 event
.preventDefault();
168 var $formGroup
= $(this).closest('.form-group');
172 var addInterfaceGroup = function (event
) {
173 event
.preventDefault();
175 var $formGroup
= $(this).closest('.interface-group');
176 var $formGroupClone
= $formGroup
.clone();
179 .toggleClass('btn-success btn-add btn-danger btn-remove')
182 $formGroupClone
.find('input').val('');
183 $formGroupClone
.insertAfter($formGroup
);
187 var removeInterfaceGroup = function (event
) {
188 event
.preventDefault();
189 var $formGroup
= $(this).closest('.interface-group');
193 function showTopology(type
, instance_id
) {
194 var url
= '/instances/'+type
+'/'+instance_id
+'/topology';
195 window
.location
= url
;
198 function showInstanceDetails(type
, instance_id
) {
199 var url_info
= '/instances/'+type
+'/'+instance_id
;
200 var dialog
= bootbox
.dialog({
201 message
: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
208 contentType
: "application/json;charset=utf-8",
209 success: function (result
) {
211 if (result
['data'] !== undefined) {
212 editorJSON
.setValue(JSON
.stringify(result
['data'], null, "\t"));
213 editorJSON
.setOption("autoRefresh", true);
214 dialog
.modal('hide');
215 $('#modal_show_instance').modal('show');
218 dialog
.modal('hide');
219 bootbox
.alert("An error occurred while retrieving the information.");
222 error: function (result
) {
223 dialog
.modal('hide');
224 bootbox
.alert("An error occurred while retrieving the information.");
231 $(document
).ready(function () {
232 var json_editor_settings
= {
234 showCursorWhenSelecting
: true,
239 gutters
: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
240 autoCloseBrackets
: true,
243 "F11": function (cm
) {
244 cm
.setOption("fullScreen", !cm
.getOption("fullScreen"));
246 "Esc": function (cm
) {
247 if (cm
.getOption("fullScreen")) cm
.setOption("fullScreen", false);
249 "Ctrl-Q": function (cm
) {
250 cm
.foldCode(cm
.getCursor());
256 var myJsonTextArea
= document
.getElementById("instance_view_json");
257 editorJSON
= CodeMirror(function (elt
) {
258 myJsonTextArea
.parentNode
.replaceChild(elt
, myJsonTextArea
);
259 }, json_editor_settings
);
262 $(document
).on('click', '.primitive-group .btn-add', addFormGroup
);
263 $(document
).on('click', '.primitive-group .btn-remove', removeFormGroup
);
265 $(document
).on('click', '.interface-group .btn-add', addInterfaceGroup
);
266 $(document
).on('click', '.interface-group .btn-remove', removeInterfaceGroup
);
269 $("#formCreateNS").submit(function (event
) {
270 event
.preventDefault(); //prevent default action
271 var post_url
= $(this).attr("action"); //get form action url
272 var request_method
= $(this).attr("method"); //get form GET/POST method
273 var form_data
= new FormData(this); //Encode form elements for submission
276 type
: request_method
,
279 "Accept": 'application/json'
283 }).done(function (response
, textStatus
, jqXHR
) {
285 $('#modal_new_instance').modal('hide');
286 }).fail(function (result
) {
287 var data
= result
.responseJSON
;
288 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
289 var message
= data
.detail
? data
.detail
: 'No detail available.';
297 $("#formCreatePDU").submit(function (event
) {
298 event
.preventDefault(); //prevent default action
299 var post_url
= $(this).attr("action"); //get form action url
300 var request_method
= $(this).attr("method"); //get form GET/POST method
301 var form_data
= new FormData(this); //Encode form elements for submission
304 type
: request_method
,
307 "Accept": 'application/json'
311 }).done(function (response
, textStatus
, jqXHR
) {
313 $('#modal_new_pdu').modal('hide');
314 }).fail(function (result
) {
315 var data
= result
.responseJSON
;
316 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
317 var message
= data
.detail
? data
.detail
: 'No detail available.';
325 $("#formActionNS").submit(function (event
) {
326 event
.preventDefault(); //prevent default action
327 var post_url
= $(this).attr("action"); //get form action url
328 var request_method
= $(this).attr("method"); //get form GET/POST method
329 var form_data
= new FormData(this); //Encode form elements for submission
330 console
.log(post_url
);
333 type
: request_method
,
336 "Accept": 'application/json'
340 }).done(function (response
, textStatus
, jqXHR
) {
341 $('#modal_instance_new_action').modal('hide');
344 message
: "Action received."
346 }).fail(function (result
) {
347 var data
= result
.responseJSON
;
348 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
349 var message
= data
.detail
? data
.detail
: 'No detail available.';
357 $("#formAlarmNS").submit(function (event
) {
358 event
.preventDefault(); //prevent default action
359 var post_url
= $(this).attr("action"); //get form action url
360 var request_method
= $(this).attr("method"); //get form GET/POST method
361 var form_data
= new FormData(this); //Encode form elements for submission
362 console
.log(post_url
);
365 type
: request_method
,
368 "Accept": 'application/json'
372 }).done(function (response
, textStatus
, jqXHR
) {
373 $('#modal_instance_new_action').modal('hide');
376 message
: "Alarm created."
378 }).fail(function (result
) {
379 var data
= result
.responseJSON
;
380 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
381 var message
= data
.detail
? data
.detail
: 'No detail available.';
389 $("#formExportMetricNS").submit(function (event
) {
390 event
.preventDefault(); //prevent default action
391 var post_url
= $(this).attr("action"); //get form action url
392 var request_method
= $(this).attr("method"); //get form GET/POST method
393 var form_data
= new FormData(this); //Encode form elements for submission
394 console
.log(post_url
);
397 type
: request_method
,
400 "Accept": 'application/json'
404 }).done(function (response
, textStatus
, jqXHR
) {
405 $('#modal_instance_new_action').modal('hide');
408 message
: "Metric exported."
410 }).fail(function (result
) {
411 var data
= result
.responseJSON
;
412 var title
= "Error " + (data
.code
? data
.code
: 'unknown');
413 var message
= data
.detail
? data
.detail
: 'No detail available.';